Skip to content

Commit

Permalink
feat: set url to current version
Browse files Browse the repository at this point in the history
  • Loading branch information
jcstein committed Oct 6, 2023
1 parent 6b99af4 commit bd19e94
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ const versions = [
];

export default function Example() {
const handleVersionChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
setSelectedVersion(event.target.value);
window.history.pushState({}, '', `?version=${event.target.value}`);
};
const [spec, setSpec] = useState<any>();
const [open, setOpen] = useState(false);
const [sidebarOpen, setSidebarOpen] = useState(false);
Expand All @@ -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);
Expand Down Expand Up @@ -296,7 +308,7 @@ export default function Example() {
Select API version:
<select
value={selectedVersion}
onChange={(e) => setSelectedVersion(e.target.value)}
onChange={handleVersionChange}
>
{versions.map((version) => (
<option key={version} value={version}>
Expand Down

0 comments on commit bd19e94

Please sign in to comment.