From 35b9808d9746b6eb2d880b5a0b7175f98f7fc0fe Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Sun, 22 Nov 2026 15:36:07 +0100 Subject: [PATCH] Close a phone panel with the swipe back off its edge An open panel now answers the swipe that undoes the one which opened it: a left drag closes the rail's drawer, a right drag the bot panel, through a panel-local listener sharing swipe-gesture.ts with the page swipes. SidePanel carries the bot panel's phone width (420px, at most 92vw) for both, and field detection moves to touch-in-field.ts so both hooks ignore a touch in a field. --- AGENTS.md | 2 +- .../general/side-panel.render.test.tsx | 11 ++ src/components/general/side-panel.tsx | 20 ++- src/hooks/use-horizontal-swipe.ts | 9 +- src/hooks/use-swipe-to-close.ts | 120 ++++++++++++++++++ .../bots/[bot_id]/(partials)/bot-panel.tsx | 1 - src/utils/side-panel-close-swipe.test.ts | 17 +++ src/utils/side-panel-close-swipe.ts | 15 +++ src/utils/touch-in-field.ts | 20 +++ 9 files changed, 206 insertions(+), 9 deletions(-) create mode 100644 src/hooks/use-swipe-to-close.ts create mode 100644 src/utils/side-panel-close-swipe.test.ts create mode 100644 src/utils/side-panel-close-swipe.ts create mode 100644 src/utils/touch-in-field.ts diff --git a/AGENTS.md b/AGENTS.md index 1b7ca9b4..8479454c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -192,7 +192,7 @@ Set in Settings > Environment (super admin), not `.env`. `envs` (private; encryp - Notification `badge` is `icons/badge-96.png` (white silhouette; Android masks by alpha, so never the opaque app icon). Brave on Android has no WebAPK, so its notifications always carry Brave's name and icon. - `public/sw.js` is served `no-store`; navigations network-only (authenticated HTML never cached); `/api/`, `/ws`, `/media/`, `/computers/`, `/build-info.json` never intercepted. A new worker takes over by itself (`skipWaiting` on install; nothing in it is per-version) and never reloads a page; there is no update prompt. In development the worker and caches are actively removed (`clear-development-service-worker.ts`, stub `/sw.js`). - **Precache (production):** a navigation without the current build cookie gets `loading.html`, which downloads all of `.bunext/public` into `cobble-assets-`, verifies, sets the cookie and reloads (falls back to network on stall). React knows nothing of this. -- Phone shell: rail is a slide-over below `md` (the shared `src/components/general/side-panel.tsx`, always mounted so it slides both ways; the rail passes `inertWhenClosed={false}` since it is the page's own rail from `md` up); rail internals use the `@rail:` container variant, not viewport `lg:`. Two swipes anywhere on a phone page move between panes: to the right opens the rail's drawer, to the left the conversation's bot panel (`cobble:open-bot-panel`, `src/utils/bot-panel-open-event.ts`, answered only by a conversation's header, so a page without one slides nothing). They are flicks, read by `src/hooks/use-horizontal-swipe.ts` (a field, a `data-no-swipe` panel, a box that scrolls sideways, a text selection, a finger down longer than `AppData.MobileSwipeMaxMs`, an open twui modal, a screen from `md` up and the open drawer all own the touch), with the thresholds and the one-decision state machine in `src/utils/swipe-gesture.ts` (`AppData.MobileSwipeMinPx`, `MobileSwipeAxisRatio`), tested without a browser. `LiveSocket` is remounted on online/pageshow/visibility since twui stops retrying after three attempts. Nothing is queued offline. +- Phone shell: rail is a slide-over below `md` (the shared `src/components/general/side-panel.tsx`, always mounted so it slides both ways; the rail passes `inertWhenClosed={false}` since it is the page's own rail from `md` up); rail internals use the `@rail:` container variant, not viewport `lg:`. Two swipes anywhere on a phone page move between panes: to the right opens the rail's drawer, to the left the conversation's bot panel (`cobble:open-bot-panel`, `src/utils/bot-panel-open-event.ts`, answered only by a conversation's header, so a page without one slides nothing). They are flicks, read by `src/hooks/use-horizontal-swipe.ts` (a field, a `data-no-swipe` panel, a box that scrolls sideways, a text selection, a finger down longer than `AppData.MobileSwipeMaxMs`, an open twui modal, a screen from `md` up and the open drawer all own the touch), with the thresholds and the one-decision state machine in `src/utils/swipe-gesture.ts` (`AppData.MobileSwipeMinPx`, `MobileSwipeAxisRatio`), tested without a browser. An open panel answers the one swipe back off its edge (`src/hooks/use-swipe-to-close.ts`, `sidePanelCloseSwipe`): a left drag closes the rail's drawer, a right drag the bot panel; `SidePanel` gives both the same phone width (`w-[420px] max-w-[92vw]`). `LiveSocket` is remounted on online/pageshow/visibility since twui stops retrying after three attempts. Nothing is queued offline. - **Web Push:** `push_subscriptions`, `user_presence`; VAPID keys generated into `envs` by `ensureVapidKeys`. `pushBotNotice` is the one trigger, skipped while the user is present (`AppData.PushPresenceWindowMs`, per user not per device). Best effort, no retry. Needs HTTPS. ### Bot files and folders diff --git a/src/components/general/side-panel.render.test.tsx b/src/components/general/side-panel.render.test.tsx index 6295d8f5..700aa7d2 100644 --- a/src/components/general/side-panel.render.test.tsx +++ b/src/components/general/side-panel.render.test.tsx @@ -54,6 +54,17 @@ describe("SidePanel", () => { expect(html.match(/data-no-swipe/g)?.length).toBe(2); }); + test("the rail's drawer and the bot panel open to the same phone width", () => { + const html = renderToString( + +

crew

+
, + ); + + expect(html).toContain("w-[420px]"); + expect(html).toContain("max-w-[92vw]"); + }); + test("a panel that is also part of the page is never inert", () => { const html = renderToString(