Skip to content

Commit

Permalink
feat: fix sharing option (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshpaliyal authored Dec 29, 2024
1 parent abd830d commit ec84e3e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
31 changes: 3 additions & 28 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useEffect, useMemo, useState } from "react";
import { useEffect, useState } from "react";
import "./App.css";
import { CompareChart } from "./CompareChart";
import { Textarea } from "@/components/ui/textarea";
Expand All @@ -18,39 +18,14 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { useSearchParams } from "react-router-dom";
import { Compare } from "./ui/Compare";

function App({ json, resetJson }: { json: string | undefined, resetJson: () => void }) {
function App({ json, resetJson, filters }: { json: string | undefined, resetJson: () => void, filters: Filters | undefined }) {
const [benchmarks, setBenchmarks] = useState<Benchmark[] | undefined>([]);

const [rawInput, setRawInput] = useState<string | undefined>(json);
const [filter, setFilter] = useState<Filters | undefined>();
const [filter, setFilter] = useState<Filters | undefined>(filters);
const [selectedTab, setSelectedTab] = useState<string | undefined>("charts");
const [searchParams] = useSearchParams();

const benchmarkFromRequest = searchParams.get("benchmarks");
const filtersQueryP = searchParams.get("filters");

useEffect(() => {
if (benchmarkFromRequest) {
try {
setRawInput(JSON.stringify(JSON.parse(benchmarkFromRequest), null, 2));
} catch (e) {
console.error(e);
}
}
}, [benchmarkFromRequest]);

useEffect(() => {
if (filtersQueryP) {
try {
setFilter(JSON.parse(filtersQueryP));
} catch (e) {
console.error(e);
}
}
}, [filtersQueryP]);

const [localBenchmarks, setLocalBenchmarks] = useState<
Record<string, string | undefined> | undefined
Expand Down
31 changes: 29 additions & 2 deletions src/mainComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { Shell } from "./ui/shell.tsx";
import Page from "./page.tsx";
import App from "./App.tsx";
import { Filters } from "./types/filters.ts";
import { useSearchParams } from "react-router-dom";

interface Props {
rawInput: string | undefined;
Expand All @@ -12,10 +14,35 @@ export const DataContext = React.createContext<Props | undefined>(undefined);

export default function DataComponent() {
const [rawInput, setRawInput] = useState<string | undefined>();
const [filter, setFilter] = useState<Filters | undefined>();
const [searchParams] = useSearchParams();

const benchmarkFromRequest = searchParams.get("benchmarks");
const filtersQueryP = searchParams.get("filters");

useEffect(() => {
if (benchmarkFromRequest) {
try {
setRawInput(JSON.stringify(JSON.parse(benchmarkFromRequest), null, 2));
} catch (e) {
console.error(e);
}
}
}, [benchmarkFromRequest]);

useEffect(() => {
if (filtersQueryP) {
try {
setFilter(JSON.parse(filtersQueryP));
} catch (e) {
console.error(e);
}
}
}, [filtersQueryP]);

let content: React.ReactElement;
if (rawInput) {
content = <App json={rawInput} resetJson={() => setRawInput(undefined)} />;
content = <App json={rawInput} resetJson={() => setRawInput(undefined)} filters={filter}/>;
} else {
content = <Page setRawInput={setRawInput} />;
}
Expand Down

0 comments on commit ec84e3e

Please sign in to comment.