import { useTRPC } from '@/integrations/trpc/react'; import { keepPreviousData, useQuery } from '@tanstack/react-query'; import { useOverviewOptions } from '@/components/overview/useOverviewOptions'; import { cn } from '@/utils/cn'; import { AspectContainer } from '../aspect-container'; import { ReportChartEmpty } from '../common/empty'; import { ReportChartError } from '../common/error'; import { useReportChartContext } from '../context'; import { Chart } from './chart'; export function ReportBarChart() { const { isLazyLoading, report, shareId } = useReportChartContext(); const trpc = useTRPC(); const { range, startDate, endDate, interval } = useOverviewOptions(); const res = useQuery( trpc.chart.aggregate.queryOptions( { ...report, shareId, reportId: 'id' in report ? report.id : undefined, range: range ?? report.range, startDate: startDate ?? report.startDate, endDate: endDate ?? report.endDate, interval: interval ?? report.interval, }, { 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 ; } function Loading() { const { isEditMode } = useReportChartContext(); return (
{Array.from({ length: 10 }).map((_, index) => (
{/* Icon skeleton */}
{/* Rank badge skeleton */}
{/* Name skeleton */}
{/* Count skeleton */}
{/* Bar skeleton */}
))}
); } function Error() { return ( ); } function Empty() { return ( ); }