fix(dashboard): remove loading state when we already have some data

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-09-20 15:01:08 +02:00
parent 49a020009f
commit 0959ede055
10 changed files with 50 additions and 12 deletions

View File

@@ -15,7 +15,11 @@ export function ReportAreaChart() {
staleTime: 1000 * 60 * 1, staleTime: 1000 * 60 * 1,
}); });
if (isLazyLoading || res.isLoading || res.isFetching) { if (
isLazyLoading ||
res.isLoading ||
(res.isFetching && !res.data?.series.length)
) {
return <Loading />; return <Loading />;
} }

View File

@@ -14,7 +14,11 @@ export function ReportBarChart() {
staleTime: 1000 * 60 * 1, staleTime: 1000 * 60 * 1,
}); });
if (isLazyLoading || res.isLoading || res.isFetching) { if (
isLazyLoading ||
res.isLoading ||
(res.isFetching && !res.data?.series.length)
) {
return <Loading />; return <Loading />;
} }

View File

@@ -98,7 +98,7 @@ export function Chart({
> >
<div <div
className={cn( className={cn(
'bg-def-400 w-full', 'bg-foreground w-full',
step.event.id === mostDropoffs.event.id && 'bg-rose-500', step.event.id === mostDropoffs.event.id && 'bg-rose-500',
)} )}
style={{ height: `${step.percent}%` }} style={{ height: `${step.percent}%` }}
@@ -236,7 +236,13 @@ export function Chart({
</div> </div>
<Progress <Progress
size="lg" size="lg"
className="w-full @2xl:w-1/2 text-white bg-def-200 mt-0.5 dark:text-black" className={cn(
'w-full @2xl:w-1/2 text-white bg-def-200 mt-0.5 dark:text-black',
)}
innerClassName={cn(
'bg-primary',
step.event.id === mostDropoffs.event.id && 'bg-rose-500',
)}
value={percent} value={percent}
/> />
</div> </div>

View File

@@ -31,7 +31,7 @@ export function ReportFunnelChart() {
keepPreviousData: true, keepPreviousData: true,
}); });
if (isLazyLoading || res.isLoading || res.isFetching) { if (isLazyLoading || res.isLoading) {
return <Loading />; return <Loading />;
} }

View File

@@ -15,7 +15,11 @@ export function ReportHistogramChart() {
staleTime: 1000 * 60 * 1, staleTime: 1000 * 60 * 1,
}); });
if (isLazyLoading || res.isLoading || res.isFetching) { if (
isLazyLoading ||
res.isLoading ||
(res.isFetching && !res.data?.series.length)
) {
return <Loading />; return <Loading />;
} }

View File

@@ -15,7 +15,11 @@ export function ReportLineChart() {
staleTime: 1000 * 60 * 1, staleTime: 1000 * 60 * 1,
}); });
if (isLazyLoading || res.isLoading || res.isFetching) { if (
isLazyLoading ||
res.isLoading ||
(res.isFetching && !res.data?.series.length)
) {
return <Loading />; return <Loading />;
} }

View File

@@ -15,7 +15,11 @@ export function ReportMapChart() {
staleTime: 1000 * 60 * 1, staleTime: 1000 * 60 * 1,
}); });
if (isLazyLoading || res.isLoading || res.isFetching) { if (
isLazyLoading ||
res.isLoading ||
(res.isFetching && !res.data?.series.length)
) {
return <Loading />; return <Loading />;
} }

View File

@@ -11,7 +11,11 @@ export function ReportMetricChart() {
staleTime: 1000 * 60 * 1, staleTime: 1000 * 60 * 1,
}); });
if (isLazyLoading || res.isLoading || res.isFetching) { if (
isLazyLoading ||
res.isLoading ||
(res.isFetching && !res.data?.series.length)
) {
return <Loading />; return <Loading />;
} }

View File

@@ -15,7 +15,11 @@ export function ReportPieChart() {
staleTime: 1000 * 60 * 1, staleTime: 1000 * 60 * 1,
}); });
if (isLazyLoading || res.isLoading || res.isFetching) { if (
isLazyLoading ||
res.isLoading ||
(res.isFetching && !res.data?.series.length)
) {
return <Loading />; return <Loading />;
} }

View File

@@ -7,8 +7,9 @@ const Progress = React.forwardRef<
React.ElementRef<typeof ProgressPrimitive.Root>, React.ElementRef<typeof ProgressPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root> & { React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root> & {
size?: 'sm' | 'default' | 'lg'; size?: 'sm' | 'default' | 'lg';
innerClassName?: string;
} }
>(({ className, value, size = 'default', ...props }, ref) => ( >(({ className, innerClassName, value, size = 'default', ...props }, ref) => (
<ProgressPrimitive.Root <ProgressPrimitive.Root
ref={ref} ref={ref}
className={cn( className={cn(
@@ -20,7 +21,10 @@ const Progress = React.forwardRef<
{...props} {...props}
> >
<ProgressPrimitive.Indicator <ProgressPrimitive.Indicator
className={'h-full w-full flex-1 rounded bg-primary transition-all'} className={cn(
'h-full w-full flex-1 rounded bg-primary transition-all',
innerClassName,
)}
style={{ style={{
transform: `translateX(-${100 - (value || 0)}%)`, transform: `translateX(-${100 - (value || 0)}%)`,
}} }}