import { useMemo, useState } from "react"; import { Link } from "react-router-dom"; import type { PageSummary } from "@ledger/shared"; import { EmptyState } from "./EmptyState"; import { Icon } from "./Icon"; import { PageHeader } from "./PageHeader"; type Space = { id: string; name: string; key: string; visibility: string; }; export function SpacesPage({ spaces, pagesBySpace }: { spaces: Space[]; pagesBySpace: Record; }) { const [tab, setTab] = useState<"updated" | "public" | "internal">("updated"); const collections = useMemo( () => spaces .map((space) => ({ ...space, count: (pagesBySpace[space.key] ?? []).length })) .sort((a, b) => b.count - a.count || a.name.localeCompare(b.name)), [pagesBySpace, spaces] ); const allPages = useMemo( () => Object.values(pagesBySpace) .flat() .sort((a, b) => Date.parse(b.updatedAt) - Date.parse(a.updatedAt)), [pagesBySpace] ); const visiblePages = allPages.filter((page) => { if (tab === "public") { return page.visibility === "public"; } if (tab === "internal") { return page.visibility !== "public"; } return true; }); return (
{allPages.length === 0 ? (
) : ( <>
{visiblePages.map((page) => { const space = spaces.find((entry) => entry.id === page.spaceId); return (
{page.title}

Updated {new Date(page.updatedAt).toLocaleDateString()} in {space?.name ?? "Collection"} - {page.visibility}

); })}
)}
); }