1
0
Fork 0
Stonks_mau/spa/src/Player.js

83 lines
1.9 KiB
JavaScript
Raw Normal View History

import React from "react";
2021-07-06 20:41:47 +00:00
import { useQuery } from "react-query";
import axios from "axios";
import {
Center,
Heading,
Image,
Table,
Thead,
Tbody,
Tr,
Th,
Td,
} from "@chakra-ui/react";
import { Link } from "react-router-dom";
2021-07-09 05:01:42 +00:00
import prettifyStatisticName from "./PrettifyStatisticName";
2021-07-06 20:41:47 +00:00
const Player = ({ playerId, players }) => {
const playerStats = useQuery(
`player ${playerId}`,
async () => {
const { data } = await axios.get(`/api/players/${playerId}`);
data.sort((a, b) => a.rank - b.rank);
2021-07-21 19:53:40 +00:00
return data.filter((x) => x.value > 0);
2021-07-06 20:41:47 +00:00
},
{
placeholderData: [],
}
);
2021-07-09 05:01:42 +00:00
const playerName = players.data.find((x) => x.id === playerId)?.name;
2021-07-06 20:41:47 +00:00
return (
<>
<Heading as="h2" size="4xl" my="8">
<Link to="/">
<Center>📈</Center>
</Link>
</Heading>
<Heading as="h3" size="sm" mt="8" fontWeight="normal">
Stonks for
</Heading>
<Heading as="h1" size="xl" mb="8">
<Image
display="inline"
width="48px"
height="48px"
src={`https://minotar.net/avatar/${playerId.replaceAll("-", "")}/48`}
mr="4"
2021-07-09 05:01:42 +00:00
rounded="md"
2021-07-06 20:41:47 +00:00
/>
{playerName}
2021-07-06 20:41:47 +00:00
</Heading>
<Table size="sm" variant="striped">
2021-07-06 20:41:47 +00:00
<Thead>
<Tr>
<Th>Statistic</Th>
<Th isNumeric>Rank</Th>
<Th isNumeric>Value</Th>
</Tr>
</Thead>
<Tbody>
{playerStats.data.map((x, i) => {
return (
<Tr key={i}>
<Td>
<Link to={`/statistic/${x.type}/${x.name}`}>
2021-07-09 05:01:42 +00:00
{prettifyStatisticName(x.type, x.name)}
2021-07-06 20:41:47 +00:00
</Link>
</Td>
<Td isNumeric>{x.rank}</Td>
<Td isNumeric>{x.value}</Td>
</Tr>
);
})}
</Tbody>
</Table>
</>
);
};
export default Player;