diff --git a/app/(authenticated)/page.tsx b/app/(authenticated)/page.tsx index 204f1e0..63c263a 100644 --- a/app/(authenticated)/page.tsx +++ b/app/(authenticated)/page.tsx @@ -1,15 +1,15 @@ -import {Breadcrumbs, Grid, Stack, Typography} from "@mui/material"; -import CardBackground from "@/components/layout/cardBackground"; -import CardLarge from "@/components/layout/cardLarge"; -import CardList from "@/components/layout/cardList"; -import SportsList from "@/components/sports/sportsList"; -import {sportFactory} from "@/src/models/SportModel"; +import {Breadcrumbs, Grid, Stack, Typography} from "@mui/material" +import CardBackground from "@/components/layout/cardBackground" +import CardLarge from "@/components/layout/cardLarge" +import SportsList from "@/components/sports/sportsList" +import {sportFactory} from "@/src/models/SportModel" +import InProgressMatchList from "@/components/match/inProgressMatchList" export default async function Home() { const sports = await sportFactory().index() return ( - + 管理者のダッシュボード @@ -23,69 +23,8 @@ export default async function Home() { - - - - - - - - - - - - - - + - ); + ) } diff --git a/app/(authenticated)/sports/[id]/games/[gameId]/page.tsx b/app/(authenticated)/sports/[id]/games/[gameId]/page.tsx index b24ab32..de85203 100644 --- a/app/(authenticated)/sports/[id]/games/[gameId]/page.tsx +++ b/app/(authenticated)/sports/[id]/games/[gameId]/page.tsx @@ -1,8 +1,8 @@ import CardBackground from "@/components/layout/cardBackground"; -import {Stack, Grid, Link, Typography, Breadcrumbs} from "@mui/material"; -import CardList from "@/components/layout/cardList"; +import {Stack, Link, Typography, Breadcrumbs} from "@mui/material"; import {sportFactory} from "@/src/models/SportModel"; import {gameFactory} from "@/src/models/GameModel"; +import MatchList from "@/components/match/matchList"; import LeagueTable from "@/components/league/table/leagueTable"; export default async function GamePage({params}: { params: { gameId:string, id: string } }) { @@ -10,6 +10,7 @@ export default async function GamePage({params}: { params: { gameId:string, id: const game = await gameFactory().show(gameId) const sportId = parseInt(params.id, 10) const sport = await sportFactory().show(sportId) + const matchList = await gameFactory().getGameMatches(gameId) return( @@ -28,10 +29,10 @@ export default async function GamePage({params}: { params: { gameId:string, id: - - - - + + ) diff --git a/app/(authenticated)/sports/[id]/page.tsx b/app/(authenticated)/sports/[id]/page.tsx index 6c1dd25..ed4ba52 100644 --- a/app/(authenticated)/sports/[id]/page.tsx +++ b/app/(authenticated)/sports/[id]/page.tsx @@ -1,10 +1,10 @@ import CardBackground from "@/components/layout/cardBackground"; import {Stack, Grid, Link, Typography, Breadcrumbs} from "@mui/material"; -import CardList from "@/components/layout/cardList"; import {sportFactory} from "@/src/models/SportModel"; import SportEditor from "@/components/sports/sportEditor"; import LeagueList from "@/components/sports/leagueList"; import {gameFactory} from "@/src/models/GameModel"; +import SportInProgressMatchList from "@/components/match/sportInProgressMatchList"; export default async function SportPage({params}: { params: { id: string } }) { const sportId = parseInt(params.id, 10) @@ -42,9 +42,7 @@ export default async function SportPage({params}: { params: { id: string } }) { - - - + ) diff --git a/components/match/inProgressMatchList.tsx b/components/match/inProgressMatchList.tsx new file mode 100644 index 0000000..e334fff --- /dev/null +++ b/components/match/inProgressMatchList.tsx @@ -0,0 +1,31 @@ +import {gameFactory} from "@/src/models/GameModel" +import {Match, matchFactory} from "@/src/models/MatchModel" +import MatchList from "@/components/match/matchList" + +export default async function InProgressMatchList() { + // get all games + const games = await gameFactory().index() + const matches = await matchFactory().index() + + const matchList: Match[] = [] + for (const game of games) { + // get all matches + const filteredMatches = matches.filter((match) => match.gameId == game.id) + // filter matches that are not finished + const inProgressMatches = filteredMatches.filter((match) => match.status == "standby" || match.status == "in_progress") + + // sort by start time + inProgressMatches.sort((a, b) => { + return new Date(a.startAt).getTime() - new Date(b.startAt).getTime() + }) + + console.log(inProgressMatches[0]) + + // pick the first match + matchList.push(inProgressMatches[0]) + } + + return ( + + ) +} diff --git a/components/layout/cardList.tsx b/components/match/matchCard.tsx similarity index 56% rename from components/layout/cardList.tsx rename to components/match/matchCard.tsx index 746b289..c7ab33e 100644 --- a/components/layout/cardList.tsx +++ b/components/match/matchCard.tsx @@ -1,22 +1,37 @@ import {Grid, Button, Avatar, Chip, Stack, Tooltip, Divider} from "@mui/material"; -import React, {ReactNode} from 'react'; import {HiClock, HiFlag, HiMapPin, HiTableCells, HiUserGroup} from "react-icons/hi2"; +import {Match} from "@/src/models/MatchModel"; +import {sportFactory} from "@/src/models/SportModel"; +import {gameFactory} from "@/src/models/GameModel"; +import {locationFactory} from "@/src/models/LocationModel"; +import {teamFactory} from "@/src/models/TeamModel"; -type CardProps = { - link?: string; - sport: string; - league: string; - judge: string; - left: string; - right: string; - time: string; - location: string; +type MatchCardProps = { + match: Match } -const CardList: React.FC = ({link, location, sport, league, judge, left, right, time}) => { +export default async function MatchCard(props: MatchCardProps) { + const sport = await sportFactory().show(props.match.sportId) + const game = await gameFactory().show(props.match.gameId) + const location = props.match.locationId == null ? undefined : await locationFactory().show(props.match.locationId) + const leftTeam = props.match.leftTeamId == null ? undefined : await teamFactory().show(props.match.leftTeamId) + const rightTeam = props.match.rightTeamId == null ? undefined : await teamFactory().show(props.match.rightTeamId) + const judgeTeam = props.match.judgeTeamId == null ? undefined : await teamFactory().show(props.match.judgeTeamId) + + const date = new Date(props.match.startAt) + const formattedDate = `${date.getHours()}時${date.getMinutes() < 10 ? '0' : ''}${date.getMinutes()}分` + return ( - + + + + + + + + + } + aria-controls="panel-content" + id="panel-header" + > + 編集する + + + + + 補足 + + + 審判 + + 審判 + + + + 試合の場所 + + 場所 + + - - - - - - } - aria-controls="panel-content" - id="panel-header" - > - 編集する - - - + + + - 補足 - - - 審判 - - 審判 - - - - 試合の場所 - - 場所 - - - - - - - - - - - - + - - - - - - - 変更が保存されました - - - - - - + + + + + 変更が保存されました + + + + + + {/*Cancel Snack*/} + + - - - - - - - 変更を元に戻しました - - - - - - - ) - } -} \ No newline at end of file + + + + + + 変更を元に戻しました + + + + + + {/*Match State Error*/} + + + + + + + + 勝者、状態を選択してください。 + + + + + + ) +} diff --git a/components/match/matchList.tsx b/components/match/matchList.tsx new file mode 100644 index 0000000..ebc2e7a --- /dev/null +++ b/components/match/matchList.tsx @@ -0,0 +1,24 @@ +import Grid from "@mui/material/Grid"; +import {Match} from "@/src/models/MatchModel"; +import MatchCard from "@/components/match/matchCard"; + +export type MatchListProps = { + matches: Match[] +} + +export default async function MatchList(props: MatchListProps) { + const components = props.matches.map((match) => + + ) + return ( + + {components} + + ) +} \ No newline at end of file diff --git a/components/match/sportInProgressMatchList.tsx b/components/match/sportInProgressMatchList.tsx new file mode 100644 index 0000000..341b9a9 --- /dev/null +++ b/components/match/sportInProgressMatchList.tsx @@ -0,0 +1,36 @@ +import {Sport} from "@/src/models/SportModel"; +import {gameFactory} from "@/src/models/GameModel"; +import {Match} from "@/src/models/MatchModel"; +import MatchList from "@/components/match/matchList"; + +export interface SportInProgressMatchListProps { + sport: Sport +} + +export default async function SportInProgressMatchList(props: SportInProgressMatchListProps) { + // get all games + const games = await gameFactory().index() + const filteredGames = games.filter((game) => game.sportId == props.sport.id) + + const matchList: Match[] = [] + for (const game of filteredGames) { + // get all matches + const matches = await gameFactory().getGameMatches(game.id) + // filter matches that are not finished + const inProgressMatches = matches.filter((match) => match.status == "standby" || match.status == "in_progress") + + // sort by start time + inProgressMatches.sort((a, b) => { + return new Date(a.startAt).getTime() - new Date(b.startAt).getTime() + }) + + console.log(inProgressMatches[0]) + + // pick the first match + matchList.push(inProgressMatches[0]) + } + + return ( + + ) +} diff --git a/src/models/MatchModel.ts b/src/models/MatchModel.ts index 8071c86..b950ca0 100644 --- a/src/models/MatchModel.ts +++ b/src/models/MatchModel.ts @@ -13,7 +13,7 @@ export type Match = { result: MatchResult, status: MatchStatus, note: string | null, - judgeTeamId: string | null, + judgeTeamId: number | null, parents: number[], children: number[], createdAt: string,