Download src/components/dashboard/weekly-heatmap.tsx from NAP1320/RotNot: direct link, hf CLI and curl.
- Browser
- Download file 2.42 kB
-
https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/components/dashboard/weekly-heatmap.tsx
- Command line
-
hf download hf://spaces/NAP1320/RotNot/src/components/dashboard/weekly-heatmap.tsx
-
curl -L -o weekly-heatmap.tsx https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/components/dashboard/weekly-heatmap.tsx
2.42 kB
| "use client"; | |
| import { format, subDays, startOfDay, isSameDay } from "date-fns"; | |
| interface DayLog { | |
| date: string; | |
| xpEarned: number; | |
| activityCount: number; | |
| goalMet: boolean; | |
| } | |
| interface WeeklyHeatmapProps { | |
| logs: DayLog[]; | |
| goalXp: number; | |
| } | |
| export function WeeklyHeatmap({ logs, goalXp }: WeeklyHeatmapProps) { | |
| const today = startOfDay(new Date()); | |
| const days = Array.from({ length: 7 }, (_, i) => subDays(today, 6 - i)); | |
| const getLog = (day: Date) => | |
| logs.find((l) => isSameDay(new Date(l.date), day)); | |
| const maxXp = Math.max(goalXp, ...logs.map((l) => l.xpEarned), 1); | |
| return ( | |
| <div className="flex items-end gap-2 justify-between"> | |
| {days.map((day) => { | |
| const log = getLog(day); | |
| const xp = log?.xpEarned ?? 0; | |
| const intensity = xp / maxXp; | |
| const isToday = isSameDay(day, today); | |
| const goalMet = log?.goalMet ?? false; | |
| // Color: goal met = indigo, partial = dimmer indigo, none = surface | |
| const bg = xp === 0 | |
| ? "rgba(255,255,255,0.05)" | |
| : goalMet | |
| ? "#6366f1" | |
| : `rgba(99,102,241,${0.2 + intensity * 0.5})`; | |
| const barHeight = xp === 0 ? 12 : Math.max(16, Math.round(intensity * 64)); | |
| return ( | |
| <div key={day.toISOString()} className="flex flex-col items-center gap-1 flex-1"> | |
| {/* XP label */} | |
| <span | |
| className="text-xs leading-none" | |
| style={{ | |
| fontFamily: "var(--font-mono)", | |
| color: xp > 0 ? "var(--text-secondary)" : "transparent", | |
| }} | |
| > | |
| {xp > 0 ? xp : ""} | |
| </span> | |
| {/* Bar */} | |
| <div | |
| className="w-full rounded-t-sm transition-all duration-500" | |
| style={{ | |
| height: barHeight, | |
| background: bg, | |
| boxShadow: goalMet ? "0 0 8px rgba(99,102,241,0.5)" : undefined, | |
| border: isToday ? "1px solid rgba(99,102,241,0.6)" : "none", | |
| }} | |
| /> | |
| {/* Day label */} | |
| <span | |
| className="text-xs" | |
| style={{ | |
| color: isToday ? "#6366f1" : "var(--text-muted)", | |
| fontWeight: isToday ? 700 : 400, | |
| }} | |
| > | |
| {format(day, "EEE")[0]} | |
| </span> | |
| </div> | |
| ); | |
| })} | |
| </div> | |
| ); | |
| } | |