Redesign the admin UI

Replaces the single-page dashboard with a structured app shell:
sidebar on desktop, bottom tab bar on mobile (PWA), and separate
screens for overview, short links, link pages, API tokens and
administration.

- detail view with tabs: content, appearance, analytics, QR code,
  settings
- small component kit (buttons, form controls, cards, dialogs,
  toasts, tabs) built on semantic color tokens with light and dark
  mode following the system
- native <dialog> modals for creating pages, editing blocks and
  confirmations instead of window.confirm
- theme presets and a live preview of unsaved appearance changes
- removed the v1 screenshots for now

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 14:21:07 +02:00
co-authored by Claude Opus 5.5
parent b217214512
commit 3929ed7663
36 changed files with 2477 additions and 876 deletions
+141 -70
View File
@@ -1,29 +1,107 @@
import { useState, type FormEvent } from "react";
import { useState } from "react";
import { KeyRound, Plus, Trash2 } from "lucide-react";
import type { ApiToken, CreatedToken } from "../../shared/api-types.js";
import { api, useApi } from "../api.js";
import { Field, useAction, useToast } from "../components/ui.js";
import { Button } from "../components/ui/button.js";
import { Dialog, useConfirm } from "../components/ui/dialog.js";
import { Field, Input } from "../components/ui/form.js";
import { CopyButton } from "../components/ui/misc.js";
import { Alert, Card, CardHeader, EmptyState, PageHeader, Skeleton } from "../components/ui/surface.js";
import { useAction } from "../components/ui/toast.js";
function relative(date: string): string {
const seconds = (new Date(date).getTime() - Date.now()) / 1000;
const units: [Intl.RelativeTimeFormatUnit, number][] = [
["year", 31536000],
["month", 2592000],
["day", 86400],
["hour", 3600],
["minute", 60],
];
const fmt = new Intl.RelativeTimeFormat(undefined, { numeric: "auto" });
for (const [unit, size] of units) {
if (Math.abs(seconds) >= size) return fmt.format(Math.round(seconds / size), unit);
}
return "just now";
}
function CreateTokenDialog({ open, onClose, onCreated }: { open: boolean; onClose: () => void; onCreated: () => void }) {
const [name, setName] = useState("");
const [created, setCreated] = useState<CreatedToken | null>(null);
const { busy, run } = useAction();
const close = () => {
setName("");
setCreated(null);
onClose();
};
if (created) {
return (
<Dialog
open={open}
onClose={close}
title="Token created"
description={`"${created.name}" is ready to use.`}
footer={<Button onClick={close}>Done</Button>}
>
<Alert title="Copy it now">You won't be able to see this token again.</Alert>
<div className="flex items-center gap-2">
<code className="flex-1 overflow-x-auto rounded-lg bg-surface-2 px-3 py-2 font-mono text-sm whitespace-nowrap">{created.token}</code>
<CopyButton value={created.token} label="Copy" />
</div>
</Dialog>
);
}
return (
<Dialog
open={open}
onClose={close}
title="New API token"
description="The token can do everything you can do in this dashboard."
onSubmit={() =>
void run(async () => {
setCreated(await api<CreatedToken>("POST", "/tokens", { name }));
onCreated();
})
}
footer={
<>
<Button variant="secondary" onClick={close}>
Cancel
</Button>
<Button type="submit" loading={busy} disabled={!name.trim()}>
Create token
</Button>
</>
}
>
<Field label="Name" hint="Something to recognize it by, e.g. where it's used.">
{(id) => <Input id={id} required autoFocus placeholder="iPhone Shortcut" value={name} onChange={(e) => setName(e.target.value)} />}
</Field>
</Dialog>
);
}
export function TokensScreen() {
const tokens = useApi<ApiToken[]>("/tokens");
const { busy, run } = useAction();
const toast = useToast();
const [name, setName] = useState("");
const [created, setCreated] = useState<CreatedToken | null>(null);
const [creating, setCreating] = useState(false);
const { run } = useAction();
const confirm = useConfirm();
const create = (e: FormEvent) => {
e.preventDefault();
void run(async () => {
setCreated(await api<CreatedToken>("POST", "/tokens", { name }));
setName("");
await tokens.reload();
const revoke = async (t: ApiToken) => {
const ok = await confirm({
title: `Revoke "${t.name}"?`,
description: "Scripts using this token stop working immediately.",
confirmLabel: "Revoke",
danger: true,
});
};
const revoke = (t: ApiToken) => {
if (!confirm(`Revoke "${t.name}"? Scripts using it stop working.`)) return;
void run(async () => {
await api("DELETE", `/tokens/${t.id}`);
await tokens.reload();
}, "Token revoked");
if (ok)
void run(async () => {
await api("DELETE", `/tokens/${t.id}`);
await tokens.reload();
}, "Token revoked");
};
const example = `curl -X POST ${location.origin}/~/api/pages \\
@@ -31,61 +109,54 @@ export function TokensScreen() {
-H "Content-Type: application/json" \\
-d '{"kind":"redirect","dest":"https://example.com"}'`;
const createButton = (
<Button icon={<Plus />} onClick={() => setCreating(true)}>
New token
</Button>
);
return (
<div className="flex flex-col gap-6">
<h1>API tokens</h1>
<p className="text-sm text-gray-400">Tokens act with your permissions. Use them for scripts or iOS Shortcuts.</p>
<>
<PageHeader title="API tokens" description="Create links from scripts, automations or iOS Shortcuts." actions={createButton} />
<form className="card" onSubmit={create}>
<Field label="Name">
<input required value={name} onChange={(e) => setName(e.target.value)} placeholder="e.g. iPhone Shortcut" />
</Field>
<button className="btn" disabled={busy}>
Create token
</button>
{created && (
<div className="mt-4 rounded border border-green-700 bg-green-900/30 p-3">
<p className="mb-2 text-sm">Copy this token now. It won't be shown again.</p>
<div className="flex gap-2">
<code className="flex-1 overflow-x-auto rounded bg-gray-900 px-2 py-1">{created.token}</code>
<button
type="button"
className="btn btn-secondary py-1"
onClick={() => navigator.clipboard.writeText(created.token).then(() => toast("Copied"))}
>
Copy
</button>
<div className="flex flex-col gap-6">
<Card className="overflow-hidden">
{!tokens.data ? (
<div className="flex flex-col gap-3 p-5">
<Skeleton className="h-10" />
<Skeleton className="h-10" />
</div>
</div>
)}
</form>
) : tokens.data.length ? (
<ul className="divide-y divide-border">
{tokens.data.map((t) => (
<li key={t.id} className="flex items-center gap-3 px-5 py-3.5">
<span className="flex size-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted">
<KeyRound className="size-4" />
</span>
<div className="min-w-0 flex-1">
<div className="truncate text-sm font-medium">{t.name}</div>
<div className="text-xs text-muted">
Created {relative(t.createdAt)} · {t.lastUsedAt ? `last used ${relative(t.lastUsedAt)}` : "never used"}
</div>
</div>
<Button variant="ghost" size="sm" icon={<Trash2 />} onClick={() => void revoke(t)} className="hover:text-danger">
Revoke
</Button>
</li>
))}
</ul>
) : (
<EmptyState icon={<KeyRound />} title="No tokens yet" description="Tokens let scripts use the API on your behalf." action={createButton} />
)}
</Card>
<section className="card">
<h2 className="mb-3">Your tokens</h2>
{tokens.data?.length ? (
tokens.data.map((t) => (
<div key={t.id} className="flex items-center justify-between gap-3 border-b border-gray-700 py-2 last:border-0">
<div>
<div className="font-semibold text-white">{t.name}</div>
<div className="text-xs text-gray-400">
created {new Date(t.createdAt).toLocaleDateString()} · last used{" "}
{t.lastUsedAt ? new Date(t.lastUsedAt).toLocaleString() : "never"}
</div>
</div>
<button className="btn btn-danger py-1" onClick={() => revoke(t)} disabled={busy}>
Revoke
</button>
</div>
))
) : (
<p className="text-gray-500">No tokens yet.</p>
)}
</section>
<Card>
<CardHeader title="Example" description="Create a short link with a random code." actions={<CopyButton value={example} />} />
<pre className="overflow-x-auto p-5 font-mono text-[13px] leading-relaxed text-muted">{example}</pre>
</Card>
</div>
<section className="card">
<h2 className="mb-3">Example</h2>
<pre className="overflow-x-auto rounded bg-gray-900 p-3 text-sm">{example}</pre>
</section>
</div>
<CreateTokenDialog open={creating} onClose={() => setCreating(false)} onCreated={() => void tokens.reload()} />
</>
);
}