Download src/components/dashboard/dashboard-client.tsx from NAP1320/RotNot: direct link, hf CLI and curl.
- Browser
- Download file 5.77 kB
-
https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/components/dashboard/dashboard-client.tsx
- Command line
-
hf download hf://spaces/NAP1320/RotNot/src/components/dashboard/dashboard-client.tsx
-
curl -L -o dashboard-client.tsx https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/components/dashboard/dashboard-client.tsx
5.77 kB
| "use client"; | |
| import { useEffect, useState } from "react"; | |
| import { DailyRing } from "./daily-ring"; | |
| import { StreakDisplay } from "./streak-display"; | |
| import { CategoryCard } from "./category-card"; | |
| import { ActivityFeed } from "./activity-feed"; | |
| import { WeeklyHeatmap } from "./weekly-heatmap"; | |
| import { type Category } from "@/config/xp"; | |
| import { Loader2 } from "lucide-react"; | |
| import { apiClient, ApiClientError, type DashboardResponse } from "@/lib/api-client"; | |
| export function DashboardClient() { | |
| const [data, setData] = useState<DashboardResponse | null>(null); | |
| const [error, setError] = useState<string | null>(null); | |
| useEffect(() => { | |
| apiClient | |
| .getDashboard() | |
| .then(setData) | |
| .catch((err: unknown) => { | |
| if (err instanceof ApiClientError) { | |
| setError(`Failed to load dashboard (${err.status})`); | |
| } else { | |
| setError("Failed to load dashboard data"); | |
| } | |
| }); | |
| }, []); | |
| if (error) { | |
| return ( | |
| <div className="max-w-5xl mx-auto"> | |
| <p style={{ color: "#f43f5e" }}>{error}</p> | |
| </div> | |
| ); | |
| } | |
| if (!data) { | |
| return ( | |
| <div className="max-w-5xl mx-auto flex items-center justify-center h-64"> | |
| <Loader2 size={32} className="animate-spin" style={{ color: "#6366f1" }} /> | |
| </div> | |
| ); | |
| } | |
| const { user, todayLog, categorySkills, recentActivities, weeklyLogs } = data; | |
| const xpToday = todayLog?.xpEarned ?? 0; | |
| const levelPct = Math.round((user.currentXp / user.xpToNextLevel) * 100); | |
| return ( | |
| <div className="max-w-5xl mx-auto space-y-8"> | |
| {/* Header */} | |
| <div> | |
| <h1 | |
| className="text-3xl font-bold mb-0.5" | |
| style={{ fontFamily: "var(--font-mono)" }} | |
| > | |
| {user.name} | |
| </h1> | |
| <p className="text-sm" style={{ color: "var(--text-secondary)" }}> | |
| {user.title} — Level {user.level} | |
| </p> | |
| </div> | |
| {/* Top stats row */} | |
| <div className="grid grid-cols-1 sm:grid-cols-3 gap-4"> | |
| {/* Daily ring */} | |
| <div className="glass-md rounded-xl p-5 flex flex-col items-center justify-center gap-2"> | |
| <span | |
| className="text-xs font-semibold uppercase tracking-wider mb-1" | |
| style={{ color: "var(--text-muted)" }} | |
| > | |
| Today | |
| </span> | |
| <DailyRing xpEarned={xpToday} goalXp={user.dailyGoalXp} /> | |
| </div> | |
| {/* Streak */} | |
| <div className="glass-md rounded-xl p-5 flex flex-col items-center justify-center gap-2"> | |
| <span | |
| className="text-xs font-semibold uppercase tracking-wider mb-1" | |
| style={{ color: "var(--text-muted)" }} | |
| > | |
| Streak | |
| </span> | |
| <StreakDisplay | |
| streak={user.streak} | |
| longestStreak={user.longestStreak} | |
| streakFreezes={user.streakFreezes} | |
| /> | |
| </div> | |
| {/* Overall level */} | |
| <div className="glass-md rounded-xl p-5 flex flex-col items-center justify-center gap-3"> | |
| <span | |
| className="text-xs font-semibold uppercase tracking-wider" | |
| style={{ color: "var(--text-muted)" }} | |
| > | |
| Overall Level | |
| </span> | |
| <div | |
| className="text-5xl font-bold" | |
| style={{ fontFamily: "var(--font-mono)", color: "#6366f1" }} | |
| > | |
| {user.level} | |
| </div> | |
| <div className="w-full space-y-1"> | |
| <div | |
| className="w-full rounded-full overflow-hidden" | |
| style={{ height: 6, background: "rgba(255,255,255,0.07)" }} | |
| > | |
| <div | |
| className="h-full rounded-full transition-all duration-1000" | |
| style={{ | |
| width: `${levelPct}%`, | |
| background: "linear-gradient(90deg, #6366f1, #8b5cf6)", | |
| }} | |
| /> | |
| </div> | |
| <div | |
| className="flex justify-between text-xs" | |
| style={{ color: "var(--text-muted)", fontFamily: "var(--font-mono)" }} | |
| > | |
| <span>{user.currentXp} XP</span> | |
| <span>{user.xpToNextLevel} XP</span> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| {/* Category grid */} | |
| <div> | |
| <h2 | |
| className="text-lg font-semibold mb-3" | |
| style={{ fontFamily: "var(--font-mono)", color: "var(--text-secondary)" }} | |
| > | |
| Skills | |
| </h2> | |
| <div className="grid grid-cols-2 sm:grid-cols-3 gap-3"> | |
| {categorySkills.map((cs) => ( | |
| <CategoryCard | |
| key={cs.category} | |
| category={cs.category as Category} | |
| level={cs.level} | |
| currentXp={cs.currentXp} | |
| xpToNext={cs.xpToNext} | |
| lastPlayedAt={cs.lastPlayedAt} | |
| /> | |
| ))} | |
| </div> | |
| </div> | |
| {/* Bottom row: heatmap + activity */} | |
| <div className="grid grid-cols-1 md:grid-cols-2 gap-4"> | |
| {/* Weekly heatmap */} | |
| <div className="glass-md rounded-xl p-5"> | |
| <h2 | |
| className="text-sm font-semibold mb-4" | |
| style={{ color: "var(--text-secondary)", fontFamily: "var(--font-mono)" }} | |
| > | |
| This Week | |
| </h2> | |
| <WeeklyHeatmap logs={weeklyLogs} goalXp={user.dailyGoalXp} /> | |
| </div> | |
| {/* Activity feed */} | |
| <div className="glass-md rounded-xl p-5"> | |
| <h2 | |
| className="text-sm font-semibold mb-4" | |
| style={{ color: "var(--text-secondary)", fontFamily: "var(--font-mono)" }} | |
| > | |
| Recent Activity | |
| </h2> | |
| <ActivityFeed activities={recentActivities} /> | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| } | |