feat: persist selected group (#6993)

pull/6997/head
Arik Chakma 3 months ago committed by GitHub
parent 29fa5397f3
commit a92ea779b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 16
      src/components/Roadmaps/RoadmapsPage.tsx

@ -3,6 +3,11 @@ import { cn } from '../../lib/classname.ts';
import { Filter, X } from 'lucide-react'; import { Filter, X } from 'lucide-react';
import { CategoryFilterButton } from './CategoryFilterButton.tsx'; import { CategoryFilterButton } from './CategoryFilterButton.tsx';
import { useOutsideClick } from '../../hooks/use-outside-click.ts'; import { useOutsideClick } from '../../hooks/use-outside-click.ts';
import {
deleteUrlParam,
getUrlParams,
setUrlParams,
} from '../../lib/browser.ts';
const groupNames = [ const groupNames = [
'Absolute Beginners', 'Absolute Beginners',
@ -468,6 +473,15 @@ export function RoadmapsPage() {
]); ]);
}, [activeGroup]); }, [activeGroup]);
useEffect(() => {
const { g } = getUrlParams() as { g: AllowGroupNames };
if (!g) {
return;
}
setActiveGroup(g);
}, []);
return ( return (
<div className="border-t bg-gray-100"> <div className="border-t bg-gray-100">
<button <button
@ -502,6 +516,7 @@ export function RoadmapsPage() {
onClick={() => { onClick={() => {
setActiveGroup(''); setActiveGroup('');
setIsFilterOpen(false); setIsFilterOpen(false);
deleteUrlParam('g');
}} }}
category={'All Roadmaps'} category={'All Roadmaps'}
selected={activeGroup === ''} selected={activeGroup === ''}
@ -514,6 +529,7 @@ export function RoadmapsPage() {
setActiveGroup(group.group); setActiveGroup(group.group);
setIsFilterOpen(false); setIsFilterOpen(false);
document?.getElementById('filter-button')?.scrollIntoView(); document?.getElementById('filter-button')?.scrollIntoView();
setUrlParams({ g: group.group });
}} }}
category={group.group} category={group.group}
selected={activeGroup === group.group} selected={activeGroup === group.group}

Loading…
Cancel
Save