From e29878bb3dc5cb4c108177e417d79464f06e198c Mon Sep 17 00:00:00 2001 From: iz0eyj Date: Tue, 24 Nov 2026 20:57:59 +0100 Subject: [PATCH] Add drag-resizable sidebar/chat separator to the web GUI Desktop-only (>=900px) pointer-drag splitter between the session list and the chat; width clamped (200px..min(480, 50% viewport)) and persisted in localStorage; keyboard arrows + ARIA separator role; hover/focus highlight. README updated. Web assets only; suite unchanged (94 green + 2 ignored), clippy/fmt clean. --- README.md | 5 +++-- web/assets/app.css | 15 +++++++++++++++ web/assets/app.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++ web/index.html | 1 + 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a034517..48ab71c 100644 --- a/README.md +++ b/README.md @@ -92,8 +92,9 @@ under `/assets/...`, embedded via `rust-embed` — no Node, no build step, works offline, same-origin so no CORS). It is a thin client over a **session-aware API**: - `GET /` — the chat shell (responsive: an off-canvas session drawer on phones, a - persistent sidebar on wide screens; streaming answers with a collapsible - "thinking" panel; touch-friendly targets and safe-area insets). + persistent sidebar on wide screens with a **drag-resizable separator** between the + session list and the chat — width clamped and persisted; streaming answers with a + collapsible "thinking" panel; touch-friendly targets and safe-area insets). - `POST /api/sessions`, `GET /api/sessions`, `GET/PATCH/DELETE /api/sessions/{id}`, `GET /api/sessions/{id}/messages` — session CRUD and history. - `POST /api/sessions/{id}/chat` — append a turn; the server loads the stored diff --git a/web/assets/app.css b/web/assets/app.css index 2a45138..74a332e 100644 --- a/web/assets/app.css +++ b/web/assets/app.css @@ -74,6 +74,9 @@ html, body { #scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 20; } +/* Resizable sidebar/chat separator: desktop only (mobile uses a drawer). */ +#splitter { display: none; } +body.resizing { cursor: col-resize; user-select: none; } .drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px; @@ -171,4 +174,16 @@ details.thinking .reasoning { #scrim { display: none !important; } #menu { display: none; } .msg.user .bubble { max-width: 70%; } + #splitter { + display: block; flex: 0 0 6px; width: 6px; cursor: col-resize; + position: relative; background: transparent; touch-action: none; + } + #splitter::after { + content: ""; position: absolute; top: 0; bottom: 0; left: 2px; width: 2px; + background: var(--border); transition: background 0.12s ease; + } + #splitter:hover::after, #splitter:focus-visible::after, body.resizing #splitter::after { + background: var(--accent); + } + #splitter:focus-visible { outline: none; } } \ No newline at end of file diff --git a/web/assets/app.js b/web/assets/app.js index edc94ae..2a32e57 100644 --- a/web/assets/app.js +++ b/web/assets/app.js @@ -236,7 +236,55 @@ function autoGrow(t) { t.style.height = Math.min(t.scrollHeight, window.innerHeight * 0.4) + "px"; } +// ---- Resizable sidebar/chat separator (desktop only) ---------------------- +function initSplitter() { + const splitter = $("#splitter"); + const root = document.documentElement; + const width = () => + parseInt(getComputedStyle(root).getPropertyValue("--sidebar-w")) || 280; + const apply = (w) => { + const max = Math.min(480, Math.floor(window.innerWidth * 0.5)); + w = Math.max(200, Math.min(max, w)); + root.style.setProperty("--sidebar-w", w + "px"); + splitter.setAttribute("aria-valuenow", String(w)); + return w; + }; + const save = () => { + try { localStorage.setItem("sidebarW", String(width())); } catch { /* private mode */ } + }; + + let dragging = false, startX = 0, startW = 0; + splitter.addEventListener("pointerdown", (e) => { + dragging = true; startX = e.clientX; startW = width(); + splitter.setPointerCapture(e.pointerId); + document.body.classList.add("resizing"); + e.preventDefault(); + }); + splitter.addEventListener("pointermove", (e) => { + if (dragging) apply(startW + (e.clientX - startX)); + }); + const end = () => { + if (!dragging) return; + dragging = false; + document.body.classList.remove("resizing"); + save(); + }; + splitter.addEventListener("pointerup", end); + splitter.addEventListener("pointercancel", end); + splitter.addEventListener("keydown", (e) => { + if (e.key === "ArrowLeft") apply(width() - 16); + else if (e.key === "ArrowRight") apply(width() + 16); + else return; + e.preventDefault(); save(); + }); + try { + const w = localStorage.getItem("sidebarW"); + if (w) apply(parseInt(w)); + } catch { /* private mode */ } +} + function wire() { + initSplitter(); $("#menu").addEventListener("click", openDrawer); $("#scrim").addEventListener("click", closeDrawer); $("#new-session").addEventListener("click", newSession); diff --git a/web/index.html b/web/index.html index c7cd55f..9ae03b2 100644 --- a/web/index.html +++ b/web/index.html @@ -20,6 +20,7 @@ +