import CollapsibleFieldset from "@/ui/display/collapsible-fieldset"; import { VerticalLogItem } from "@/ui/display/log-item"; import ErrorDisplay from "@/ui/error-display"; import { useApi } from "@/util/api"; import { Center, Text, 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 ? (
) : totals.isError ? (
) : ( Totals {totalsData?.by_class?.map((category) => ( {category.aircraft_category} {category.classes.map((total) => ( <> ))} ))} )}
); }