From 8d84987fed5155184be6768e80c9e25af65e0390 Mon Sep 17 00:00:00 2001 From: testusuke Date: Sun, 19 May 2024 13:05:37 +0900 Subject: [PATCH 1/2] =?UTF-8?q?change:=20dnd=E9=96=A2=E9=80=A3=E3=82=92?= =?UTF-8?q?=E5=88=A5=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF=E3=83=88=E3=83=AA?= =?UTF-8?q?=E3=81=AB=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/(authenticated)/sports/[id]/create-league/page.tsx | 2 +- components/league/{ => create}/dndContainer.tsx | 0 components/league/{ => create}/dndItem.tsx | 0 components/league/{ => create}/dndPlaceHolder.tsx | 0 components/league/{ => create}/dndSortableItem.tsx | 0 components/league/{ => create}/leagueDnd.tsx | 0 6 files changed, 1 insertion(+), 1 deletion(-) rename components/league/{ => create}/dndContainer.tsx (100%) rename components/league/{ => create}/dndItem.tsx (100%) rename components/league/{ => create}/dndPlaceHolder.tsx (100%) rename components/league/{ => create}/dndSortableItem.tsx (100%) rename components/league/{ => create}/leagueDnd.tsx (100%) diff --git a/app/(authenticated)/sports/[id]/create-league/page.tsx b/app/(authenticated)/sports/[id]/create-league/page.tsx index 34e7cc9..806fd76 100644 --- a/app/(authenticated)/sports/[id]/create-league/page.tsx +++ b/app/(authenticated)/sports/[id]/create-league/page.tsx @@ -1,6 +1,6 @@ import {Breadcrumbs, Link, Stack, Typography} from "@mui/material"; import CardBackground from "@/components/layout/cardBackground"; -import LeagueDnd from "@/components/league/leagueDnd"; +import LeagueDnd from "@/components/league/create/leagueDnd"; import {sportFactory} from "@/src/models/SportModel"; export default async function LeaguePage({params}: { params: { id: string } }) { diff --git a/components/league/dndContainer.tsx b/components/league/create/dndContainer.tsx similarity index 100% rename from components/league/dndContainer.tsx rename to components/league/create/dndContainer.tsx diff --git a/components/league/dndItem.tsx b/components/league/create/dndItem.tsx similarity index 100% rename from components/league/dndItem.tsx rename to components/league/create/dndItem.tsx diff --git a/components/league/dndPlaceHolder.tsx b/components/league/create/dndPlaceHolder.tsx similarity index 100% rename from components/league/dndPlaceHolder.tsx rename to components/league/create/dndPlaceHolder.tsx diff --git a/components/league/dndSortableItem.tsx b/components/league/create/dndSortableItem.tsx similarity index 100% rename from components/league/dndSortableItem.tsx rename to components/league/create/dndSortableItem.tsx diff --git a/components/league/leagueDnd.tsx b/components/league/create/leagueDnd.tsx similarity index 100% rename from components/league/leagueDnd.tsx rename to components/league/create/leagueDnd.tsx From 1fe11d5871b8ca95a30d3ad26caf4d874cb85c7f Mon Sep 17 00:00:00 2001 From: testusuke Date: Sun, 19 May 2024 15:18:01 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E3=83=AA=E3=83=BC=E3=82=B0?= =?UTF-8?q?=E8=A1=A8=E3=81=AE=E3=83=97=E3=83=AD=E3=83=88=E3=82=BF=E3=82=A4?= =?UTF-8?q?=E3=83=97=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sports/[id]/games/[gameId]/page.tsx | 2 + components/league/table/leagueTable.tsx | 90 +++++++++++++++++++ components/league/table/matchCell.tsx | 53 +++++++++++ components/league/table/slashCell.tsx | 14 +++ components/league/table/teamCell.tsx | 28 ++++++ 5 files changed, 187 insertions(+) create mode 100644 components/league/table/leagueTable.tsx create mode 100644 components/league/table/matchCell.tsx create mode 100644 components/league/table/slashCell.tsx create mode 100644 components/league/table/teamCell.tsx diff --git a/app/(authenticated)/sports/[id]/games/[gameId]/page.tsx b/app/(authenticated)/sports/[id]/games/[gameId]/page.tsx index bde3291..b24ab32 100644 --- a/app/(authenticated)/sports/[id]/games/[gameId]/page.tsx +++ b/app/(authenticated)/sports/[id]/games/[gameId]/page.tsx @@ -3,6 +3,7 @@ import {Stack, Grid, Link, Typography, Breadcrumbs} from "@mui/material"; import CardList from "@/components/layout/cardList"; import {sportFactory} from "@/src/models/SportModel"; import {gameFactory} from "@/src/models/GameModel"; +import LeagueTable from "@/components/league/table/leagueTable"; export default async function GamePage({params}: { params: { gameId:string, id: string } }) { const gameId = parseInt(params.gameId, 10) @@ -25,6 +26,7 @@ export default async function GamePage({params}: { params: { gameId:string, id: {game.name}(ID:{gameId}) + diff --git a/components/league/table/leagueTable.tsx b/components/league/table/leagueTable.tsx new file mode 100644 index 0000000..921e66c --- /dev/null +++ b/components/league/table/leagueTable.tsx @@ -0,0 +1,90 @@ +import {Game, gameFactory} from "@/src/models/GameModel"; +import {Sport} from "@/src/models/SportModel"; +import {Stack} from "@mui/material"; +import {ReactNode} from "react"; +import TeamCell from "@/components/league/table/teamCell"; +import SlashCell from "@/components/league/table/slashCell"; +import MatchCell from "@/components/league/table/matchCell"; + +export type LeagueTableProps = { + game: Game + sport: Sport +} + +export default async function LeagueTable(props: LeagueTableProps) { + const entries = await gameFactory().getGameEntries(props.game.id) + const matches = await gameFactory().getGameMatches(props.game.id) + + const cells: ReactNode[] = [] + + // create 2 dimensional Stack components + // 1st dimension: rows + // 2nd dimension: columns + // each cell is a LeagueTableCell component + for (let i = 0; i < (entries.length + 1); i++) { + const rows: ReactNode[] = [] + for (let j = 0; j < (entries.length + 1); j++) { + if (i === 0 && j === 0) { + // meaningless data + rows.push( + + ) + } + else if (i === 0 || j === 0) { + const index = (i === 0) ? (j - 1) : (i - 1) + const team = entries[index] + + // Team name + rows.push( + + ) + } + else if (i === j) { + // meaningless match data + rows.push( + + ) + } + else { + const leftTeam = entries[i - 1] + const rightTeam = entries[j - 1] + + // find the match between leftTeam and rightTeam + const match = matches.find(match => { + return (match.leftTeamId === leftTeam.id && match.rightTeamId === rightTeam.id) || + (match.leftTeamId === rightTeam.id && match.rightTeamId === leftTeam.id) + }) + + if (match) { + // create a LeagueTableCell component + rows.push( + + ) + } + else { + // create a LeagueTableCell component + rows.push( + + ) + } + } + } + cells.push({rows}) + } + + + return ( + + {cells} + + ) +} diff --git a/components/league/table/matchCell.tsx b/components/league/table/matchCell.tsx new file mode 100644 index 0000000..6a538f7 --- /dev/null +++ b/components/league/table/matchCell.tsx @@ -0,0 +1,53 @@ +import {Box, Typography} from "@mui/material"; +import Link from "next/link"; +import {Match} from "@/src/models/MatchModel"; +import {Sport} from "@/src/models/SportModel"; +import {Game} from "@/src/models/GameModel"; +import {Team} from "@/src/models/TeamModel"; + + +export type MatchCellProps = { + sport: Sport + game: Game + match: Match + teams: Team[] +} + +export default function MatchCell(props: MatchCellProps) { + const leftTeam = props.teams.find(team => team.id === props.match.leftTeamId) + const rightTeam = props.teams.find(team => team.id === props.match.rightTeamId) + + if (!leftTeam || !rightTeam) { + return ( + + + エラー + + + ) + } + + return ( + + + {leftTeam.name} vs {rightTeam.name} + + + ) +} \ No newline at end of file diff --git a/components/league/table/slashCell.tsx b/components/league/table/slashCell.tsx new file mode 100644 index 0000000..bcfcda2 --- /dev/null +++ b/components/league/table/slashCell.tsx @@ -0,0 +1,14 @@ +import {Box} from "@mui/material"; + +export default function SlashCell() { + // display slash + return ( + + + ) +} \ No newline at end of file diff --git a/components/league/table/teamCell.tsx b/components/league/table/teamCell.tsx new file mode 100644 index 0000000..b37ab43 --- /dev/null +++ b/components/league/table/teamCell.tsx @@ -0,0 +1,28 @@ +import {Box, Typography} from "@mui/material"; +import {Team} from "@/src/models/TeamModel"; +import Link from "next/link"; + + +export type TeamCellProps = { + team: Team +} + +export default function TeamCell(props: TeamCellProps) { + + return ( + + + {props.team.name} + + + ) +} \ No newline at end of file