import React, { useMemo } from "react"; import { useQuery } from "react-query"; import axios from "axios"; import { Center, Heading, Table, Thead, Tbody, Tr, Th, Td, } from "@chakra-ui/react"; import { Link } from "react-router-dom"; import prettifyStatisticName from "./PrettifyStatisticName"; const Statistic = ({ type, name, players }) => { const ranking = useQuery(`statistic ${type} ${name}`, async () => { const { data } = await axios.get(`/api/statistics/${type}/${name}`); return data.filter((x) => x.value > 0); }); const playerDict = useMemo(() => { return Object.assign({}, ...players.map((x) => ({ [x.id]: x.name }))); }, [players]); return ( <>
📈
Stonks for {prettifyStatisticName(type, name)} {ranking.isSuccess ? ( ranking.data.map((x, i) => { return ( ); }) ) : ( <> )}
Player Rank Value
{playerDict[x.playerId]} {x.rank} {x.value}
); }; export default Statistic;