From ac3beb5d8f6141e5feb5dd55971091ca59ebc5ee Mon Sep 17 00:00:00 2001 From: kyuuseiryuu Date: Tue, 3 Mar 2026 18:11:17 +0900 Subject: [PATCH] feat: Add isPassedGame logic and update GroupingPrediction component - Added `dayjs` import for date manipulation in `GamePanel.tsx`. - Introduced `isPassedGame` memoized value in `GamePanel.tsx` to determine if the game date has passed. - Updated `GroupingPrediction` component to accept `isPassedGame` prop and adjust `nowScoreGroup` state accordingly. --- src/components/GamePanel.tsx | 17 ++++++++++++++++- src/components/GroupingPrediction.tsx | 7 ++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/components/GamePanel.tsx b/src/components/GamePanel.tsx index c3044bd..aa49fc8 100644 --- a/src/components/GamePanel.tsx +++ b/src/components/GamePanel.tsx @@ -4,6 +4,7 @@ import { Tabs } from "antd"; import { PlayerList } from "./PlayerList"; import { GroupingPrediction } from "./GroupingPrediction"; import { useMemo } from "react"; +import dayjs from "dayjs"; interface Props { title: string; @@ -15,6 +16,14 @@ export const GamePanel: React.FC = props => { const sneckMode = useMemo(() => { return !!props.title?.includes('争霸赛'); }, [props.title]); + const isPassedGame = useMemo(() => { + const match = /(?\d{4})年(?\d{1,2})月(?\d{1,2})/.exec(props.title); + const { year, month, day } = match?.groups ?? {}; + const date = dayjs(`${year}-${month}-${day}`); + console.debug('date %s', date.format('YYYY-MM-DD')); + if (!date.isValid()) return true; + return date.isBefore(dayjs()); + }, []); return ( <> = props => { { key: 'groups', label: '分组预测', - children: + children: ( + + ), }, { key: 'players', diff --git a/src/components/GroupingPrediction.tsx b/src/components/GroupingPrediction.tsx index cfa0cc4..380fc9d 100644 --- a/src/components/GroupingPrediction.tsx +++ b/src/components/GroupingPrediction.tsx @@ -18,6 +18,7 @@ interface CustomPlayer extends Player { interface Props { players?: Player[]; sneckMode: boolean; + isPassedGame: boolean; } enum OrderScore { @@ -27,7 +28,11 @@ enum OrderScore { export const GroupingPrediction: React.FC = props => { const [maxPlayerSize, setMaxPlayerSize] = useState(48); - const [nowScoreGroup, setNowScoreGroup] = useState(OrderScore.当前积分); + const [nowScoreGroup, setNowScoreGroup] = useState( + props.isPassedGame + ? OrderScore.年度积分 + : OrderScore.当前积分 + ); const refactoredPlayers = useMemo(() => { return nowScoreGroup === OrderScore.当前积分 ? props.players?.map(e => ({ ...e,