Skip to content

Commit

Permalink
improve performance chart loading
Browse files Browse the repository at this point in the history
  • Loading branch information
afadil committed Dec 15, 2024
1 parent b4fc678 commit 9e6938a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,8 @@ export function usePerformanceData({
.map((result) => result.value);
},
enabled: selectedItems.length > 0 && !!dateRange?.from && !!dateRange?.to,
placeholderData: (previousData) => previousData,
staleTime: 30 * 1000,
refetchInterval: false,
});
}
50 changes: 36 additions & 14 deletions src/pages/performance/performance-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { DateRange } from 'react-day-picker';
import { ApplicationHeader } from '@/components/header';
import { ApplicationShell } from '@/components/shell';
import { EmptyPlaceholder } from '@/components/ui/empty-placeholder';
import { ReturnMethod, usePerformanceData } from './hooks/usePerformanceData';
import { ReturnMethod, usePerformanceData } from './hooks/use-performance-data';
import { BenchmarkSymbolSelector } from '@/components/benchmark-symbol-selector';

const PORTFOLIO_TOTAL: ComparisonItem = {
Expand All @@ -33,6 +33,36 @@ type ComparisonItem = {
name: string;
};

function PerformanceContent({
performanceData,
isLoading,
}: {
performanceData: any[] | undefined;
isLoading: boolean;
}) {
return (
<div className="relative">
{performanceData && performanceData.length > 0 && <PerformanceChart data={performanceData} />}

{!performanceData?.length && !isLoading && (
<EmptyPlaceholder
className="mx-auto flex h-[400px] max-w-[420px] items-center justify-center"
icon={<BarChart className="h-10 w-10" />}
title="No performance data"
description="Select accounts to compare their performance over time."
/>
)}

{/* Overlay loading indicator */}
{isLoading && (
<div className="absolute inset-0 flex items-center justify-center bg-background/50">
<Skeleton className="h-[400px] w-full bg-muted/50" />
</div>
)}
</div>
);
}

export default function PerformancePage() {
const [selectedItems, setSelectedItems] = useState<ComparisonItem[]>([PORTFOLIO_TOTAL]);
const [dateRange, setDateRange] = useState<DateRange | undefined>({
Expand Down Expand Up @@ -139,18 +169,10 @@ export default function PerformancePage() {
</div>
</CardHeader>
<CardContent className="space-y-6">
{isLoadingPerformance ? (
<Skeleton className="h-[400px] w-full" />
) : performanceData && performanceData.length > 0 ? (
<PerformanceChart data={performanceData} />
) : (
<EmptyPlaceholder
className="mx-auto flex h-[400px] max-w-[420px] items-center justify-center"
icon={<BarChart className="h-10 w-10" />}
title="No performance data"
description="Select accounts to compare their performance over time."
/>
)}
<PerformanceContent
performanceData={performanceData}
isLoading={isLoadingPerformance}
/>
</CardContent>
</Card>
</div>
Expand All @@ -168,7 +190,7 @@ function PerformanceDashboardSkeleton() {
<Skeleton className="h-4 w-[100px]" />
</CardHeader>
<CardContent>
<Skeleton className="h-[400px] w-full" />
<Skeleton className="h-[400px] w-full bg-muted/50" />
</CardContent>
</Card>
</main>
Expand Down

0 comments on commit 9e6938a

Please sign in to comment.