Add repos from the page, answer actions in place, Expo-style redesign
Add repository: - New remote verb `add-repo KEY OWNER/NAME`. Off unless config.toml has [repo_add] (base_url + owners). Only listed owners; the dev box builds the URL itself, checks it with `git ls-remote` (bot access), then appends to [repos] under the lock. No URL crosses the SSH link. - `repos` also reports where adding is allowed, so the page shows the form only when it's on and rejects other hosts before calling SSH. - set_toml_string inserts after the section's last key, not after trailing blank lines / the next section's comments. Responsiveness: - web/static/app.js (progressive enhancement; every form still works without JS): forms go via fetch and get a JSON answer instead of POST-redirect-GET; buttons/cards show the change immediately; the list refreshes itself (15 s, 3 s while something is starting). - `repos` is cached for 5 min (refreshed on add-repo), so a page view is one SSH call instead of two. - `list` reads all unit states with one `systemctl show` instead of one per session: 676 -> 374 ms on the dev box with 21 sessions. - Static assets are content-hashed and cached immutably. Design: slate greys, hairline borders, black primary action, tinted status badges, monospace repo/branch, two columns on desktop, stacked on phones, light and dark. Docs: README security model, AGENTS.md (JS convention, add-repo invariant), config.example.toml. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MCUMXh8zZConC75Mptbeou
This commit is contained in:
parent
39997de1e8
commit
1b3172bd50
10 changed files with 1084 additions and 92 deletions
254
web/static/app.css
Normal file
254
web/static/app.css
Normal file
|
|
@ -0,0 +1,254 @@
|
|||
/* sessions-web. A quiet, monochrome UI in the style of Expo's design language:
|
||||
slate greys, hairline borders, a black primary action, soft tinted status badges. */
|
||||
|
||||
:root {
|
||||
--bg: #ffffff;
|
||||
--bg-subtle: #f8f9fa;
|
||||
--bg-hover: #f1f3f5;
|
||||
--line: #e6e8eb;
|
||||
--line-strong: #d7dbdf;
|
||||
--fg: #11181c;
|
||||
--fg-2: #687076;
|
||||
--fg-3: #889096;
|
||||
--primary: #11181c;
|
||||
--on-primary: #ffffff;
|
||||
--ok: #18794e; --ok-bg: #e9f9ee;
|
||||
--warn: #ad5700; --warn-bg: #fff4d5;
|
||||
--bad: #cd2b31; --bad-bg: #ffefef;
|
||||
--idle: #687076; --idle-bg: #f1f3f5;
|
||||
--focus: #0091ff;
|
||||
--shadow: 0 1px 2px rgba(17, 24, 28, .04), 0 1px 1px rgba(17, 24, 28, .03);
|
||||
--shadow-lg: 0 10px 30px -10px rgba(17, 24, 28, .25);
|
||||
--radius: 12px;
|
||||
--radius-sm: 8px;
|
||||
--font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
|
||||
--mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg: #151718;
|
||||
--bg-subtle: #1a1d1e;
|
||||
--bg-hover: #202425;
|
||||
--line: #2b2f31;
|
||||
--line-strong: #393e40;
|
||||
--fg: #ecedee;
|
||||
--fg-2: #9ba1a6;
|
||||
--fg-3: #787f85;
|
||||
--primary: #ecedee;
|
||||
--on-primary: #151718;
|
||||
--ok: #4cc38a; --ok-bg: #0f291e;
|
||||
--warn: #f1a10d; --warn-bg: #2c2100;
|
||||
--bad: #ff6369; --bad-bg: #3c181a;
|
||||
--idle: #9ba1a6; --idle-bg: #202425;
|
||||
--focus: #52a9ff;
|
||||
--shadow: 0 1px 2px rgba(0, 0, 0, .3);
|
||||
--shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, .7);
|
||||
color-scheme: dark;
|
||||
}
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
[hidden] { display: none !important; }
|
||||
html { -webkit-text-size-adjust: 100%; }
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--fg);
|
||||
font: 15px/1.5 var(--font);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
font-feature-settings: "cv11", "ss01";
|
||||
}
|
||||
a { color: inherit; }
|
||||
h1, h2, h3 { margin: 0; letter-spacing: -0.015em; }
|
||||
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
|
||||
|
||||
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
|
||||
|
||||
/* ---------------------------------------------------------------- top bar */
|
||||
|
||||
.top {
|
||||
position: sticky; top: 0; z-index: 10;
|
||||
background: color-mix(in srgb, var(--bg) 85%, transparent);
|
||||
-webkit-backdrop-filter: saturate(180%) blur(12px);
|
||||
backdrop-filter: saturate(180%) blur(12px);
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.top-inner { height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
||||
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; text-decoration: none; letter-spacing: -0.01em; }
|
||||
.mark { width: 24px; height: 24px; flex: none; }
|
||||
.mark rect { fill: var(--primary); }
|
||||
.mark path { stroke: var(--on-primary); }
|
||||
.user {
|
||||
font-size: 13px; color: var(--fg-2);
|
||||
padding: 4px 10px; border: 1px solid var(--line); border-radius: 99px;
|
||||
max-width: 50vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- layout */
|
||||
|
||||
.grid { display: grid; gap: 32px; padding-top: 32px; padding-bottom: 64px; }
|
||||
@media (min-width: 900px) {
|
||||
.grid { grid-template-columns: minmax(0, 1fr) 340px; gap: 48px; padding-top: 48px; }
|
||||
.col-side { position: sticky; top: 88px; align-self: start; }
|
||||
}
|
||||
|
||||
.intro h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.2; }
|
||||
.intro p { margin: 6px 0 0; color: var(--fg-2); }
|
||||
|
||||
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 32px 0 12px; }
|
||||
.section-head h2 { font-size: 17px; font-weight: 600; }
|
||||
.counter { font-size: 13px; color: var(--fg-2); font-variant-numeric: tabular-nums; }
|
||||
|
||||
.list { display: grid; gap: 12px; }
|
||||
|
||||
/* ---------------------------------------------------------------- cards */
|
||||
|
||||
.card {
|
||||
background: var(--bg);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
padding: 16px;
|
||||
box-shadow: var(--shadow);
|
||||
transition: border-color .15s, opacity .2s, transform .2s;
|
||||
}
|
||||
.card:hover { border-color: var(--line-strong); }
|
||||
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
|
||||
.title { font-size: 16px; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
|
||||
.meta { margin-top: 4px; font-size: 13px; color: var(--fg-2); display: flex; flex-wrap: wrap; gap: 0 6px; }
|
||||
.mono { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
|
||||
.dim { color: var(--fg-3); }
|
||||
.warn {
|
||||
margin-top: 12px; padding: 8px 12px; border-radius: var(--radius-sm);
|
||||
background: var(--warn-bg); color: var(--warn); font-size: 13px;
|
||||
}
|
||||
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
|
||||
.card.archived { background: var(--bg-subtle); box-shadow: none; }
|
||||
.card.archived .title { color: var(--fg-2); }
|
||||
.card.pending { opacity: .7; }
|
||||
.card.leaving { opacity: 0; transform: scale(.98); }
|
||||
.card.ghost { border-style: dashed; box-shadow: none; }
|
||||
.card.ghost .title { color: var(--fg-2); }
|
||||
|
||||
.empty {
|
||||
display: grid; gap: 4px; text-align: center; padding: 40px 16px;
|
||||
border: 1px dashed var(--line-strong); border-radius: var(--radius); color: var(--fg-2); font-size: 14px;
|
||||
}
|
||||
.empty strong { color: var(--fg); font-weight: 600; }
|
||||
|
||||
/* ---------------------------------------------------------------- badges */
|
||||
|
||||
.badge {
|
||||
flex: none; display: inline-flex; align-items: center; gap: 6px;
|
||||
font-size: 12px; font-weight: 500; line-height: 1;
|
||||
padding: 5px 9px; border-radius: 99px;
|
||||
background: var(--idle-bg); color: var(--idle);
|
||||
}
|
||||
.badge i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
|
||||
.badge.active { background: var(--ok-bg); color: var(--ok); }
|
||||
.badge.activating, .badge.deactivating, .badge.reloading { background: var(--warn-bg); color: var(--warn); }
|
||||
.badge.activating i, .badge.deactivating i, .badge.reloading i { animation: pulse 1s ease-in-out infinite; }
|
||||
.badge.failed, .badge.unknown { background: var(--bad-bg); color: var(--bad); }
|
||||
|
||||
/* ---------------------------------------------------------------- buttons */
|
||||
|
||||
.btn {
|
||||
font: inherit; font-size: 14px; font-weight: 500; line-height: 20px;
|
||||
display: inline-flex; align-items: center; justify-content: center; gap: 8px;
|
||||
min-height: 36px; padding: 7px 14px;
|
||||
border-radius: var(--radius-sm); border: 1px solid transparent;
|
||||
background: var(--primary); color: var(--on-primary);
|
||||
text-decoration: none; cursor: pointer; white-space: nowrap;
|
||||
transition: background-color .15s, border-color .15s, opacity .15s;
|
||||
}
|
||||
.btn:hover { opacity: .88; }
|
||||
.btn.secondary { background: var(--bg); color: var(--fg); border-color: var(--line-strong); }
|
||||
.btn.secondary:hover { background: var(--bg-hover); opacity: 1; }
|
||||
.btn.ghost { background: transparent; color: var(--fg-2); }
|
||||
.btn.ghost:hover { background: var(--bg-hover); color: var(--fg); opacity: 1; }
|
||||
.btn.wide { flex: 1; }
|
||||
.btn:disabled { cursor: progress; opacity: .6; }
|
||||
.btn.loading::before {
|
||||
content: ""; width: 14px; height: 14px; border-radius: 50%;
|
||||
border: 2px solid currentColor; border-right-color: transparent;
|
||||
animation: spin .7s linear infinite;
|
||||
}
|
||||
form.inline { display: contents; }
|
||||
|
||||
/* ---------------------------------------------------------------- panels and forms */
|
||||
|
||||
.col-side { display: grid; gap: 16px; align-content: start; }
|
||||
.panel {
|
||||
background: var(--bg-subtle);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
padding: 20px;
|
||||
}
|
||||
.panel h2 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
|
||||
details.panel > summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; }
|
||||
details.panel > summary::-webkit-details-marker { display: none; }
|
||||
details.panel > summary h2 { margin: 0; }
|
||||
details.panel > summary::after { content: "+"; font-size: 18px; color: var(--fg-2); line-height: 1; }
|
||||
details.panel[open] > summary::after { content: "–"; }
|
||||
details.panel[open] > summary { margin-bottom: 4px; }
|
||||
|
||||
label { display: block; font-size: 13px; font-weight: 500; color: var(--fg); margin: 14px 0 6px; }
|
||||
.opt { font-weight: 400; color: var(--fg-3); }
|
||||
input, select {
|
||||
font: inherit; font-size: 15px; width: 100%;
|
||||
min-height: 40px; padding: 8px 12px;
|
||||
border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
|
||||
background: var(--bg); color: var(--fg);
|
||||
transition: border-color .15s, box-shadow .15s;
|
||||
}
|
||||
input::placeholder { color: var(--fg-3); }
|
||||
input:focus, select:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
|
||||
select {
|
||||
appearance: none; -webkit-appearance: none; padding-right: 36px;
|
||||
background-image: linear-gradient(45deg, transparent 50%, var(--fg-2) 50%), linear-gradient(135deg, var(--fg-2) 50%, transparent 50%);
|
||||
background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
|
||||
background-size: 5px 5px; background-repeat: no-repeat;
|
||||
}
|
||||
.panel .actions { margin-top: 20px; }
|
||||
.hint { margin: 12px 0 0; font-size: 12.5px; color: var(--fg-2); }
|
||||
.note { margin: 0; font-size: 12.5px; color: var(--fg-3); padding: 0 4px; }
|
||||
|
||||
/* ---------------------------------------------------------------- archive */
|
||||
|
||||
details.archive { margin-top: 28px; }
|
||||
details.archive > summary {
|
||||
cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 8px;
|
||||
font-size: 14px; font-weight: 500; color: var(--fg-2); margin-bottom: 12px;
|
||||
}
|
||||
details.archive > summary::-webkit-details-marker { display: none; }
|
||||
details.archive > summary::before { content: "›"; display: inline-block; transition: transform .15s; font-size: 16px; }
|
||||
details.archive[open] > summary::before { transform: rotate(90deg); }
|
||||
.count { font-size: 12px; padding: 1px 7px; border-radius: 99px; background: var(--bg-hover); }
|
||||
|
||||
/* ---------------------------------------------------------------- messages */
|
||||
|
||||
.callout { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14px; margin-top: 24px; }
|
||||
.callout.err { background: var(--bad-bg); color: var(--bad); }
|
||||
|
||||
#toasts {
|
||||
position: fixed; z-index: 20; left: 16px; right: 16px; bottom: 16px;
|
||||
display: grid; gap: 8px; justify-items: center; pointer-events: none;
|
||||
}
|
||||
@media (min-width: 640px) { #toasts { left: auto; right: 24px; bottom: 24px; justify-items: end; } }
|
||||
.toast {
|
||||
pointer-events: auto; max-width: 420px;
|
||||
padding: 12px 16px; border-radius: var(--radius-sm);
|
||||
background: var(--primary); color: var(--on-primary);
|
||||
font-size: 14px; box-shadow: var(--shadow-lg);
|
||||
animation: rise .2s ease-out; transition: opacity .3s, transform .3s;
|
||||
}
|
||||
.toast.err { background: var(--bad); color: #fff; }
|
||||
.toast.out { opacity: 0; transform: translateY(6px); }
|
||||
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
@keyframes pulse { 50% { opacity: .35; } }
|
||||
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
|
||||
}
|
||||
224
web/static/app.js
Normal file
224
web/static/app.js
Normal file
|
|
@ -0,0 +1,224 @@
|
|||
// sessions-web: progressive enhancement. The page works without this file;
|
||||
// with it, buttons answer in place (no reload) and the list keeps itself fresh.
|
||||
//
|
||||
// - Every POST form is sent with fetch() and `Accept: application/json`; the
|
||||
// server then answers {ok, message|error} instead of redirecting.
|
||||
// - The button and card show the change at once; the real state follows from
|
||||
// a background refresh, which re-fetches "/" and swaps #live and the
|
||||
// Repository options. Nothing from the server is inserted as HTML except
|
||||
// that same-origin page.
|
||||
// - The list refreshes every 15 s (every 3 s while something is starting or
|
||||
// stopping) and only while the tab is visible.
|
||||
(() => {
|
||||
"use strict";
|
||||
|
||||
const $ = (sel, root = document) => root.querySelector(sel);
|
||||
const BUSY_LABEL = {
|
||||
start: "Starting", stop: "Stopping", archive: "Archiving", unarchive: "Restoring",
|
||||
create: "Creating", "add-repo": "Checking",
|
||||
};
|
||||
const SLOW = 15000, FAST = 3000;
|
||||
let inFlight = 0, timer = 0;
|
||||
|
||||
// The no-JS flow lands on /?ok=… — drop it so a reload doesn't repeat it.
|
||||
if (location.search) history.replaceState(null, "", location.pathname);
|
||||
|
||||
// ------------------------------------------------------------ toasts
|
||||
|
||||
function dismiss(el, after) {
|
||||
setTimeout(() => { el.classList.add("out"); setTimeout(() => el.remove(), 300); }, after);
|
||||
}
|
||||
|
||||
function toast(kind, text) {
|
||||
const el = document.createElement("div");
|
||||
el.className = "toast " + kind;
|
||||
el.setAttribute("role", kind === "err" ? "alert" : "status");
|
||||
el.textContent = text;
|
||||
$("#toasts").appendChild(el);
|
||||
dismiss(el, kind === "err" ? 9000 : 4500);
|
||||
}
|
||||
|
||||
document.querySelectorAll("#toasts .toast").forEach((el) => dismiss(el, 6000));
|
||||
|
||||
// ------------------------------------------------------------ relative times
|
||||
|
||||
function ago(iso) {
|
||||
const s = (Date.now() - Date.parse(iso)) / 1000;
|
||||
if (!isFinite(s)) return null;
|
||||
if (s < 60) return "just now";
|
||||
const units = [["d", 86400], ["h", 3600], ["min", 60]];
|
||||
for (const [u, n] of units) if (s >= n) return `${Math.floor(s / n)} ${u} ago`;
|
||||
return null;
|
||||
}
|
||||
|
||||
function humanizeTimes(root) {
|
||||
root.querySelectorAll("time[datetime]").forEach((t) => {
|
||||
const rel = ago(t.dateTime);
|
||||
if (rel) { t.title = t.textContent; t.textContent = rel; }
|
||||
});
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ refresh
|
||||
|
||||
function needsFastPoll() {
|
||||
return !!$('#live [data-state="activating"], #live [data-state="deactivating"], #live .card.ghost') ||
|
||||
!!$('#live [data-state="active"]:not([data-linked])'); // waiting for the Remote Control link
|
||||
}
|
||||
|
||||
function schedule() {
|
||||
clearTimeout(timer);
|
||||
if (!document.hidden) timer = setTimeout(refresh, needsFastPoll() ? FAST : SLOW);
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
if (inFlight) return schedule(); // an action's own refresh follows it
|
||||
let res;
|
||||
try {
|
||||
res = await fetch("/", { headers: { Accept: "text/html" }, cache: "no-store", credentials: "same-origin" });
|
||||
} catch {
|
||||
return schedule(); // offline, or the login expired (redirect to another origin)
|
||||
}
|
||||
if (!res.ok || inFlight) return schedule();
|
||||
const doc = new DOMParser().parseFromString(await res.text(), "text/html");
|
||||
const live = $("#live", doc);
|
||||
if (!live) return schedule();
|
||||
swapLive(live);
|
||||
swapRepos($("#repo", doc));
|
||||
schedule();
|
||||
}
|
||||
|
||||
function swapLive(fresh) {
|
||||
const current = $("#live");
|
||||
const wasOpen = $("details.archive", current)?.open;
|
||||
const archive = $("details.archive", fresh);
|
||||
if (archive && wasOpen) archive.open = true;
|
||||
humanizeTimes(fresh);
|
||||
current.replaceWith(document.adoptNode(fresh));
|
||||
}
|
||||
|
||||
function swapRepos(freshSelect) {
|
||||
const select = $("#repo");
|
||||
if (!select || !freshSelect) return;
|
||||
setRepoOptions([...freshSelect.options].map((o) => o.value));
|
||||
}
|
||||
|
||||
function setRepoOptions(names, pick) {
|
||||
const select = $("#repo");
|
||||
const have = [...select.options].map((o) => o.value);
|
||||
if (have.join("\n") === names.join("\n") && !pick) return;
|
||||
const keep = pick || select.value;
|
||||
select.replaceChildren(...names.map((n) => new Option(n, n)));
|
||||
if (names.includes(keep)) select.value = keep;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ actions
|
||||
|
||||
// Show the action as happening right away. Returns an undo for failures.
|
||||
function showPending(verb, form, button) {
|
||||
const undo = [];
|
||||
const label = button.textContent;
|
||||
button.disabled = true;
|
||||
button.classList.add("loading");
|
||||
button.textContent = BUSY_LABEL[verb] || "Working";
|
||||
undo.push(() => { button.disabled = false; button.classList.remove("loading"); button.textContent = label; });
|
||||
|
||||
const card = form.closest(".card");
|
||||
if (card) {
|
||||
card.classList.add("pending");
|
||||
card.querySelectorAll("button").forEach((b) => { b.disabled = true; });
|
||||
const badge = $(".badge", card);
|
||||
const old = badge.cloneNode(true);
|
||||
const state = { start: "activating", stop: "deactivating", archive: "deactivating" }[verb];
|
||||
if (state) {
|
||||
badge.className = "badge " + state;
|
||||
badge.lastChild.textContent = BUSY_LABEL[verb];
|
||||
card.dataset.state = state;
|
||||
}
|
||||
if (verb === "archive" || verb === "unarchive") card.classList.add("leaving");
|
||||
undo.push(() => { card.classList.remove("pending", "leaving"); badge.replaceWith(old); });
|
||||
}
|
||||
|
||||
if (verb === "create") {
|
||||
const ghost = document.createElement("article");
|
||||
ghost.className = "card ghost";
|
||||
ghost.innerHTML = '<div class="card-top"><h3 class="title"></h3>' +
|
||||
'<span class="badge activating"><i></i>Cloning</span></div><div class="meta"><span class="mono"></span></div>';
|
||||
$(".title", ghost).textContent = new FormData(form).get("name");
|
||||
$(".mono", ghost).textContent = new FormData(form).get("repo");
|
||||
const list = $("#live .list");
|
||||
const empty = $(".empty", list);
|
||||
if (empty) empty.hidden = true;
|
||||
list.prepend(ghost);
|
||||
undo.push(() => { ghost.remove(); if (empty) empty.hidden = false; });
|
||||
}
|
||||
return () => undo.forEach((f) => f());
|
||||
}
|
||||
|
||||
async function submit(form, button) {
|
||||
const verb = new URL(form.action).pathname.slice(1);
|
||||
const body = new URLSearchParams(new FormData(form));
|
||||
const undo = showPending(verb, form, button);
|
||||
inFlight++;
|
||||
clearTimeout(timer);
|
||||
let data;
|
||||
try {
|
||||
const res = await fetch(form.action, {
|
||||
method: "POST", body, credentials: "same-origin", headers: { Accept: "application/json" },
|
||||
});
|
||||
data = res.headers.get("Content-Type")?.startsWith("application/json")
|
||||
? await res.json()
|
||||
: { ok: false, error: `${res.status} ${(await res.text()).trim().slice(0, 200)}` };
|
||||
} catch {
|
||||
data = { ok: false, error: "Couldn't reach the server. Check your connection and try again." };
|
||||
}
|
||||
inFlight--;
|
||||
|
||||
if (data.ok) {
|
||||
toast("ok", data.message);
|
||||
if (!form.closest(".card")) undo(); // side panel forms stay; cards are replaced by the refresh
|
||||
if (verb === "create") {
|
||||
const repo = form.elements.repo.value;
|
||||
form.reset();
|
||||
form.elements.repo.value = repo;
|
||||
}
|
||||
if (verb === "add-repo") {
|
||||
const added = new FormData(form).get("key") || null;
|
||||
form.reset();
|
||||
if (data.repos) setRepoOptions(data.repos, data.repos.find((r) => r === added) || newest(data.repos));
|
||||
$("#name")?.focus();
|
||||
}
|
||||
} else {
|
||||
undo();
|
||||
toast("err", data.error || "Something went wrong");
|
||||
}
|
||||
refresh();
|
||||
}
|
||||
|
||||
// The key add-repo just added: the one that wasn't in the list before.
|
||||
function newest(names) {
|
||||
const before = new Set([...$("#repo").options].map((o) => o.value));
|
||||
return names.find((n) => !before.has(n));
|
||||
}
|
||||
|
||||
document.addEventListener("submit", (ev) => {
|
||||
const form = ev.target;
|
||||
if (!(form instanceof HTMLFormElement) || form.method.toLowerCase() !== "post") return;
|
||||
ev.preventDefault();
|
||||
const button = ev.submitter || $("button", form);
|
||||
if (button?.disabled) return;
|
||||
submit(form, button);
|
||||
});
|
||||
|
||||
document.addEventListener("click", (ev) => {
|
||||
const link = ev.target.closest("[data-refresh]");
|
||||
if (!link) return;
|
||||
ev.preventDefault();
|
||||
link.classList.add("loading");
|
||||
refresh().finally(() => link.classList.remove("loading"));
|
||||
});
|
||||
|
||||
document.addEventListener("visibilitychange", () => (document.hidden ? clearTimeout(timer) : refresh()));
|
||||
|
||||
humanizeTimes(document);
|
||||
schedule();
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue