import { useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import { DashboardLayout } from '../../components/dashboard/DashboardLayout'; import { GalleryCard } from '../../components/dashboard/GalleryCard'; import { StudioStat } from '../../components/dashboard/StudioStat'; import { useAuth } from '../../features/auth/useAuth'; import { deleteGallery, getGalleries } from '../../lib/api'; import { formatBytes } from '../../lib/format'; import type { GallerySummary } from '../../types/gallery'; export default function DashboardPage() { const { user } = useAuth(); const [galleries, setGalleries] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); useEffect(() => { getGalleries() .then(setGalleries) .catch((reason: unknown) => setError(reason instanceof Error ? reason.message : 'Could not load galleries.'), ) .finally(() => setLoading(false)); }, []); async function removeGallery(gallery: GallerySummary) { if (!window.confirm(`Delete "${gallery.title}"? This cannot be undone.`)) return; try { await deleteGallery(gallery.id); setGalleries((current) => current.filter((item) => item.id !== gallery.id)); } catch (reason) { setError(reason instanceof Error ? reason.message : 'Could not delete gallery.'); } } const photos = galleries.reduce((total, gallery) => total + gallery.photoCount, 0); const storage = galleries.reduce((total, gallery) => total + gallery.totalBytes, 0); const published = galleries.filter((gallery) => gallery.status === 'published').length; return (

{user?.name || 'Studio'} / Overview

Dashboard

New Gallery
{error &&

{error}

} {loading ? (
) : galleries.length === 0 ? (
+

No galleries yet

No galleries. Create one to start.

Create Gallery
) : (
{galleries.slice(0, 3).map((gallery) => ( ))}
)}
); }