-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( | ||
<SlashCell key={`${i}_${j}`}/> | ||
) | ||
} | ||
else if (i === 0 || j === 0) { | ||
const index = (i === 0) ? (j - 1) : (i - 1) | ||
const team = entries[index] | ||
|
||
// Team name | ||
rows.push( | ||
<TeamCell team={team} key={`${i}_${j}`} /> | ||
) | ||
} | ||
else if (i === j) { | ||
// meaningless match data | ||
rows.push( | ||
<SlashCell key={`${i}_${j}`}/> | ||
) | ||
} | ||
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( | ||
<MatchCell | ||
sport={props.sport} | ||
game={props.game} | ||
match={match} | ||
teams={entries} | ||
key={`${i}_${j}`} | ||
/> | ||
) | ||
} | ||
else { | ||
// create a LeagueTableCell component | ||
rows.push( | ||
<SlashCell key={`${i}_${j}`}/> | ||
) | ||
} | ||
} | ||
} | ||
cells.push(<Stack key={i} direction={"column"}>{rows}</Stack>) | ||
} | ||
|
||
|
||
return ( | ||
<Stack | ||
spacing={0} | ||
direction={"row"} | ||
> | ||
{cells} | ||
</Stack> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Box | ||
height={100} | ||
width={200} | ||
border={1} | ||
alignItems={"center"} | ||
justifyContent={"center"} | ||
display={"flex"} | ||
> | ||
<Typography> | ||
エラー | ||
</Typography> | ||
</Box> | ||
) | ||
} | ||
|
||
return ( | ||
<Box | ||
height={100} | ||
width={200} | ||
border={1} | ||
component={Link} | ||
href={`/sports/${props.sport.id}/games/${props.game.id}/matches/${props.match.id}`} | ||
alignItems={"center"} | ||
justifyContent={"center"} | ||
display={"flex"} | ||
> | ||
<Typography> | ||
{leftTeam.name} vs {rightTeam.name} | ||
</Typography> | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {Box} from "@mui/material"; | ||
|
||
export default function SlashCell() { | ||
// display slash | ||
return ( | ||
<Box | ||
height={100} | ||
width={200} | ||
border={1} | ||
bgcolor={"#d3d3d3"} | ||
> | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Box | ||
height={100} | ||
width={200} | ||
border={1} | ||
component={Link} | ||
href={`/teams/${props.team.id}`} | ||
alignItems={"center"} | ||
justifyContent={"center"} | ||
display={"flex"} | ||
> | ||
<Typography> | ||
{props.team.name} | ||
</Typography> | ||
</Box> | ||
) | ||
} |