"use client"; import { useState } from "react"; export default function StatsDashboard() { const [authenticated, setAuthenticated] = useState(false); const [password, setPassword] = useState(""); const [stats, setStats] = useState<{ views: number; projectsViewed: Record; } | null>(null); const [error, setError] = useState(""); const handleLogin = () => { // Simple password check. Replace with secure authentication. if (password === "admin123") { setAuthenticated(true); fetchStats(); } else { setError("Incorrect password."); } }; const fetchStats = async () => { try { const res = await fetch("/api/stats"); const data = await res.json(); setStats(data); } catch (err) { console.error(err); setError("Failed to fetch stats."); } }; if (!authenticated) { return (

Admin Login

{error &&

{error}

} setPassword(e.target.value)} />
); } return (

Statistics Dashboard

{stats ? (

Total Views: {stats.views}

Project Views:

    {Object.entries(stats.projectsViewed).map(([projectId, count]) => (
  • Project ID {projectId}: {count} view{count !== 1 ? "s" : ""}
  • ))}
) : (

Loading statistics...

)}
); }