Skip to content

Commit

Permalink
Fix classmatch select season behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
P-man2976 committed Sep 29, 2024
1 parent 2824b20 commit 646da6b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/pages/Classmatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
useDisclosure,
} from '@chakra-ui/react';
import { Helmet } from 'react-helmet-async';
import { Navigate, useParams, useSearchParams } from 'react-router-dom';
import { useSearchParams } from 'react-router-dom';
import { useQueryClient } from '@tanstack/react-query';
import { TbChevronRight } from 'react-icons/tb';
import Header from '@/components/nav/Header';
Expand All @@ -31,31 +31,34 @@ import Loading from '@/components/common/Loading';
import HistoryModal from '@/components/classmatch/HistoryModal';

export default function Classmatch() {
const { year: y } = useParams();
const year = Number(y);
const queryClient = useQueryClient();
const [searchParams, setSearchParams] = useSearchParams();
const { isOpen, onOpen, onClose } = useDisclosure();
const [year, setYear] = useState(
Number(searchParams.get('year')) || new Date().getFullYear(),
);
const [season, setSeason] = useState<ClassmatchSeason>(
searchParams.get('season') ?? new Date().getMonth() > 6
? 'autumn'
: 'spring',
);

useEffect(() => {
searchParams.set('year', year.toString());
searchParams.set('season', season);
setSearchParams(searchParams);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [season]);
}, [year, season]);

const onSeasonSelected = useCallback(
({
// year: newYear,
year: newYear,
season: newSeason,
}: {
year: number;
season: ClassmatchSeason;
}) => {
setYear(newYear);
setSeason(newSeason);
},
[],
Expand Down Expand Up @@ -88,8 +91,6 @@ export default function Classmatch() {
},
);

if (!year) return <Navigate to={`/classmatch/${new Date().getFullYear()}`} />;

return (
<Box>
<Helmet>
Expand Down

0 comments on commit 646da6b

Please sign in to comment.