import { useState, useEffect } from 'react'; import { useAuth } from '../../../stores/auth'; import { getPosts, deletePost, ApiError } from '../../../lib/api'; import type { Post } from '../../../lib/types'; export default function Dashboard() { const [posts, setPosts] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); const logout = useAuth(s => s.logout); async function loadPosts() { setLoading(true); setError(''); try { setPosts(await getPosts()); } catch (e) { setError(e instanceof ApiError ? e.message : 'Failed to load posts.'); } finally { setLoading(false); } } useEffect(() => { loadPosts(); }, []); async function handleDelete(slug: string) { if (!confirm(`Are you sure you want to delete "${slug}"?`)) return; try { await deletePost(slug); loadPosts(); } catch { setError('Failed to delete post.'); } } function handleLogout() { logout(); window.location.href = '/'; } return ( <>
{/* Quick Links */}
{/* Posts List */}

Manage Posts

{loading && (
)} {error &&
{error}
} {!loading && posts.length === 0 && !error && (
No posts yet.
)} {posts.map(post => (

{post.slug}

/posts/{post.slug}

))}
); } const ICONS: Record = { write: , assets: , settings: , }; function QuickLink({ href, icon, title, desc, color, hoverColor }: { href: string; icon: string; title: string; desc: string; color: string; hoverColor: string }) { return (
{ICONS[icon]}

{title}

{desc}

); }