[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,32 +5,36 @@
|
||||
// Handoff §2.8 order: paused / needs attention, lost contact, health unavailable, the Caddy
|
||||
// notice, then (on Hosts) the intermediate banner. First on every screen.
|
||||
import { Banner, Button, Details } from "@ianitor/ui";
|
||||
import { post, sentence } from "../lib/api";
|
||||
import { app, refresh } from "../lib/app.svelte";
|
||||
import { when } from "../lib/format";
|
||||
import type { ApplyView } from "../lib/types";
|
||||
import { app, refresh, restorable as canRestore, restoreLastKept } from "../lib/app.svelte";
|
||||
import { atTime, whenInline } from "../lib/format";
|
||||
|
||||
const o = $derived(app.overview);
|
||||
let restoring = $state(false);
|
||||
let problem = $state<string | null>(null);
|
||||
|
||||
const restorable = $derived(
|
||||
!!o?.paused && ["apply.needs_attention", "control.files_unwritten"].includes(o.paused_reason ?? "") && !!o.undo?.target,
|
||||
);
|
||||
const restorable = $derived(canRestore());
|
||||
|
||||
async function restoreLastKept() {
|
||||
if (!o?.undo?.target) return;
|
||||
async function restore() {
|
||||
restoring = true;
|
||||
try {
|
||||
const a = await post<{ apply: ApplyView }>("/restore", { change_id: o.undo.target.change_id, base_rev: o.rev });
|
||||
app.panel = { kind: "host", resume: a.apply.id };
|
||||
} catch (e) {
|
||||
problem = sentence(e);
|
||||
} finally {
|
||||
restoring = false;
|
||||
}
|
||||
problem = await restoreLastKept();
|
||||
restoring = false;
|
||||
}
|
||||
|
||||
// §7.6: the bold line and line 2 by the pause's underlying code.
|
||||
const pause = $derived.by(() => {
|
||||
const code = o?.paused_reason ?? "";
|
||||
const message = o?.paused?.message ?? "";
|
||||
if (code === "apply.needs_attention")
|
||||
return { bold: "Ianitor could not undo a failed change.", line2: "Visitors are served the last good settings, but the routes repository still has the change. Restore the last kept version to make them match again.", extra: "" };
|
||||
if (code === "control.files_unwritten")
|
||||
return { bold: "The change is live, but Ianitor could not save the proxy settings to disk.", line2: "Changes are paused until Ianitor restarts and saves them. Restoring the last kept version also clears this.", extra: "On the server: sudo systemctl restart ianitor-control" };
|
||||
// control.paused wraps the reason: "Changes are paused: <reason>"; show the reason itself.
|
||||
const own = message.replace(/^Changes are paused: /, "");
|
||||
if (/^(repo|file|site)\./.test(code))
|
||||
return { bold: own, line2: `Fix the file in the ${o?.repo?.name ?? "routes"} repository; Ianitor picks it up by itself.`, extra: "" };
|
||||
return { bold: own, line2: "", extra: "" };
|
||||
});
|
||||
|
||||
async function retry() {
|
||||
await refresh();
|
||||
}
|
||||
@@ -38,11 +42,13 @@
|
||||
|
||||
{#if o?.paused}
|
||||
<Banner tone="down" live="alert">
|
||||
{#snippet title()}<span class="ia-status" data-s="down"><span class="word">{restorable ? "needs attention" : "paused"}</span></span> <strong>{o.paused?.message}</strong>{/snippet}
|
||||
{#if restorable && o.undo?.target}Goes back to "{o.undo.target.summary}" from {when(o.undo.target.kept_at, app.now)}. It is checked like any change.{/if}
|
||||
{#if problem} {problem}{/if}
|
||||
{#snippet title()}<span class="ia-status" data-s="down"><span class="word">{o.paused_reason === "apply.needs_attention" ? "needs attention" : "paused"}</span></span> <strong>{pause.bold}</strong>{/snippet}
|
||||
{#if pause.line2}<span class="line2">{pause.line2}</span>{/if}
|
||||
{#if restorable && o.undo?.target}<p class="ia-hint">Goes back to "{o.undo.target.summary}" from {whenInline(o.undo.target.kept_at, app.now)}. It is checked like any change.</p>{/if}
|
||||
{#if problem}<p role="status">{problem}</p>{/if}
|
||||
{#if pause.extra}<Details detail={pause.extra} />{/if}
|
||||
{#snippet actions()}
|
||||
{#if restorable}<Button variant="primary" onclick={restoreLastKept} pending={restoring}>Restore the last kept version</Button>{/if}
|
||||
{#if restorable}<Button variant="primary" onclick={restore} pending={restoring}>Restore the last kept version</Button>{/if}
|
||||
{/snippet}
|
||||
</Banner>
|
||||
{/if}
|
||||
@@ -50,7 +56,7 @@
|
||||
{#if app.lostContact}
|
||||
<Banner tone="down" live="alert">
|
||||
{#snippet title()}<strong>{typeof navigator !== "undefined" && navigator.onLine === false ? "This device is offline. Ianitor keeps running." : "Ianitor's control service is not answering."}</strong>{/snippet}
|
||||
Traffic keeps flowing; changes wait until it is back.{#if app.lastUpdated} Last updated {when(new Date(app.lastUpdated).toISOString(), app.now)}.{/if}
|
||||
Traffic keeps flowing; changes wait until it is back.{#if app.lastUpdated} Last updated {atTime(new Date(app.lastUpdated).toISOString(), app.now)}.{/if}
|
||||
{#snippet actions()}<Button onclick={retry}>Try again now</Button>{/snippet}
|
||||
</Banner>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user