diff --git a/spa/src/App.js b/spa/src/App.js index eaed35b..2076b82 100644 --- a/spa/src/App.js +++ b/spa/src/App.js @@ -41,14 +41,17 @@ const App = () => { )} /> ( - + )} /> diff --git a/spa/src/Player.js b/spa/src/Player.js index 7d2574e..b310663 100644 --- a/spa/src/Player.js +++ b/spa/src/Player.js @@ -16,19 +16,13 @@ import { Link } from "react-router-dom"; import prettifyStatisticName from "./PrettifyStatisticName"; 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 || b.value - a.value); - return data.filter((x) => x.value > 0); - }, - { - placeholderData: [], - } - ); + const playerStats = useQuery(`player ${playerId}`, async () => { + const { data } = await axios.get(`/api/players/${playerId}`); + data.sort((a, b) => a.rank - b.rank || b.value - a.value); + return data.filter((x) => x.value > 0); + }); - const playerName = players.data.find((x) => x.id === playerId)?.name; + const playerName = players?.find((x) => x.id === playerId)?.name; return ( <> @@ -60,19 +54,23 @@ const Player = ({ playerId, players }) => { - {playerStats.data.map((x, i) => { - return ( - - - - {prettifyStatisticName(x.type, x.name)} - - - {x.rank} - {x.value} - - ); - })} + {playerStats.isSuccess ? ( + playerStats.data.map((x, i) => { + return ( + + + + {prettifyStatisticName(x.type, x.name)} + + + {x.rank} + {x.value} + + ); + }) + ) : ( + <>> + )} > diff --git a/spa/src/Statistic.js b/spa/src/Statistic.js index f85dcd1..09416cc 100644 --- a/spa/src/Statistic.js +++ b/spa/src/Statistic.js @@ -15,19 +15,13 @@ 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); - }, - { - placeholderData: [], - } - ); + 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.data.map((x) => ({ [x.id]: x.name }))); + return Object.assign({}, ...players.map((x) => ({ [x.id]: x.name }))); }, [players]); return ( @@ -52,19 +46,23 @@ const Statistic = ({ type, name, players }) => { - {ranking.data.map((x, i) => { - return ( - - - - {playerDict[x.playerId]} - - - {x.rank} - {x.value} - - ); - })} + {ranking.isSuccess ? ( + ranking.data.map((x, i) => { + return ( + + + + {playerDict[x.playerId]} + + + {x.rank} + {x.value} + + ); + }) + ) : ( + <>> + )} >