From 45d63e45ca6f03b261786216a63fddc646446ee4 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Tue, 30 Sep 2025 23:14:55 +0000 Subject: [PATCH] Use Supabase data for dashboard stats cgen-9f82f54e643646fabb4123dae484a53d --- client/pages/Dashboard.tsx | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/client/pages/Dashboard.tsx b/client/pages/Dashboard.tsx index f12e97bd..e31d2708 100644 --- a/client/pages/Dashboard.tsx +++ b/client/pages/Dashboard.tsx @@ -372,6 +372,20 @@ export default function Dashboard() { setAchievements([]); } + // Load follower count for real collaboration insight + let followerCount = 0; + try { + const { count, error } = await supabase + .from("user_follows") + .select("id", { count: "exact", head: true }) + .eq("following_id", user!.id); + if (!error && typeof count === "number") { + followerCount = count; + } + } catch (e) { + console.warn("Could not load follower count:", e); + } + // Calculate stats (treat planning and in_progress as active) const activeCount = userProjects.filter( (p) => p.status === "in_progress" || p.status === "planning", @@ -380,11 +394,21 @@ export default function Dashboard() { (p) => p.status === "completed", ).length; + const totalXp = typeof (profile as any)?.total_xp === "number" + ? (profile as any).total_xp + : 0; + const performanceBase = + 60 + activeCount * 5 + completedCount * 8 + userAchievements.length * 3; + const performanceScore = Math.min( + 100, + Math.round(performanceBase + totalXp / 150), + ); + setStats({ activeProjects: activeCount, completedTasks: completedCount, - teamMembers: 8, // Mock for now - performanceScore: `${Math.min(95, 70 + completedCount * 5)}%`, + teamMembers: followerCount, + performanceScore: `${performanceScore}%`, }); } catch (error) { console.error("Error loading dashboard data:", error);