From bcfedd00099bb583830d5c3e172a2d771044e8ca Mon Sep 17 00:00:00 2001 From: kyuuseiryuu Date: Sat, 7 Mar 2026 11:37:11 +0900 Subject: [PATCH] feat(GameSelector): request only once --- src/components/GameSelector/GameSelector.tsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/GameSelector/GameSelector.tsx b/src/components/GameSelector/GameSelector.tsx index c829768..ffe172b 100644 --- a/src/components/GameSelector/GameSelector.tsx +++ b/src/components/GameSelector/GameSelector.tsx @@ -2,7 +2,7 @@ import { Card, Divider, Flex, Select, Skeleton, Space, Statistic, Switch, Typogr import type React from 'react'; import { useRequest } from 'ahooks'; import { clubs } from './clubList'; -import { useCallback, useMemo, useState } from 'react'; +import { useCallback, useEffect, useMemo, useState } from 'react'; import dayjs from 'dayjs'; import type { IEventInfo } from '../../types'; @@ -12,11 +12,11 @@ interface Props { export const GameSelector: React.FC = props => { const [clubId, setClubId] = useState(clubs[0]?.clubId ?? ''); - const requestEvents = useRequest( - async () => { + const requestEvents = useRequest( + async (clubId: string) => { if (!clubId) return []; return (await fetch(`/api/events/${clubId}`)).json() - }, { manual: false, refreshDeps: [clubId] }) + }, { manual: true }); const [showFinished, setShowFinished] = useState(false); const gameList = useMemo(() => { const activeList = requestEvents.data?.map(e => ({ @@ -30,6 +30,15 @@ export const GameSelector: React.FC = props => { }, [gameList]); const handleClubChange = useCallback(async (id: string) => { setClubId(id); + requestEvents.runAsync(id); + }, []); + useEffect(() => { + const id = setTimeout(() => { + const clubId = clubs?.[0]?.clubId; + if (!clubId) return; + requestEvents.run(clubId); + }, 100); + return () => clearTimeout(id); }, []); return (