-
Notifications
You must be signed in to change notification settings - Fork 2
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
6 changed files
with
149 additions
and
10 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
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 |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import { Box } from "@mui/material"; | ||
import { Page } from "utils/types"; | ||
import MainMenu from "./MainMenu"; | ||
import { Box } from '@mui/material' | ||
import { ScrollRestoration } from 'react-router-dom' | ||
import { Page } from 'utils/types' | ||
import MainMenu from './MainMenu' | ||
|
||
type Props = { | ||
currentPage: Page; | ||
children?: React.ReactNode; | ||
}; | ||
currentPage: Page | ||
children?: React.ReactNode | ||
} | ||
|
||
export default function MainScreen({ children, currentPage }: Props) { | ||
return ( | ||
<Box> | ||
<MainMenu currentPage={currentPage} /> | ||
{children} | ||
<ScrollRestoration /> | ||
</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,87 @@ | ||
import { | ||
Box, | ||
TableBody, | ||
TableCell, | ||
TableContainer, | ||
TableHead, | ||
TableRow, | ||
} from '@mui/material' | ||
import { useQuery } from '@tanstack/react-query' | ||
import { fetchPlayers, fetchStats } from 'utils/api' | ||
import { Player } from 'utils/types' | ||
|
||
export default function StatsPage() { | ||
const { data: playersData } = useQuery({ | ||
queryKey: ['players'], | ||
queryFn: fetchPlayers, | ||
staleTime: 1000 * 60 * 1, | ||
}) | ||
const players = playersData?.players | ||
|
||
const { data } = useQuery({ | ||
queryKey: ['playersStats'], | ||
queryFn: fetchStats, | ||
staleTime: 1000 * 60 * 1, | ||
}) | ||
const playersStats = data?.players | ||
|
||
if (!playersStats || !players) { | ||
return <div>Loading...</div> | ||
} | ||
|
||
const playersById = players.reduce( | ||
(acc, player) => { | ||
acc[player.id] = player | ||
return acc | ||
}, | ||
{} as Record<number, Player> | ||
) | ||
|
||
const playersStatsByPosition = playersStats.sort( | ||
(a, b) => b.map_position - a.map_position | ||
) | ||
|
||
return ( | ||
<Box> | ||
<Box textAlign={'center'}> | ||
<h2>Лидерборд</h2> | ||
</Box> | ||
<Box | ||
marginTop={2} | ||
marginLeft={4} | ||
marginRight={4} | ||
justifyContent="center" | ||
display="flex" | ||
> | ||
<TableContainer sx={{ width: 'auto' }}> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell>#</TableCell> | ||
<TableCell>Участник</TableCell> | ||
<TableCell>Позиция на карте</TableCell> | ||
<TableCell>Очки</TableCell> | ||
<TableCell>Пройдено игр</TableCell> | ||
<TableCell>Реролов</TableCell> | ||
<TableCell>Просмотрено фильмов</TableCell> | ||
<TableCell>Шейх-моментов</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{playersStatsByPosition.map((playerStat, index) => ( | ||
<TableRow key={index}> | ||
<TableCell>{index + 1}</TableCell> | ||
<TableCell>{playersById[playerStat.id].name}</TableCell> | ||
<TableCell>{playerStat.map_position}</TableCell> | ||
<TableCell>{0}</TableCell> | ||
<TableCell>{playerStat.games_completed}</TableCell> | ||
<TableCell>{playerStat.rerolls}</TableCell> | ||
<TableCell>{playerStat.movies}</TableCell> | ||
<TableCell>{playerStat.sheikh_moments}</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</TableContainer> | ||
</Box> | ||
</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
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