Skip to content

Commit

Permalink
2024 classmatch preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
P-man2976 committed Apr 12, 2024
1 parent 238d587 commit aa37f6d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 27 deletions.
10 changes: 7 additions & 3 deletions src/components/nav/SideMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const MenuBody = React.memo(() => {
type: 'button',
icon: <Icon as={TbTrophy} boxSize={7} />,
label: 'クラスマッチ',
href: '/classmatch/2023',
href: '/classmatch',
},
{
type: 'divider',
Expand Down Expand Up @@ -218,7 +218,9 @@ const MenuBody = React.memo(() => {
w="100%"
spacing={4}
color={
location.pathname === menuItem.href ? 'blue.400' : undefined
location.pathname.startsWith(menuItem.href)
? 'blue.400'
: undefined
}
layerStyle="button"
rounded="xl"
Expand All @@ -230,7 +232,9 @@ const MenuBody = React.memo(() => {
<Text
color={
menuItem.color ??
(location.pathname === menuItem.href ? 'blue.400' : undefined)
(location.pathname.startsWith(menuItem.href)
? 'blue.400'
: undefined)
}
textStyle="title"
fontSize="lg"
Expand Down
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 { useSearchParams } from 'react-router-dom';
import { Navigate, useParams, 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 @@ -30,9 +30,9 @@ import Error from '@/components/cards/Error';
import Loading from '@/components/common/Loading';
import HistoryModal from '@/components/classmatch/HistoryModal';

const year = 2023;

export default function Classmatch2023() {
export default function Classmatch() {
const { year: y } = useParams();
const year = Number(y);
const queryClient = useQueryClient();
const [searchParams, setSearchParams] = useSearchParams();
const { isOpen, onOpen, onClose } = useDisclosure();
Expand Down Expand Up @@ -65,18 +65,30 @@ export default function Classmatch2023() {
data: sports,
status: sportsStatus,
error: sportsError,
} = useClassmatchSports({
year,
season,
});
} = useClassmatchSports(
{
year,
season,
},
{
enabled: !!year,
},
);
const {
data: streams,
status: streamsStatus,
error: streamsError,
} = useClassmatchLiveStreams({
year,
season,
});
} = useClassmatchLiveStreams(
{
year,
season,
},
{
enabled: !!year,
},
);

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

return (
<Box>
Expand Down
8 changes: 3 additions & 5 deletions src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ const ClassroomMaterial = React.lazy(
const ClassroomBookmarks = React.lazy(
() => import('./pages/classroom/ClassroomBookmarks'),
);
const Classmatch2023 = React.lazy(
() => import('./pages/classmatch/Classmatch2023'),
);
const Classmatch = React.lazy(() => import('./pages/Classmatch'));

const Settings = React.lazy(() => import('./pages/Settings'));
const SettingsTop = React.lazy(() => import('./pages/settings/Top'));
Expand Down Expand Up @@ -178,8 +176,8 @@ const router = createBrowserRouter([
element: <ClassroomMaterial />,
},
{
path: 'classmatch/2023',
element: <Classmatch2023 />,
path: 'classmatch/:year?',
element: <Classmatch />,
},
],
},
Expand Down
21 changes: 14 additions & 7 deletions src/services/classmatch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ export const useClassmatchSportInfo = (
});
};

export const useClassmatchLiveStreams = ({
year,
season,
}: {
year: number;
season: ClassmatchSeason;
}) => {
export const useClassmatchLiveStreams = (
{
year,
season,
}: {
year: number;
season: ClassmatchSeason;
},
options?: Omit<
UseQueryOptions<ClassmatchLiveStream[]>,
'queryKey' | 'queryFn'
>,
) => {
const { client } = useClient();

return useQuery({
Expand All @@ -71,6 +77,7 @@ export const useClassmatchLiveStreams = ({
signal,
})
).data,
...options,
});
};

Expand Down

0 comments on commit aa37f6d

Please sign in to comment.