From 7df7b70516ef31b4d9e89ae7b1e041335f082ec4 Mon Sep 17 00:00:00 2001 From: kyuuseiryuu Date: Wed, 28 Jan 2026 16:02:45 +0900 Subject: [PATCH] feat(index) --- src/components/ChangeBackground.tsx | 7 ++ src/components/GameSelector/GameSelector.tsx | 108 +++++++++++-------- src/page/ProfilePage.tsx | 10 +- 3 files changed, 74 insertions(+), 51 deletions(-) create mode 100644 src/components/ChangeBackground.tsx diff --git a/src/components/ChangeBackground.tsx b/src/components/ChangeBackground.tsx new file mode 100644 index 0000000..5cfd2d0 --- /dev/null +++ b/src/components/ChangeBackground.tsx @@ -0,0 +1,7 @@ +import { createGlobalStyle } from "styled-components"; + +export const ChangeBackground = createGlobalStyle<{ url?: string }>` + body:before { + ${({ url }) => url ? `background: url(${url});` : ''} + } +` \ No newline at end of file diff --git a/src/components/GameSelector/GameSelector.tsx b/src/components/GameSelector/GameSelector.tsx index e6eb970..4f5f56d 100644 --- a/src/components/GameSelector/GameSelector.tsx +++ b/src/components/GameSelector/GameSelector.tsx @@ -1,10 +1,10 @@ -import { Card, Divider, Select, Space, Spin, Statistic, Typography } from 'antd'; +import { Card, Divider, Flex, Select, Space, Statistic, Switch, Typography } from 'antd'; import type React from 'react'; import { useRequest } from 'ahooks'; import { clubs } from './clubList'; -import { useCallback, useEffect, useMemo, useState } from 'react'; -import type { IEventInfo } from '../../types'; +import { useCallback, useEffect, useState } from 'react'; import dayjs from 'dayjs'; +import type { IEventInfo } from '../../types'; interface Props { onGameClick?: (info: IEventInfo) => void; @@ -14,14 +14,18 @@ export const GameSelector: React.FC = props => { const requestEvents = useRequest( async (clubId: string) => (await fetch(`/api/events/${clubId}`)).json() , { manual: true }) - const [gameList, setGameList] = useState([]); + const [gameList, setGameList] = useState<(IEventInfo & { finished: boolean })[]>([]); const [isEmpty, setIsEmpty] = useState(false); const [clubId, setClubId] = useState(clubs[0].clubId); + const [showFinished, setShowFinished] = useState(false); const handleClubChange = useCallback(async (clubId: string) => { const list = await requestEvents.runAsync(clubId); - const activeList = list.filter(e => !e.info.join('').includes('已结束')); + const activeList = list.map(e => ({ + ...e, + finished: e.info.join('').includes('已结束'), + })); setGameList(activeList); - setIsEmpty(activeList.length === 0); + setIsEmpty(activeList.filter(e => !e.finished).length === 0); }, []); useEffect(() => { const clubId = clubs[0].clubId; @@ -29,43 +33,61 @@ export const GameSelector: React.FC = props => { }, []); return ( - ({ label: e.name, value: e.clubId }))} + onChange={handleClubChange} + /> + + {isEmpty && (没有未开始的比赛)} + + {gameList + .filter(e => showFinished || !e.finished) + .map(e => ) + } + ); +} + +interface EventCardProps { + eventInfo: IEventInfo & { finished: boolean }; + onGameClick?: (info: IEventInfo) => void; +} + +function EventCard(props: EventCardProps) { + const { eventInfo: e } = props; + const { y, M, D } = /^(?\d{4})年(?\d+)月(?\d+)日/.exec(e.title)?.groups ?? {} as { y: string; M: string; D: string}; + const hm = /(?\d+:\d+)\b/.exec(e.info.join('\n'))?.groups?.hm ?? '10:00'; + const day = dayjs(`${y}-${M}-${D} ${hm}`); + return ( + props.onGameClick?.(e)} + > + {e.title} + + {e.info.map(e => ( +
+ {e} +
+ ))} +
+ ) } \ No newline at end of file diff --git a/src/page/ProfilePage.tsx b/src/page/ProfilePage.tsx index 70a795d..bcdfd23 100644 --- a/src/page/ProfilePage.tsx +++ b/src/page/ProfilePage.tsx @@ -5,13 +5,7 @@ import { HomeOutlined } from "@ant-design/icons"; import User from "../components/User"; import React from "react"; -import { createGlobalStyle } from "styled-components"; - -const BodyBG = createGlobalStyle<{ url?: string }>` - body:before { - ${({ url }) => url ? `background: url(${url});` : ''} - } -` +import { ChangeBackground } from "../components/ChangeBackground"; function Honor(props: { honors?: XCXProfile['honors'] }) { if (!props.honors?.length) return null; @@ -81,7 +75,7 @@ export default function ProfilePage() { const navigate = useNavigate(); return ( <> - + } onClick={() => navigate('/')} />