Browse Source

fix(dashboard): throw on statistics fetch failure and constrain chart height

ding113 1 week ago
parent
commit
32342dcfd3

+ 4 - 3
src/app/[locale]/dashboard/_components/bento/dashboard-bento.tsx

@@ -60,9 +60,9 @@ async function fetchActiveSessions(): Promise<ActiveSessionInfo[]> {
   return result.data;
 }
 
-async function fetchStatistics(timeRange: TimeRange): Promise<UserStatisticsData | null> {
+async function fetchStatistics(timeRange: TimeRange): Promise<UserStatisticsData> {
   const result = await getUserStatistics(timeRange);
-  if (!result.ok) return null;
+  if (!result.ok) throw new Error(result.error || "Failed to fetch statistics");
   return result.data;
 }
 
@@ -140,12 +140,13 @@ export function DashboardBento({
   });
 
   // Statistics
-  const { data: statistics } = useQuery<UserStatisticsData | null>({
+  const { data: statistics } = useQuery<UserStatisticsData>({
     queryKey: ["statistics", timeRange],
     queryFn: () => fetchStatistics(timeRange),
     initialData: timeRange === DEFAULT_TIME_RANGE ? initialStatistics : undefined,
     staleTime: 30_000,
     placeholderData: keepPreviousData,
+    retry: 3,
   });
 
   // Leaderboards

+ 1 - 1
src/app/[locale]/dashboard/_components/bento/statistics-chart-card.tsx

@@ -168,7 +168,7 @@ export function StatisticsChartCard({
   };
 
   return (
-    <BentoCard className={cn("flex flex-col p-0 overflow-hidden", className)}>
+    <BentoCard className={cn("flex flex-col p-0 overflow-hidden max-h-[50vh]", className)}>
       {/* Header */}
       <div className="flex items-center justify-between border-b border-border/50 dark:border-white/[0.06]">
         <div className="flex items-center gap-4 p-4">