Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tuckner committed Jan 4, 2024
2 parents 5abe230 + e5aa625 commit 67e02eb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Board from "components/Board";
import { MdVisibilityOff } from "react-icons/md";
import { useMediaQuery } from "react-responsive";
import { Collapse } from "@chakra-ui/react";
import { retrieveAndSaveState } from "utilis";

function App() {
const [showSidebar,setShowSidebar] = useState<boolean>(false);
Expand All @@ -20,6 +21,14 @@ function App() {
} else {
document.documentElement.classList.remove("dark");
}

const queryParams = new URLSearchParams(location.search);
const configParam = queryParams.get("config"); // Replace 'sidebar' with your actual query parameter

// Set the state based on the URL parameter
if (configParam) {
retrieveAndSaveState(configParam);
}
}, []);

const isMobile = useMediaQuery({ query: "(min-width: 700px)" });
Expand Down
16 changes: 16 additions & 0 deletions src/utilis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ export const handleFilterChange = (newFilter: string | null) => {
}
};

export const retrieveAndSaveState = async (config: string) => {
try {
const response = await fetch('https://fetch.automation-capability-matrix.workers.dev/?config=' + config);
if (!response.ok) {
throw new Error("Failed to retrieve data from the URL");
}
const parsedData = await response.json();
parsedData.config.active = parsedData.config.board[0];
const boardData = { board: {} };
boardData.board = parsedData.config;
saveState(boardData);
} catch (err) {
console.error("Error retrieving and saving state:", err);
}
};

export const saveState = (state: any) => {
try {
const serializesState = JSON.stringify(state);
Expand Down

0 comments on commit 67e02eb

Please sign in to comment.