From ab6cedfe727727d9df91f05b802033268a35cd66 Mon Sep 17 00:00:00 2001 From: John Tuckner Date: Wed, 3 Jan 2024 21:38:35 -0600 Subject: [PATCH] add config query param --- src/App.tsx | 9 +++++++++ src/utilis/index.ts | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/App.tsx b/src/App.tsx index 6733a17d..c791cd45 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -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(false); @@ -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)" }); diff --git a/src/utilis/index.ts b/src/utilis/index.ts index dc2f71e2..45f9d09d 100644 --- a/src/utilis/index.ts +++ b/src/utilis/index.ts @@ -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);