import { useState } from "react"; import { ArrowRight, Link2, MousePointerClick, PanelsTopLeft, Plus, TrendingUp } from "lucide-react"; import type { Conflict, Me, PageKind, PageSummary } from "../../shared/api-types.js"; import { useApi } from "../api.js"; import { CreatePageDialog } from "../components/CreatePageDialog.js"; import { Button, buttonClass } from "../components/ui/button.js"; import { DomainIcon, Link, Stat } from "../components/ui/misc.js"; import { Alert, Card, CardHeader, EmptyState, PageHeader, Skeleton } from "../components/ui/surface.js"; import { isMine } from "../lib/scope.js"; import { detailPath, navigate } from "../router.js"; function TopPages({ pages }: { pages: PageSummary[] }) { const top = pages.filter((p) => p.totalClicks > 0).sort((a, b) => b.totalClicks - a.totalClicks).slice(0, 6); const max = Math.max(1, ...top.map((p) => p.totalClicks)); if (!top.length) { return } title="No clicks yet" description="Once people open your links, the most visited ones show up here." />; } return ( ); } export function OverviewScreen({ me }: { me: Me }) { const pages = useApi("/pages"); const conflicts = useApi(me.isAdmin ? "/conflicts" : null); const [creating, setCreating] = useState(null); // Admins see their own and root content here; other users' content is under Administration. const all = (pages.data ?? []).filter((p) => isMine(p, me)); const links = all.filter((p) => p.kind === "redirect"); const linkPages = all.filter((p) => p.kind === "linkpage"); const clicks = all.reduce((sum, p) => sum + p.totalClicks, 0); const scope = me.isAdmin ? "yours & root" : `in /${me.username}/`; return ( <> } />
{!!conflicts.data?.length && ( {conflicts.data.map((c, i) => ( {i > 0 && ", "} /{c.username} ))}{" "} {conflicts.data.length === 1 ? "is" : "are"} both a root link and a username. Consider deleting or recreating the root link under another code. )}
{pages.data ? ( <> } hint={scope} /> } hint={scope} /> } hint="all time" /> ) : ( [0, 1, 2].map((i) => ) )}
All links } /> {pages.data ? : }
{creating && ( setCreating(null)} onCreated={(page) => navigate(detailPath(page))} /> )} ); }