Use Supabase data for dashboard stats
cgen-9f82f54e643646fabb4123dae484a53d
This commit is contained in:
parent
e98476e055
commit
45d63e45ca
1 changed files with 26 additions and 2 deletions
|
|
@ -372,6 +372,20 @@ export default function Dashboard() {
|
||||||
setAchievements([]);
|
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)
|
// Calculate stats (treat planning and in_progress as active)
|
||||||
const activeCount = userProjects.filter(
|
const activeCount = userProjects.filter(
|
||||||
(p) => p.status === "in_progress" || p.status === "planning",
|
(p) => p.status === "in_progress" || p.status === "planning",
|
||||||
|
|
@ -380,11 +394,21 @@ export default function Dashboard() {
|
||||||
(p) => p.status === "completed",
|
(p) => p.status === "completed",
|
||||||
).length;
|
).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({
|
setStats({
|
||||||
activeProjects: activeCount,
|
activeProjects: activeCount,
|
||||||
completedTasks: completedCount,
|
completedTasks: completedCount,
|
||||||
teamMembers: 8, // Mock for now
|
teamMembers: followerCount,
|
||||||
performanceScore: `${Math.min(95, 70 + completedCount * 5)}%`,
|
performanceScore: `${performanceScore}%`,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error loading dashboard data:", error);
|
console.error("Error loading dashboard data:", error);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue