+
+ {t.error ? : }
{t.message}
))}
@@ -46,7 +36,7 @@ export function ToastProvider({ children }: { children: ReactNode }) {
export const useToast = () => useContext(ToastContext);
-// Runs an async action with a busy flag and reports failures as a toast.
+// Runs an async action with a busy flag and reports the outcome as a toast.
export function useAction() {
const toast = useToast();
const [busy, setBusy] = useState(false);
@@ -68,7 +58,3 @@ export function useAction() {
);
return { busy, run };
}
-
-export function publicUrl(path: string): string {
- return `${location.origin}${path}`;
-}
diff --git a/src/web/lib/cx.ts b/src/web/lib/cx.ts
new file mode 100644
index 0000000..78986e9
--- /dev/null
+++ b/src/web/lib/cx.ts
@@ -0,0 +1,4 @@
+// Joins class names, skipping falsy values.
+export function cx(...classes: (string | false | null | undefined)[]): string {
+ return classes.filter(Boolean).join(" ");
+}
diff --git a/src/web/lib/markdown.ts b/src/web/lib/markdown.ts
new file mode 100644
index 0000000..efcdd18
--- /dev/null
+++ b/src/web/lib/markdown.ts
@@ -0,0 +1,8 @@
+// Rough plain-text version of Markdown for compact previews in the editor.
+export function stripMarkdown(markdown: string): string {
+ return markdown
+ .replace(/\[([^\]]*)\]\([^)]*\)/g, "$1")
+ .replace(/[*_`#>~]/g, "")
+ .replace(/\s+/g, " ")
+ .trim();
+}
diff --git a/src/web/main.tsx b/src/web/main.tsx
index 8a21e8e..740a082 100644
--- a/src/web/main.tsx
+++ b/src/web/main.tsx
@@ -1,80 +1,16 @@
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
-import type { Me } from "../shared/api-types.js";
-import { useApi } from "./api.js";
-import { Link, ToastProvider } from "./components/ui.js";
-import { usePath } from "./router.js";
-import { Dashboard } from "./screens/Dashboard.js";
-import { PageScreen } from "./screens/PageScreen.js";
-import { TokensScreen } from "./screens/TokensScreen.js";
+import { App } from "./app/App.js";
+import { ConfirmProvider } from "./components/ui/dialog.js";
+import { ToastProvider } from "./components/ui/toast.js";
import "./styles.css";
-function Login() {
- return (
-
- );
-}
-
-function App() {
- const me = useApi
("/me");
- const path = usePath();
-
- if (me.error?.status === 401) return ;
- if (me.error) return Could not reach the server: {me.error.message}
;
- if (!me.data) return null;
-
- const logout = async () => {
- await fetch("/~/auth/logout", { method: "POST", credentials: "same-origin" });
- location.href = "/~/";
- };
-
- const pageMatch = path.match(/^\/~\/pages\/(\d+)$/);
- const screen = pageMatch ? (
-
- ) : path === "/~/tokens" ? (
-
- ) : (
-
- );
-
- return (
-
-
-
-
- short
-
-
-
- {screen}
-
- );
-}
-
createRoot(document.getElementById("root")!).render(
-
+
+
+
,
);
diff --git a/src/web/router.ts b/src/web/router.ts
index b431b31..b55e317 100644
--- a/src/web/router.ts
+++ b/src/web/router.ts
@@ -1,10 +1,12 @@
import { useSyncExternalStore, type MouseEvent } from "react";
+import type { PageKind } from "../shared/api-types.js";
// A tiny history-based router; the app only has a handful of screens under /~/.
const listeners = new Set<() => void>();
export function navigate(to: string) {
history.pushState(null, "", to);
+ window.scrollTo({ top: 0 });
listeners.forEach((l) => l());
}
@@ -27,3 +29,35 @@ export function linkHandler(to: string) {
navigate(to);
};
}
+
+export type Route =
+ | { name: "overview" }
+ | { name: "list"; kind: PageKind }
+ | { name: "detail"; kind: PageKind; id: number; tab: string | undefined }
+ | { name: "tokens" }
+ | { name: "admin" }
+ | { name: "notFound" };
+
+const KIND_SEGMENT: Record = { links: "redirect", pages: "linkpage" };
+
+export function listPath(kind: PageKind): string {
+ return kind === "redirect" ? "/~/links" : "/~/pages";
+}
+
+export function detailPath(page: { id: number; kind: PageKind }, tab?: string): string {
+ return `${listPath(page.kind)}/${page.id}${tab ? `/${tab}` : ""}`;
+}
+
+export function parseRoute(path: string): Route {
+ const p = path.replace(/\/+$/, "") || "/~";
+ if (p === "/~") return { name: "overview" };
+ if (p === "/~/tokens") return { name: "tokens" };
+ if (p === "/~/admin") return { name: "admin" };
+ const m = p.match(/^\/~\/(links|pages)(?:\/(\d+)(?:\/([a-z]+))?)?$/);
+ if (m) {
+ const kind = KIND_SEGMENT[m[1]!]!;
+ if (!m[2]) return { name: "list", kind };
+ return { name: "detail", kind, id: Number(m[2]), tab: m[3] };
+ }
+ return { name: "notFound" };
+}
diff --git a/src/web/screens/AdminScreen.tsx b/src/web/screens/AdminScreen.tsx
new file mode 100644
index 0000000..abcdcda
--- /dev/null
+++ b/src/web/screens/AdminScreen.tsx
@@ -0,0 +1,124 @@
+import { useEffect, useState } from "react";
+import { PinOff, TriangleAlert, Users } from "lucide-react";
+import type { Conflict, PageSummary } from "../../shared/api-types.js";
+import { api, useApi } from "../api.js";
+import { Button } from "../components/ui/button.js";
+import { Select } from "../components/ui/form.js";
+import { Link } from "../components/ui/misc.js";
+import { Badge, Card, CardBody, CardHeader, EmptyState, PageHeader, Skeleton } from "../components/ui/surface.js";
+import { useAction } from "../components/ui/toast.js";
+import { detailPath } from "../router.js";
+
+function HomepageCard({ pages, reload }: { pages: PageSummary[]; reload: () => Promise }) {
+ const pinned = pages.find((p) => p.pinned);
+ const [selected, setSelected] = useState(pinned ? String(pinned.id) : "");
+ const { busy, run } = useAction();
+
+ useEffect(() => setSelected(pinned ? String(pinned.id) : ""), [pinned]);
+
+ const save = () =>
+ run(async () => {
+ if (selected) await api("PUT", "/pin", { pageId: Number(selected) });
+ else await api("DELETE", "/pin");
+ await reload();
+ }, selected ? "Homepage updated" : "Homepage cleared");
+
+ return (
+
+
+
+
+
+
+
+ {pinned && (
+ } onClick={() => setSelected("")}>
+ Clear
+
+ )}
+
+
+
+
+ );
+}
+
+export function AdminScreen() {
+ const pages = useApi("/pages");
+ const users = useApi("/users");
+ const conflicts = useApi("/conflicts");
+
+ const countByUser = new Map();
+ for (const p of pages.data ?? []) countByUser.set(p.namespace, (countByUser.get(p.namespace) ?? 0) + 1);
+
+ return (
+ <>
+
+
+
+ {pages.data ?
:
}
+
+
+
+ {!conflicts.data ? (
+
+ ) : conflicts.data.length ? (
+
+ {conflicts.data.map((c) => (
+ -
+
+ /{c.username}
+
+ Open root link
+
+
+ ))}
+
+ ) : (
+ No conflicts.
+ )}
+
+
+
+ {users.data.length}}
+ />
+ {!users.data ? (
+
+ ) : users.data.length ? (
+
+ {users.data.map((u) => (
+ -
+
+ {u.charAt(0)}
+
+ /{u}/
+
+ {countByUser.get(u) ?? 0} {(countByUser.get(u) ?? 0) === 1 ? "page" : "pages"}
+
+
+ ))}
+
+ ) : (
+ } title="No users yet" />
+ )}
+
+
+
+ >
+ );
+}
diff --git a/src/web/screens/Dashboard.tsx b/src/web/screens/Dashboard.tsx
deleted file mode 100644
index 3c88ecf..0000000
--- a/src/web/screens/Dashboard.tsx
+++ /dev/null
@@ -1,151 +0,0 @@
-import { useState, type FormEvent } from "react";
-import type { Conflict, Me, PageKind, PageSummary } from "../../shared/api-types.js";
-import { api, useApi } from "../api.js";
-import { Field, Link, publicUrl, useAction, useToast } from "../components/ui.js";
-import { navigate } from "../router.js";
-
-function CreateForm({ me, onCreated }: { me: Me; onCreated: () => void }) {
- const users = useApi(me.isAdmin ? "/users" : null);
- const { busy, run } = useAction();
- const [kind, setKind] = useState("redirect");
- const [namespace, setNamespace] = useState(me.username);
- const [code, setCode] = useState("");
- const [value, setValue] = useState("");
-
- const submit = (e: FormEvent) => {
- e.preventDefault();
- void run(async () => {
- const body = {
- kind,
- namespace,
- ...(code.trim() && { code: code.trim() }),
- ...(kind === "redirect" ? { dest: value.trim() } : { title: value.trim() }),
- };
- const page = await api("POST", "/pages", body);
- setCode("");
- setValue("");
- if (page.kind === "linkpage") navigate(`/~/pages/${page.id}`);
- else {
- await navigator.clipboard?.writeText(publicUrl(page.path)).catch(() => {});
- onCreated();
- }
- }, kind === "redirect" ? "Link created and copied" : "Link page created");
- };
-
- const prefix = namespace ? `/${namespace}/` : "/";
-
- return (
-
- );
-}
-
-function PageRow({ page }: { page: PageSummary }) {
- const toast = useToast();
- const copy = async () => {
- await navigator.clipboard.writeText(publicUrl(page.path));
- toast("Copied");
- };
- return (
-
-
-
- {page.path}
- {page.pinned && pinned to /}
-
-
{page.kind === "redirect" ? page.dest : page.title}
-
-
{page.totalClicks} clicks
-
-
- );
-}
-
-export function Dashboard({ me }: { me: Me }) {
- const pages = useApi("/pages");
- const conflicts = useApi(me.isAdmin ? "/conflicts" : null);
- const [filter, setFilter] = useState("");
-
- const visible = (pages.data ?? []).filter(
- (p) => !filter || p.path.toLowerCase().includes(filter.toLowerCase()) || (p.dest ?? p.title ?? "").toLowerCase().includes(filter.toLowerCase()),
- );
- const links = visible.filter((p) => p.kind === "redirect");
- const linkPages = visible.filter((p) => p.kind === "linkpage");
-
- return (
- <>
- {!!conflicts.data?.length && (
-
- Username conflicts:{" "}
- {conflicts.data.map((c, i) => (
-
- {i > 0 && ", "}
-
- /{c.username}
-
-
- ))}{" "}
- {conflicts.data.length === 1 ? "is" : "are"} both a root link and a username. Consider renaming the root link.
-
- )}
-
- Create
- void pages.reload()} />
-
-
-
Pages
- setFilter(e.target.value)} />
-
- {pages.error && {pages.error.message}
}
-
- Link pages
- {linkPages.length ? linkPages.map((p) => ) : None yet.
}
-
- Short links
- {links.length ? links.map((p) => ) : None yet.
}
- >
- );
-}
diff --git a/src/web/screens/ListScreen.tsx b/src/web/screens/ListScreen.tsx
new file mode 100644
index 0000000..0193b1c
--- /dev/null
+++ b/src/web/screens/ListScreen.tsx
@@ -0,0 +1,155 @@
+import { useMemo, useState } from "react";
+import { ChevronRight, Link2, PanelsTopLeft, Pin, Plus, Search } from "lucide-react";
+import type { Me, PageKind, PageSummary } from "../../shared/api-types.js";
+import { useApi } from "../api.js";
+import { CreatePageDialog } from "../components/CreatePageDialog.js";
+import { Button } from "../components/ui/button.js";
+import { Input, Select } from "../components/ui/form.js";
+import { CopyButton, DomainIcon, Link, publicUrl } from "../components/ui/misc.js";
+import { Badge, Card, EmptyState, PageHeader, Skeleton } from "../components/ui/surface.js";
+import { useToast } from "../components/ui/toast.js";
+import { detailPath, navigate } from "../router.js";
+
+const COPY: Record = {
+ redirect: {
+ title: "Short links",
+ description: "Short URLs that redirect to another address.",
+ create: "New short link",
+ empty: "No short links yet",
+ emptyText: "Create your first short link to share long URLs and track clicks.",
+ },
+ linkpage: {
+ title: "Link pages",
+ description: "Pages that collect several links, like a link in bio.",
+ create: "New link page",
+ empty: "No link pages yet",
+ emptyText: "Create a page with your avatar, link buttons and some text.",
+ },
+};
+
+function Row({ page }: { page: PageSummary }) {
+ const isLink = page.kind === "redirect";
+ return (
+
+ {isLink ? (
+
+ ) : (
+
+
+
+ )}
+
+
+ {/* The link stretches over the whole row; the copy button sits above it. */}
+
+ {page.path}
+
+ {page.pinned && (
+ }>
+ Home
+
+ )}
+
+
{isLink ? page.dest : page.title}
+
+
{isLink ? page.dest : page.title}
+
{page.totalClicks.toLocaleString()}
+
+
+ );
+}
+
+export function ListScreen({ kind, me }: { kind: PageKind; me: Me }) {
+ const pages = useApi("/pages");
+ const toast = useToast();
+ const [query, setQuery] = useState("");
+ const [namespace, setNamespace] = useState(null);
+ const [creating, setCreating] = useState(false);
+ const copy = COPY[kind];
+
+ const ofKind = useMemo(() => (pages.data ?? []).filter((p) => p.kind === kind), [pages.data, kind]);
+ const namespaces = useMemo(() => [...new Set(ofKind.map((p) => p.namespace))].sort(), [ofKind]);
+ const q = query.trim().toLowerCase();
+ const visible = ofKind.filter(
+ (p) =>
+ (namespace === null || p.namespace === namespace) &&
+ (!q || p.path.toLowerCase().includes(q) || (p.dest ?? p.title ?? "").toLowerCase().includes(q)),
+ );
+
+ const created = async (page: PageSummary) => {
+ if (page.kind === "linkpage") return navigate(detailPath(page));
+ await navigator.clipboard?.writeText(publicUrl(page.path)).catch(() => {});
+ toast(`Created ${page.path} — copied to clipboard`);
+ void pages.reload();
+ };
+
+ const createButton = (
+ } onClick={() => setCreating(true)}>
+ {copy.create}
+
+ );
+
+ return (
+ <>
+
+
+
+
+
+
+ setQuery(e.target.value)} aria-label="Search" />
+
+ {me.isAdmin && namespaces.length > 1 && (
+
+
+
+ )}
+
+
+
+
+ {kind === "redirect" ? "Short link" : "Page"}
+ {kind === "redirect" ? "Destination" : "Title"}
+ Clicks
+
+
+
+ {!pages.data ? (
+
+ {[0, 1, 2].map((i) => (
+
+ ))}
+
+ ) : visible.length ? (
+
+ {visible.map((p) => (
+
+ ))}
+
+ ) : ofKind.length ? (
+ } title="No matches" description="Try a different search or namespace." />
+ ) : (
+ : } title={copy.empty} description={copy.emptyText} action={createButton} />
+ )}
+
+
+ setCreating(false)} onCreated={created} />
+ >
+ );
+}
diff --git a/src/web/screens/OverviewScreen.tsx b/src/web/screens/OverviewScreen.tsx
new file mode 100644
index 0000000..06f25ab
--- /dev/null
+++ b/src/web/screens/OverviewScreen.tsx
@@ -0,0 +1,125 @@
+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 { 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 (
+
+ {top.map((p) => (
+ -
+
+ {p.kind === "redirect" ? (
+
+ ) : (
+
+
+
+ )}
+
+ {p.totalClicks.toLocaleString()}
+
+
+ ))}
+
+ );
+}
+
+export function OverviewScreen({ me }: { me: Me }) {
+ const pages = useApi("/pages");
+ const conflicts = useApi(me.isAdmin ? "/conflicts" : null);
+ const [creating, setCreating] = useState(null);
+
+ const all = pages.data ?? [];
+ 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 ? "across all namespaces" : `in /${me.username}/`;
+
+ return (
+ <>
+
+ } onClick={() => setCreating("linkpage")}>
+ New link page
+
+ } onClick={() => setCreating("redirect")}>
+ New short link
+
+ >
+ }
+ />
+
+
+ {!!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))}
+ />
+ )}
+ >
+ );
+}
diff --git a/src/web/screens/PageScreen.tsx b/src/web/screens/PageScreen.tsx
deleted file mode 100644
index 59db814..0000000
--- a/src/web/screens/PageScreen.tsx
+++ /dev/null
@@ -1,188 +0,0 @@
-import { useEffect, useState, type FormEvent } from "react";
-import type { Me, PageDetail } from "../../shared/api-types.js";
-import type { Theme } from "../../shared/validation.js";
-import { api, useApi } from "../api.js";
-import { BlockEditor } from "../components/BlockEditor.js";
-import { QrPanel } from "../components/QrPanel.js";
-import { StatsPanel } from "../components/StatsPanel.js";
-import { Field, Link, publicUrl, useAction, useToast } from "../components/ui.js";
-import { navigate } from "../router.js";
-
-const THEME_FIELDS: [keyof Theme, string][] = [
- ["background", "Background"],
- ["text", "Text"],
- ["button", "Button"],
- ["buttonText", "Button text"],
-];
-
-function RedirectSettings({ page, onSaved }: { page: PageDetail; onSaved: (p: PageDetail) => void }) {
- const [dest, setDest] = useState(page.dest ?? "");
- const { busy, run } = useAction();
- const submit = (e: FormEvent) => {
- e.preventDefault();
- void run(async () => onSaved(await api("PATCH", `/pages/${page.id}`, { dest })), "Saved");
- };
- return (
-
- );
-}
-
-function LinkPageSettings({ page, onSaved }: { page: PageDetail; onSaved: (p: PageDetail) => void }) {
- const [title, setTitle] = useState(page.title ?? "");
- const [theme, setTheme] = useState(page.theme);
- const { busy, run } = useAction();
-
- const submit = (e: FormEvent) => {
- e.preventDefault();
- void run(async () => onSaved(await api("PATCH", `/pages/${page.id}`, { title, theme })), "Saved");
- };
-
- const upload = (file: File | undefined) => {
- if (!file) return;
- const form = new FormData();
- form.append("file", file);
- void run(async () => {
- const { avatarUrl } = await api<{ avatarUrl: string }>("PUT", `/pages/${page.id}/avatar`, form);
- onSaved({ ...page, avatarUrl });
- }, "Avatar updated");
- };
- const removeAvatar = () =>
- run(async () => {
- await api("DELETE", `/pages/${page.id}/avatar`);
- onSaved({ ...page, avatarUrl: null });
- });
-
- return (
-
- );
-}
-
-export function PageScreen({ id, me }: { id: number; me: Me }) {
- const page = useApi(`/pages/${id}`);
- const toast = useToast();
- const { busy, run } = useAction();
- const [previewKey, setPreviewKey] = useState(0);
-
- // Reload the preview whenever the page changes.
- useEffect(() => setPreviewKey((k) => k + 1), [page.data]);
-
- if (page.error) {
- return (
-
- {page.error.status === 404 ? "Page not found." : page.error.message}{" "}
-
- Back
-
-
- );
- }
- const p = page.data;
- if (!p) return null;
- const url = publicUrl(p.path);
-
- const remove = () => {
- if (!confirm(`Delete ${p.path}? Its stats and any buttons pointing to it are removed too.`)) return;
- void run(async () => {
- await api("DELETE", `/pages/${p.id}`);
- navigate("/~/");
- }, "Deleted");
- };
- const togglePin = () =>
- run(async () => {
- if (p.pinned) await api("DELETE", "/pin");
- else await api("PUT", "/pin", { pageId: p.id });
- await page.reload();
- }, p.pinned ? "Unpinned" : "Pinned to /");
-
- return (
-
-
-
-
- ← All pages
-
-
{p.path}
-
{p.kind === "redirect" ? "Short link" : "Link page"}
-
-
-
- Open
-
-
- {me.isAdmin && (
-
- )}
-
-
-
-
- {p.kind === "redirect" ? (
-
- ) : (
-
-
-
- page.set({ ...p, blocks })}
- />
-
-
-
Preview
-
-
-
- )}
-
-
-
-
- );
-}
diff --git a/src/web/screens/TokensScreen.tsx b/src/web/screens/TokensScreen.tsx
index 9d9dfe0..c995d49 100644
--- a/src/web/screens/TokensScreen.tsx
+++ b/src/web/screens/TokensScreen.tsx
@@ -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(null);
+ const { busy, run } = useAction();
+
+ const close = () => {
+ setName("");
+ setCreated(null);
+ onClose();
+ };
+
+ if (created) {
+ return (
+
+ );
+ }
+
+ return (
+
+ );
+}
export function TokensScreen() {
const tokens = useApi("/tokens");
- const { busy, run } = useAction();
- const toast = useToast();
- const [name, setName] = useState("");
- const [created, setCreated] = useState(null);
+ const [creating, setCreating] = useState(false);
+ const { run } = useAction();
+ const confirm = useConfirm();
- const create = (e: FormEvent) => {
- e.preventDefault();
- void run(async () => {
- setCreated(await api("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 = (
+ } onClick={() => setCreating(true)}>
+ New token
+
+ );
+
return (
-
-
API tokens
-
Tokens act with your permissions. Use them for scripts or iOS Shortcuts.
+ <>
+
-