feat(maestro): web UI persistent sidebar + content split w/ background connection pool (NAP-338)
ci / rust (push) Successful in 5m24s
ci / rust (push) Successful in 5m24s
Replace the full-screen route-swap SPA with a persistent two-pane layout: - Global top bar (brand + Spawn + theme) above a sidebar (search + status + session tree, highlights the active session) and a content pane (welcome or the attached terminal). Selecting a row swaps only the content pane; the sidebar and its store subscription persist. - New `connections.ts` ConnectionPool: attach connections (terminal + WS) are decoupled from the UI — navigating away parks a session (keeps it streaming) rather than tearing it down, so switching back is instant with scrollback intact. LRU-bounded (MAX_LIVE=6); explicit `⏻` disconnect distinct from nav. - `attach.ts` → mountable `createAttachConnection`; `catalog.ts` exposes `renderTopbar` + `renderSidebar`; `main.ts` is the shell + hash router. - Responsive: desktop side-by-side; mobile single-pane (list ↔ terminal). Single session viewed at a time (split panes deferred). Typecheck + production build green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+58
-35
@@ -1,5 +1,5 @@
|
||||
import { renderAttach } from "./attach.js";
|
||||
import { renderCatalog } from "./catalog.js";
|
||||
import { renderSidebar, renderTopbar } from "./catalog.js";
|
||||
import { ConnectionPool } from "./connections.js";
|
||||
import { CatalogStore } from "./events.js";
|
||||
import { initTheme } from "./theme.js";
|
||||
import "./styles.css";
|
||||
@@ -20,6 +20,48 @@ if (import.meta.env.DEV && location.search.includes("mock")) {
|
||||
void import("./mock.js").then((m) => m.seedMock(store));
|
||||
}
|
||||
|
||||
// ---- persistent shell: sidebar (list) + content (welcome | attach) ----
|
||||
|
||||
const shellEl = document.createElement("div");
|
||||
shellEl.className = "app-shell";
|
||||
shellEl.dataset.route = "catalog";
|
||||
|
||||
const sidebar = renderSidebar(store);
|
||||
const content = document.createElement("section");
|
||||
content.className = "content";
|
||||
|
||||
shellEl.append(sidebar.el, content);
|
||||
root.replaceChildren(renderTopbar(store), shellEl);
|
||||
|
||||
// The pool owns attach connections independently of the route: navigating away
|
||||
// parks a session (keeps it streaming); navigating back re-mounts it instantly.
|
||||
const pool = new ConnectionPool({
|
||||
onActiveChange: (id) => sidebar.setActive(id),
|
||||
});
|
||||
|
||||
function renderWelcome(): HTMLElement {
|
||||
const el = document.createElement("div");
|
||||
el.className = "empty content-welcome";
|
||||
el.innerHTML = `
|
||||
<div class="empty-glyph" aria-hidden="true">⌘</div>
|
||||
<div class="empty-title">No session open</div>
|
||||
<p class="empty-hint">
|
||||
Pick a session from the list, or press <kbd>+ Spawn</kbd> to start one.
|
||||
Open sessions keep streaming in the background — switching back is instant.
|
||||
</p>`;
|
||||
return el;
|
||||
}
|
||||
|
||||
function renderNotFound(raw: string): HTMLElement {
|
||||
const el = document.createElement("div");
|
||||
el.className = "not-found";
|
||||
el.innerHTML = `
|
||||
<h1>Unknown route</h1>
|
||||
<p><code>#${raw.replace(/[<&]/g, "")}</code> doesn't match anything.</p>
|
||||
<a class="btn btn-primary" href="#/">Back to catalog</a>`;
|
||||
return el;
|
||||
}
|
||||
|
||||
type Route =
|
||||
| { kind: "catalog" }
|
||||
| { kind: "attach"; sessionId: string }
|
||||
@@ -33,44 +75,25 @@ function parseRoute(): Route {
|
||||
return { kind: "not-found", raw: hash };
|
||||
}
|
||||
|
||||
let currentTeardown: (() => void) | (() => Promise<void>) | null = null;
|
||||
|
||||
async function dispatch() {
|
||||
if (currentTeardown) {
|
||||
try {
|
||||
await Promise.resolve(currentTeardown());
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
currentTeardown = null;
|
||||
}
|
||||
function dispatch(): void {
|
||||
const route = parseRoute();
|
||||
switch (route.kind) {
|
||||
case "catalog": {
|
||||
const teardown = renderCatalog(root!, store);
|
||||
currentTeardown = teardown;
|
||||
case "attach":
|
||||
shellEl.dataset.route = "attach";
|
||||
pool.activate(route.sessionId, content);
|
||||
return;
|
||||
}
|
||||
case "attach": {
|
||||
const handle = await renderAttach(root!, route.sessionId);
|
||||
currentTeardown = () => handle.dispose();
|
||||
case "not-found":
|
||||
shellEl.dataset.route = "notfound";
|
||||
pool.parkActive();
|
||||
content.replaceChildren(renderNotFound(route.raw));
|
||||
return;
|
||||
}
|
||||
case "not-found": {
|
||||
root!.innerHTML = `
|
||||
<div class="not-found">
|
||||
<h1>Unknown route</h1>
|
||||
<p><code>#${route.raw}</code> doesn't match anything.</p>
|
||||
<a class="btn btn-primary" href="#/">Back to catalog</a>
|
||||
</div>
|
||||
`;
|
||||
case "catalog":
|
||||
shellEl.dataset.route = "catalog";
|
||||
pool.parkActive();
|
||||
content.replaceChildren(renderWelcome());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("hashchange", () => {
|
||||
void dispatch();
|
||||
});
|
||||
|
||||
void dispatch();
|
||||
window.addEventListener("hashchange", dispatch);
|
||||
dispatch();
|
||||
|
||||
Reference in New Issue
Block a user