import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import type { PageSummary, SessionUser } from "@ledger/shared"; import { api } from "../lib/api"; import { EmptyState } from "./EmptyState"; import { Icon } from "./Icon"; import { PageHeader } from "./PageHeader"; type Space = { id: string; name: string; key: string; visibility: string; }; export function DraftsPage({ user, spaces }: { user: SessionUser | null; spaces: Space[]; }) { const [drafts, setDrafts] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { if (!user || user.role === "viewer" || user.role === "public") { setLoading(false); setDrafts([]); return; } api .get<{ pages: PageSummary[] }>("/api/pages/drafts") .then((response) => setDrafts(response.pages)) .catch((reason) => setError(reason instanceof Error ? reason.message : "Could not load drafts.")) .finally(() => setLoading(false)); }, [user]); return (
New draft : null} />
{loading ?

Loading drafts...

: null} {!loading && (!user || user.role === "viewer" || user.role === "public") ? ( ) : null} {!loading && error ? ( ) : null} {!loading && !error && drafts.length === 0 && user && user.role !== "viewer" && user.role !== "public" ? ( ) : null} {!loading && drafts.length > 0 ? (
{drafts.map((page) => (
{page.title}

{spaces.find((space) => space.id === page.spaceId)?.name ?? "Collection"} - draft

{page.excerpt ?? "Draft page without an excerpt yet."}

))}
) : null}
); }