[web] Design review: last row's menu not clipped, Hostname focused after loading, popover closes on Esc and outside click, phone engine chip in the top bar, paused and needs-attention copy with Restore in the panel, change bar offers and countdown, focus after share and kept, fingerprint check when signing by hand, draft kept through sign-in
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
// Shared UI state: the overview (polled, handoff §3), the route, contact and sign-in state,
|
||||
// the server clock offset and toasts. No business logic: everything shown comes from control.
|
||||
|
||||
import { call, setClientEvents } from "./api";
|
||||
import { call, newKey, sentence, setClientEvents } from "./api";
|
||||
import type { Overview } from "./types";
|
||||
|
||||
export interface Toast {
|
||||
@@ -31,6 +31,10 @@ export const app = $state({
|
||||
switchResult: null as null | { ok: boolean; title: string; text: string; detail?: string | null },
|
||||
/** A renewal just installed (handoff §13.5). */
|
||||
renewedUntil: null as null | string,
|
||||
/** After a kept add or edit: the row whose More button gets focus (§7.5). */
|
||||
focusHost: null as string | null,
|
||||
/** Narrower than 720 px (the phone layout, handoff §5.2). */
|
||||
phone: false,
|
||||
/** Panels the main screen opens (add/edit host, share, engine). */
|
||||
panel: null as null | { kind: "host"; hostname?: string; resume?: string } | { kind: "share"; hostname: string } | { kind: "engine" },
|
||||
});
|
||||
@@ -135,6 +139,12 @@ export function navigate(path: string): void {
|
||||
app.path = path;
|
||||
}
|
||||
|
||||
if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
|
||||
const mq = window.matchMedia("(max-width: 719.98px)");
|
||||
app.phone = mq.matches;
|
||||
mq.addEventListener?.("change", (e) => (app.phone = e.matches));
|
||||
}
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
window.addEventListener("popstate", () => {
|
||||
app.path = location.pathname + location.search;
|
||||
@@ -148,3 +158,23 @@ export function changesBlocked(): string | null {
|
||||
if (o?.paused) return "Changes are paused.";
|
||||
return null;
|
||||
}
|
||||
|
||||
/** "Restore the last kept version" (handoff §7.6): start it and show its progress in a panel.
|
||||
* Returns the sentence to show when it could not start. */
|
||||
export async function restoreLastKept(): Promise<string | null> {
|
||||
const o = app.overview;
|
||||
if (!o?.undo?.target) return null;
|
||||
try {
|
||||
const a = await call<{ apply: { id: string } }>("POST", "/restore", { change_id: o.undo.target.change_id, base_rev: o.rev }, { idem: newKey() });
|
||||
if (a.data) app.panel = { kind: "host", resume: a.data.apply.id };
|
||||
return null;
|
||||
} catch (e) {
|
||||
return sentence(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether the pause can be cleared by restoring the last kept version. */
|
||||
export function restorable(): boolean {
|
||||
const o = app.overview;
|
||||
return !!o?.paused && ["apply.needs_attention", "control.files_unwritten"].includes(o.paused_reason ?? "") && !!o.undo?.target;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// runs; quiet retries while edge reloads; the id kept in sessionStorage so a reload resumes it.
|
||||
|
||||
import { get } from "./api";
|
||||
import { refresh } from "./app.svelte";
|
||||
import { app, refresh } from "./app.svelte";
|
||||
import type { ApplyView } from "./types";
|
||||
|
||||
export const FINAL = ["kept", "reverted", "failed", "needs_attention"];
|
||||
@@ -36,6 +36,11 @@ export function follow(id: string, onupdate: (a: ApplyView) => void, every = 100
|
||||
remember(id);
|
||||
const tick = async () => {
|
||||
if (stopped) return;
|
||||
if (app.signedOut) {
|
||||
// No requests while signed out (the overview poll stops too); look again shortly.
|
||||
timer = setTimeout(tick, every);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const a = await get<ApplyView>(`/applies/${encodeURIComponent(id)}`);
|
||||
if (stopped) return;
|
||||
|
||||
@@ -25,6 +25,21 @@ export function when(iso: string | null | undefined, now = Date.now()): string {
|
||||
return `${d.getDate()} ${MONTHS[d.getMonth()]} ${hm}`;
|
||||
}
|
||||
|
||||
/** Inside a sentence: "today 14:02", "yesterday 21:14", "5 Nov 21:14". */
|
||||
export function whenInline(iso: string | null | undefined, now = Date.now()): string {
|
||||
return when(iso, now).replace(/^(Today|Yesterday)/, (s) => s.toLowerCase());
|
||||
}
|
||||
|
||||
/** After "at" / "on": "at 14:03", "yesterday at 21:14", "on 5 Nov at 21:14", "on 5 Nov 2025". */
|
||||
export function atTime(iso: string | null | undefined, now = Date.now()): string {
|
||||
const w = when(iso, now);
|
||||
if (!w) return "";
|
||||
if (w.startsWith("Today ")) return `at ${w.slice(6)}`;
|
||||
if (w.startsWith("Yesterday ")) return `yesterday at ${w.slice(10)}`;
|
||||
const m = /^(\d+ \w+) (\d\d:\d\d)$/.exec(w);
|
||||
return m ? `on ${m[1]} at ${m[2]}` : `on ${w}`;
|
||||
}
|
||||
|
||||
/** "14 November 2026 at 14:20". */
|
||||
export function longDate(iso: string | null | undefined, withTime = true): string {
|
||||
if (!iso) return "";
|
||||
@@ -57,12 +72,13 @@ export function ago(iso: string | null | undefined, now: number): string {
|
||||
return duration((now - Date.parse(iso)) / 1000) + " ago";
|
||||
}
|
||||
|
||||
/** "7 hosts · 5 healthy, 1 degraded, 1 down" (handoff §5.1). */
|
||||
export function countsSentence(c: { hosts: number; healthy: number; degraded: number; down: number; unknown: number }): string {
|
||||
/** "7 hosts · 5 healthy, 1 degraded, 1 down" (handoff §5.1); short (phone, §5.2): "5 healthy, 1 degraded, 1 down". */
|
||||
export function countsSentence(c: { hosts: number; healthy: number; degraded: number; down: number; unknown: number }, short = false): string {
|
||||
const parts = [`${c.healthy} healthy`];
|
||||
if (c.degraded) parts.push(`${c.degraded} degraded`);
|
||||
if (c.down) parts.push(`${c.down} down`);
|
||||
if (c.unknown) parts.push(`${c.unknown} not checked`);
|
||||
if (short) return parts.join(", ");
|
||||
return `${c.hosts} ${c.hosts === 1 ? "host" : "hosts"} · ${parts.join(", ")}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,7 @@ export interface PkiRequest {
|
||||
device_id: string | null;
|
||||
name: string | null;
|
||||
csr_pem: string | null;
|
||||
csr_sha256?: string | null;
|
||||
not_after: string | null;
|
||||
message_code: string;
|
||||
message: string;
|
||||
@@ -136,7 +137,7 @@ export interface EngineView {
|
||||
since: string | null;
|
||||
target: string | null;
|
||||
switchable: boolean;
|
||||
fallback_ready: { built_at: string | null; current: boolean } | null;
|
||||
fallback_ready: { built_at: string | null; current: boolean; compared: number; matched: number; differences: string[] } | null;
|
||||
last_error: Reason | null;
|
||||
notes: Blocked[];
|
||||
}
|
||||
@@ -154,7 +155,7 @@ export interface Overview {
|
||||
engine: EngineView;
|
||||
last_apply: ApplyView | null;
|
||||
undo: UndoView;
|
||||
active_apply: { id: string; state: string; summary: string; seconds_left: number | null; queued: number } | null;
|
||||
active_apply: { id: string; state: string; summary: string; seconds_left: number | null; kind: string; hosts: string[]; watch_ends_at: string | null; queued: number } | null;
|
||||
repo: { name: string; last_push_at: string | null; unpushed: number; push_error_code: string | null } | null;
|
||||
intermediate: IntermediateView | null;
|
||||
site: { forward_auth_configured: boolean; acme_configured: boolean; secrets: string[]; watch_seconds: number; share_links_available: boolean; auth_logout_url?: string | null } | null;
|
||||
@@ -234,6 +235,7 @@ export interface CertsView {
|
||||
root: { offline: boolean; subject: string; not_after: string; sha256: string };
|
||||
devices: DeviceRow[];
|
||||
device_lifetime_days: number;
|
||||
device_valid_until: string | null;
|
||||
server_lifetime_days: number;
|
||||
approval: string;
|
||||
requests: PkiRequest[];
|
||||
|
||||
Reference in New Issue
Block a user