Fix aggregatesShowcase error handling

main
Kevin Belisle 2021-09-03 11:45:23 -04:00
parent 34e5e207d9
commit 7c637f181e
1 changed files with 31 additions and 47 deletions

View File

@ -2,59 +2,43 @@ import React from "react";
import { useQuery } from "react-query"; import { useQuery } from "react-query";
import axios from "axios"; import axios from "axios";
import { import { SimpleGrid, Stat, StatLabel, StatNumber } from "@chakra-ui/react";
AspectRatio,
Box,
Flex,
Heading,
HStack,
Icon,
SimpleGrid,
Stat,
StatLabel,
StatNumber,
StatHelpText,
StatArrow,
StatGroup,
Tooltip,
} from "@chakra-ui/react";
import { FaUserCircle, FaArrowAltCircleRight } from "react-icons/fa";
import { Link } from "react-router-dom";
import { AutoSizer, WindowScroller, List } from "react-virtualized";
import prettifyStatisticName from "./PrettifyStatisticName"; import prettifyStatisticName from "./PrettifyStatisticName";
import StackedBar from "./StackedBar"; import StackedBar from "./StackedBar";
const AggregatesShowcase = () => { const AggregatesShowcase = () => {
const aggregates = useQuery( const aggregates = useQuery(`aggregates`, async () => {
`aggregates`,
async () => {
const { data } = await axios.get(`/api/aggregates`); const { data } = await axios.get(`/api/aggregates`);
return data; return data;
}, });
{
placeholderData: [],
}
);
const killedAggregates = aggregates.data const killedAggregates = aggregates.isSuccess
? aggregates.data
.filter((x) => x.type === "minecraft:killed") .filter((x) => x.type === "minecraft:killed")
.sort((a, b) => b.value - a.value); .sort((a, b) => b.value - a.value)
const killedTotal = killedAggregates.reduce((acc, val) => acc + val.value, 0); : [];
// const killedTotal = killedAggregates.reduce((acc, val) => acc + val.value, 0);
const killedByAggregates = aggregates.data const killedByAggregates = aggregates.isSuccess
? aggregates.data
.filter((x) => x.type === "minecraft:killed_by") .filter((x) => x.type === "minecraft:killed_by")
.sort((a, b) => b.value - a.value); .sort((a, b) => b.value - a.value)
const killedByTotal = killedByAggregates.reduce( : [];
(acc, val) => acc + val.value, // const killedByTotal = killedByAggregates.reduce(
0 // (acc, val) => acc + val.value,
); // 0
// );
const travelAggregates = aggregates.data const travelAggregates = aggregates.isSuccess
.filter((x) => x.type === "minecraft:custom" && x.name.endsWith("one_cm")) ? aggregates.data
.sort((a, b) => b.value - a.value); .filter(
const travelTotal = travelAggregates.reduce((acc, val) => acc + val.value, 0); (x) => x.type === "minecraft:custom" && x.name.endsWith("one_cm")
)
.sort((a, b) => b.value - a.value)
: [];
// const travelTotal = travelAggregates.reduce((acc, val) => acc + val.value, 0);
return aggregates.isFetched ? ( return aggregates.isSuccess ? (
<> <>
<StackedBar heading="Mobs Killed" aggregates={killedAggregates} /> <StackedBar heading="Mobs Killed" aggregates={killedAggregates} />
@ -73,13 +57,13 @@ const AggregatesShowcase = () => {
.map((x, i) => { .map((x, i) => {
var value = x.value; var value = x.value;
if (x.name === "minecraft:play_one_minute") { if (x.name === "minecraft:play_one_minute") {
value = x.value / 20 / 60; value = Math.floor(x.value / 20 / 60);
} }
return ( return (
<Stat key={i}> <Stat key={i}>
<StatLabel>{prettifyStatisticName(x.type, x.name)}</StatLabel> <StatLabel>{prettifyStatisticName(x.type, x.name)}</StatLabel>
<StatNumber>{`${x.value <StatNumber>{`${value
.toString() .toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}`}</StatNumber> .replace(/\B(?=(\d{3})+(?!\d))/g, ",")}`}</StatNumber>
</Stat> </Stat>