import { useTRPC } from '@/integrations/trpc/react'; import { keepPreviousData, useQuery } from '@tanstack/react-query'; import { useReportChartContext } from '../context'; import { Chart } from './chart'; export function ReportMetricChart() { const { isLazyLoading, report } = useReportChartContext(); const trpc = useTRPC(); const res = useQuery( trpc.chart.chart.queryOptions(report, { placeholderData: keepPreviousData, staleTime: 1000 * 60 * 1, enabled: !isLazyLoading, }), ); if ( isLazyLoading || res.isLoading || (res.isFetching && !res.data?.series.length) ) { return ; } if (res.isError) { return ; } if (!res.data || res.data?.series.length === 0) { return ; } return ; } export function Loading() { return (
); } export function Error() { return (
Error fetching data
); } export function Empty() { return (
No data
); }