"use client"; import { AlertCircle, Clock, Hash, Heart, Shield, Sparkles, Users, } from "lucide-react"; import { useState } from "react"; import { ActivityChart } from "@/components/dashboard/activity-chart"; import { ChannelsSection } from "@/components/dashboard/channels-section"; import { HourlyActivityChart } from "@/components/dashboard/hourly-activity-chart"; import { ModerationDonut } from "@/components/dashboard/moderation-donut"; import { ReactionsSection } from "@/components/dashboard/reactions-section"; import { StatCard } from "@/components/dashboard/stat-card"; import { TopChannelsChart } from "@/components/dashboard/top-channels-chart"; import { UsersSection } from "@/components/dashboard/users-section"; import { SubNav } from "@/components/layout/sub-nav"; import { ErrorState, LoadingSkeleton } from "@/components/shared"; import { useActivity, useStats } from "@/hooks"; import type { DashboardActivity, DashboardStats } from "@/lib/types"; import { cn } from "@/lib/utils"; type DashboardTab = "stats" | "users" | "channels" | "reactions"; const DAY_RANGES = [7, 14, 30] as const; const MODERATION_COLORS: Record = { Clean: "oklch(0.72 0.16 155)", Flagged: "oklch(0.62 0.19 25)", Warned: "oklch(0.78 0.15 80)", Error: "oklch(0.55 0.02 245)", }; /** * Dashboard view — hydrated on the client but seeded with server-rendered * initial data. SWR takes over for revalidation after first paint. */ export default function DashboardView({ initialStats, initialActivity, }: { initialStats?: DashboardStats; initialActivity?: DashboardActivity; }) { const [tab, setTab] = useState("stats"); const [days, setDays] = useState(14); const { data: stats, error, mutate: refetch } = useStats(initialStats); const { data: activity } = useActivity( days, days === 14 ? initialActivity : undefined, ); const subNavTabs = [ { id: "stats", label: "Stats", icon: }, { id: "users", label: "Users", icon: }, { id: "channels", label: "Channels", icon: }, { id: "reactions", label: "Reactions", icon: }, ]; const moderationData = stats ? [ { name: "Clean", value: stats.total_clean, color: MODERATION_COLORS.Clean, }, { name: "Flagged", value: stats.total_flagged, color: MODERATION_COLORS.Flagged, }, { name: "Warned", value: stats.total_warned, color: MODERATION_COLORS.Warned, }, { name: "Error", value: stats.total_error, color: MODERATION_COLORS.Error, }, ].filter((d) => d.value > 0) : []; return (
setTab(t as DashboardTab)} /> {tab === "stats" && (
{error ? ( ) : !stats ? ( ) : ( <>
{DAY_RANGES.map((range) => ( ))}
{activity && }
{activity && }
({ name: c.channel_name ?? c.channel_id, count: c.message_count, }))} />
)}
)} {tab === "users" && } {tab === "channels" && } {tab === "reactions" && }
); }