Skip to content

Commit 9e6938a

Browse files
committed
improve performance chart loading
1 parent b4fc678 commit 9e6938a

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

src/pages/performance/hooks/usePerformanceData.ts renamed to src/pages/performance/hooks/use-performance-data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,8 @@ export function usePerformanceData({
6060
.map((result) => result.value);
6161
},
6262
enabled: selectedItems.length > 0 && !!dateRange?.from && !!dateRange?.to,
63+
placeholderData: (previousData) => previousData,
64+
staleTime: 30 * 1000,
65+
refetchInterval: false,
6366
});
6467
}

src/pages/performance/performance-page.tsx

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { DateRange } from 'react-day-picker';
1818
import { ApplicationHeader } from '@/components/header';
1919
import { ApplicationShell } from '@/components/shell';
2020
import { EmptyPlaceholder } from '@/components/ui/empty-placeholder';
21-
import { ReturnMethod, usePerformanceData } from './hooks/usePerformanceData';
21+
import { ReturnMethod, usePerformanceData } from './hooks/use-performance-data';
2222
import { BenchmarkSymbolSelector } from '@/components/benchmark-symbol-selector';
2323

2424
const PORTFOLIO_TOTAL: ComparisonItem = {
@@ -33,6 +33,36 @@ type ComparisonItem = {
3333
name: string;
3434
};
3535

36+
function PerformanceContent({
37+
performanceData,
38+
isLoading,
39+
}: {
40+
performanceData: any[] | undefined;
41+
isLoading: boolean;
42+
}) {
43+
return (
44+
<div className="relative">
45+
{performanceData && performanceData.length > 0 && <PerformanceChart data={performanceData} />}
46+
47+
{!performanceData?.length && !isLoading && (
48+
<EmptyPlaceholder
49+
className="mx-auto flex h-[400px] max-w-[420px] items-center justify-center"
50+
icon={<BarChart className="h-10 w-10" />}
51+
title="No performance data"
52+
description="Select accounts to compare their performance over time."
53+
/>
54+
)}
55+
56+
{/* Overlay loading indicator */}
57+
{isLoading && (
58+
<div className="absolute inset-0 flex items-center justify-center bg-background/50">
59+
<Skeleton className="h-[400px] w-full bg-muted/50" />
60+
</div>
61+
)}
62+
</div>
63+
);
64+
}
65+
3666
export default function PerformancePage() {
3767
const [selectedItems, setSelectedItems] = useState<ComparisonItem[]>([PORTFOLIO_TOTAL]);
3868
const [dateRange, setDateRange] = useState<DateRange | undefined>({
@@ -139,18 +169,10 @@ export default function PerformancePage() {
139169
</div>
140170
</CardHeader>
141171
<CardContent className="space-y-6">
142-
{isLoadingPerformance ? (
143-
<Skeleton className="h-[400px] w-full" />
144-
) : performanceData && performanceData.length > 0 ? (
145-
<PerformanceChart data={performanceData} />
146-
) : (
147-
<EmptyPlaceholder
148-
className="mx-auto flex h-[400px] max-w-[420px] items-center justify-center"
149-
icon={<BarChart className="h-10 w-10" />}
150-
title="No performance data"
151-
description="Select accounts to compare their performance over time."
152-
/>
153-
)}
172+
<PerformanceContent
173+
performanceData={performanceData}
174+
isLoading={isLoadingPerformance}
175+
/>
154176
</CardContent>
155177
</Card>
156178
</div>
@@ -168,7 +190,7 @@ function PerformanceDashboardSkeleton() {
168190
<Skeleton className="h-4 w-[100px]" />
169191
</CardHeader>
170192
<CardContent>
171-
<Skeleton className="h-[400px] w-full" />
193+
<Skeleton className="h-[400px] w-full bg-muted/50" />
172194
</CardContent>
173195
</Card>
174196
</main>

0 commit comments

Comments
 (0)