From bd19e945176c6bc985b64b64f9d718c65c2018cc Mon Sep 17 00:00:00 2001 From: "joshcs.eth" <46639943+jcstein@users.noreply.github.com> Date: Thu, 5 Oct 2023 21:19:58 -0400 Subject: [PATCH] feat: set url to current version --- src/pages/index.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 845cbcb..997d4f4 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -80,6 +80,10 @@ const versions = [ ]; export default function Example() { + const handleVersionChange = (event: React.ChangeEvent) => { + setSelectedVersion(event.target.value); + window.history.pushState({}, '', `?version=${event.target.value}`); + }; const [spec, setSpec] = useState(); const [open, setOpen] = useState(false); const [sidebarOpen, setSidebarOpen] = useState(false); @@ -106,6 +110,14 @@ export default function Example() { fetchJsonData(); }, [selectedVersion]); + useEffect(() => { + const urlParams = new URLSearchParams(window.location.search); + const versionParam = urlParams.get('version'); + if (versionParam && versions.includes(versionParam)) { + setSelectedVersion(versionParam); + } + }, []); + const activateSidebar = (param: any) => { setOpen(true); setCurrentParam(param); @@ -296,7 +308,7 @@ export default function Example() { Select API version: