Improve error handling - just display nothing
parent
d224ac81d8
commit
5b7885368f
|
@ -41,14 +41,17 @@ const App = () => {
|
||||||
<Statistic
|
<Statistic
|
||||||
type={routeProps.match.params.type}
|
type={routeProps.match.params.type}
|
||||||
name={routeProps.match.params.name}
|
name={routeProps.match.params.name}
|
||||||
players={players}
|
players={players.data}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/player/:id"
|
path="/player/:id"
|
||||||
render={(routeProps) => (
|
render={(routeProps) => (
|
||||||
<Player playerId={routeProps.match.params.id} players={players} />
|
<Player
|
||||||
|
playerId={routeProps.match.params.id}
|
||||||
|
players={players.data}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<Route>
|
<Route>
|
||||||
|
|
|
@ -16,19 +16,13 @@ import { Link } from "react-router-dom";
|
||||||
import prettifyStatisticName from "./PrettifyStatisticName";
|
import prettifyStatisticName from "./PrettifyStatisticName";
|
||||||
|
|
||||||
const Player = ({ playerId, players }) => {
|
const Player = ({ playerId, players }) => {
|
||||||
const playerStats = useQuery(
|
const playerStats = useQuery(`player ${playerId}`, async () => {
|
||||||
`player ${playerId}`,
|
|
||||||
async () => {
|
|
||||||
const { data } = await axios.get(`/api/players/${playerId}`);
|
const { data } = await axios.get(`/api/players/${playerId}`);
|
||||||
data.sort((a, b) => a.rank - b.rank || b.value - a.value);
|
data.sort((a, b) => a.rank - b.rank || b.value - a.value);
|
||||||
return data.filter((x) => x.value > 0);
|
return data.filter((x) => x.value > 0);
|
||||||
},
|
});
|
||||||
{
|
|
||||||
placeholderData: [],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const playerName = players.data.find((x) => x.id === playerId)?.name;
|
const playerName = players?.find((x) => x.id === playerId)?.name;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -60,7 +54,8 @@ const Player = ({ playerId, players }) => {
|
||||||
</Tr>
|
</Tr>
|
||||||
</Thead>
|
</Thead>
|
||||||
<Tbody>
|
<Tbody>
|
||||||
{playerStats.data.map((x, i) => {
|
{playerStats.isSuccess ? (
|
||||||
|
playerStats.data.map((x, i) => {
|
||||||
return (
|
return (
|
||||||
<Tr key={i}>
|
<Tr key={i}>
|
||||||
<Td>
|
<Td>
|
||||||
|
@ -72,7 +67,10 @@ const Player = ({ playerId, players }) => {
|
||||||
<Td isNumeric>{x.value}</Td>
|
<Td isNumeric>{x.value}</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
);
|
);
|
||||||
})}
|
})
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
</Tbody>
|
</Tbody>
|
||||||
</Table>
|
</Table>
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -15,19 +15,13 @@ import { Link } from "react-router-dom";
|
||||||
import prettifyStatisticName from "./PrettifyStatisticName";
|
import prettifyStatisticName from "./PrettifyStatisticName";
|
||||||
|
|
||||||
const Statistic = ({ type, name, players }) => {
|
const Statistic = ({ type, name, players }) => {
|
||||||
const ranking = useQuery(
|
const ranking = useQuery(`statistic ${type} ${name}`, async () => {
|
||||||
`statistic ${type} ${name}`,
|
|
||||||
async () => {
|
|
||||||
const { data } = await axios.get(`/api/statistics/${type}/${name}`);
|
const { data } = await axios.get(`/api/statistics/${type}/${name}`);
|
||||||
return data.filter((x) => x.value > 0);
|
return data.filter((x) => x.value > 0);
|
||||||
},
|
});
|
||||||
{
|
|
||||||
placeholderData: [],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const playerDict = useMemo(() => {
|
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]);
|
}, [players]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -52,7 +46,8 @@ const Statistic = ({ type, name, players }) => {
|
||||||
</Tr>
|
</Tr>
|
||||||
</Thead>
|
</Thead>
|
||||||
<Tbody>
|
<Tbody>
|
||||||
{ranking.data.map((x, i) => {
|
{ranking.isSuccess ? (
|
||||||
|
ranking.data.map((x, i) => {
|
||||||
return (
|
return (
|
||||||
<Tr key={i}>
|
<Tr key={i}>
|
||||||
<Td>
|
<Td>
|
||||||
|
@ -64,7 +59,10 @@ const Statistic = ({ type, name, players }) => {
|
||||||
<Td isNumeric>{x.value}</Td>
|
<Td isNumeric>{x.value}</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
);
|
);
|
||||||
})}
|
})
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
</Tbody>
|
</Tbody>
|
||||||
</Table>
|
</Table>
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in New Issue