Skip to content

Commit

Permalink
fix: 🐛 nav update
Browse files Browse the repository at this point in the history
  • Loading branch information
HuskyHsu committed Dec 16, 2023
1 parent af40b5d commit 5cd011a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
21 changes: 5 additions & 16 deletions src/pages/Pokedex/UseFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@ const localStorageKey = 'pokeDexPage';

export function UseFilter() {
const [searchParams, setSearchParams] = useSearchParams();
const [display, setDisplay] = useState<Display>({
advancedFilter: false,
EVs: false,
ability: false,
});

let cacheObj = getJsonCache(localStorageKey);
useEffect(() => {
for (const key of Object.keys(cacheObj)) {
if (searchParams.get(key) === null) {
setSearchParams((prev) => {
prev.set(key, cacheObj[key as keyof typeof cacheObj]);
return prev;
});
}
}
}, [cacheObj, searchParams, setSearchParams]);

const filter: Filter = {
keyword: searchParams.get('keyword') || '',
Expand All @@ -34,12 +29,6 @@ export function UseFilter() {
tags: new Set((searchParams.get('tags') || '').split('-').filter(Boolean)),
};

const [display, setDisplay] = useState<Display>({
advancedFilter: false,
EVs: false,
ability: false,
});

const updateState = (key: ValueKeys<Filter, string>[keyof Filter]) => {
return (val: string) => {
if (val === '') {
Expand Down
10 changes: 9 additions & 1 deletion src/routers/layouts/MainLayout/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ import { Icon } from '@/newComponents';
import { Loading } from '@/newComponents/common';
import { useBackToTopContext } from '@/newComponents/contexts';
import { Item } from './Item';
import { getJsonCache } from '@/store';

const localStorageKey = 'pokeDexPage';

function MainLayout() {
const { ref, toggleVisibility } = useBackToTopContext();
const location = useLocation();
const navigate = useNavigate();

let cacheObj = getJsonCache(localStorageKey);
const navLink = Object.entries(cacheObj)
.map(([key, val]) => `${key}=${val}`)
.join('&');

const hash = location.pathname.split('/')[1];

const updateNav = (to: string) => {
Expand Down Expand Up @@ -59,7 +67,7 @@ function MainLayout() {
text={'圖鑑清單'}
color="bg-custom-red"
selected={['pokedex', ''].includes(hash)}
onClick={() => updateNav('')}
onClick={() => updateNav(`/?${navLink}`)}
>
<Icon.Books className="h-5 w-5 fill-current" />
</Item>
Expand Down

0 comments on commit 5cd011a

Please sign in to comment.