From 91f6da1f5e740884e1937a558bdb8e36a1968bfe Mon Sep 17 00:00:00 2001 From: april Date: Thu, 11 Jan 2024 16:40:54 -0600 Subject: [PATCH] Add totals by class --- web/app/routes/logbook.dashboard/route.tsx | 84 ++++++++++++++++++---- 1 file changed, 69 insertions(+), 15 deletions(-) diff --git a/web/app/routes/logbook.dashboard/route.tsx b/web/app/routes/logbook.dashboard/route.tsx index 6185e7c..6cefbee 100644 --- a/web/app/routes/logbook.dashboard/route.tsx +++ b/web/app/routes/logbook.dashboard/route.tsx @@ -3,17 +3,31 @@ import { VerticalLogItem } from "@/ui/display/log-item"; import ErrorDisplay from "@/ui/error-display"; import { useApi } from "@/util/api"; import { Center, Group, Loader, Container, Stack, Title } from "@mantine/core"; +import { randomId } from "@mantine/hooks"; import { useQuery } from "@tanstack/react-query"; +import { useEffect, useState } from "react"; export default function Dashboard() { const client = useApi(); + const [totalsData, setTotalsData] = useState<{ + by_class: object; + totals: object; + } | null>(null); + const totals = useQuery({ queryKey: ["totals"], queryFn: async () => await client.get(`/flights/totals`).then((res) => res.data), }); + useEffect(() => { + if (totals.isFetched && !!totals.data) { + console.log(totals.data); + setTotalsData(totals.data); + } + }, [totals.data]); + return ( {totals.isLoading ? ( @@ -29,50 +43,90 @@ export default function Dashboard() { Totals - - - - + + + + + + + {totalsData?.by_class?.map((total: object[]) => ( + <> + + + ))} + + - + - + + + - - - +