Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): allow back swipes on Forum cards

Generde3ef9a21159
diff --git a/src/web/src/components/community/channels/forum-view.swipe.dom.test.tsx b/src/web/src/components/community/channels/forum-view.swipe.dom.test.tsx
new file mode 100644
index 000000000..8e262aaea
--- /dev/null
+++ b/src/web/src/components/community/channels/forum-view.swipe.dom.test.tsx
@@ -0,0 +1,126 @@
+import { afterEach, describe, expect, it, vi } from "vitest"
+import { fireEvent, mockElementGeometry, render, waitFor } from "@/test/react-dom-harness"
+import { SwipeRoot, SwipePortal, SwipeViewport, SwipePopup, SwipeTitle } from "@/components/ui/swipe-container"
+import { canStartSwipe } from "@/components/ui/swipe-gesture-policy"
+import type { ForumThread } from "@/lib/community/models/message"
+import { tid } from "@/lib/community/testids"
+import { ForumView } from "./forum-view"
+
+vi.mock("@/hooks/use-mobile", () => ({ useIsMobile: () => true, useBreakpoint: () => "mobile" }))
+vi.mock("@/lib/community-db/projections", () => ({ useCanonicalProfilesByUserId: () => new Map() }))
+
+const hitTest = Object.getOwnPropertyDescriptor(document, "elementFromPoint")
+afterEach(() => {
+ vi.restoreAllMocks()
+ if (hitTest) Object.defineProperty(document, "elementFromPoint", hitTest)
+ else Reflect.deleteProperty(document, "elementFromPoint")
+})
+
+const post: ForumThread = {
+ id: "post", name: "Post", messageCount: 1, lastMessageAt: "2026-10-22T10:00:00Z",
+ parent: { authorName: "Author", text: "Root" }, authorId: "author", authorAvatar: "A", authorAvatarVersion: 0,
+ openerMessageId: "opener", tags: [], preview: "Card body", participants: [], participantCount: 1,
+}
+
+function fixture({ empty = false, kind = "page" as "page" | "overlay" } = {}) {
+ const opened = vi.fn(), changed = vi.fn(), archive = vi.fn()
+ const view = render(<SwipeRoot kind={kind} open onOpenChange={changed}>
+ <SwipePortal><SwipeViewport data-testid="page-viewport"><SwipePopup data-testid="page-popup">
+ <SwipeTitle>Forum</SwipeTitle>
+ <ForumView forumChannelId="forum" members={[]} posts={empty ? [] : [post]}
+ tag="All" tagsKnown availableTags={[]} onTagChange={() => {}} onOpenPost={opened}
+ onEditPostTags={archive} canEditPostTags={() => true}
+ onScrollRoot={node => { if (node) mockElementGeometry(node, { clientHeight: 600, clientWidth: 390 }) }} />
+ </SwipePopup></SwipeViewport></SwipePortal>
+ </SwipeRoot>)
+ const root = view.getByTestId("page-viewport"), popup = view.getByTestId("page-popup")
+ const restore = mockElementGeometry(popup, { width: 390, height: 600, offsetWidth: 390, offsetHeight: 600, clientWidth: 390, clientHeight: 600 })
+ const target = view.getByText(empty ? "No posts with this tag yet. Start one with New Post." : "Card body")
+ Object.defineProperty(document, "elementFromPoint", { configurable: true, value: () => target })
+ return { ...view, root, popup, target, opened, changed, archive, restore }
+}
+
+function touch(target: Element, type: "touchstart" | "touchmove" | "touchend" | "touchcancel", x: number, timeStamp: number, y = 100) {
+ const point = { clientX: x, clientY: y, identifier: 0, target }
+ const event = new Event(type, { bubbles: true, cancelable: true })
+ Object.defineProperties(event, {
+ touches: { value: type === "touchend" || type === "touchcancel" ? [] : [point] },
+ changedTouches: { value: [point] }, timeStamp: { value: timeStamp },
+ })
+ fireEvent(target, event)
+}
+
+describe("Forum navigation row inside the real shared Drawer", () => {
+ it.each([false, true])("admits populated and empty content through the same page policy (empty=%s)", async empty => {
+ const f = fixture({ empty })
+ try {
+ expect(canStartSwipe({ target: f.target, root: f.root, x: 40, y: 100, kind: "page", enabled: true, pointerType: "touch" })).toBe(true)
+ touch(f.target, "touchstart", 40, 100)
+ touch(f.target, "touchmove", 130, 200)
+ touch(f.target, "touchmove", 360, 300)
+ touch(f.target, "touchend", 360, 400)
+ await waitFor(() => expect(f.changed).toHaveBeenCalledOnce())
+ expect(f.changed.mock.calls[0][0]).toBe(false)
+ expect(f.opened).not.toHaveBeenCalled()
+ } finally { f.restore() }
+ })
+
+ it.each(["touchend", "touchcancel"] as const)("restores a short or cancelled gesture without opening a post (%s)", async end => {
+ const f = fixture()
+ try {
+ touch(f.target, "touchstart", 40, 100)
+ touch(f.target, "touchmove", 80, 300)
+ touch(f.target, "touchmove", 95, 1000)
+ expect(f.popup).toHaveAttribute("data-swiping")
+ touch(f.target, end, 95, 1500)
+ await waitFor(() => expect(f.popup).not.toHaveAttribute("data-swiping"))
+ expect(f.changed).not.toHaveBeenCalled()
+ expect(f.opened).not.toHaveBeenCalled()
+ } finally { f.restore() }
+ })
+
+ it("preserves post activation and embedded action ownership", () => {
+ const f = fixture()
+ try {
+ const card = f.getByTestId(tid.forumThreadCard(post.id))
+ expect(card).toHaveAttribute("role", "button")
+ expect(card).toHaveAttribute("tabindex", "0")
+ fireEvent.click(f.target)
+ fireEvent.keyDown(card, { key: "Enter" })
+ fireEvent.keyDown(card, { key: " " })
+ expect(f.opened.mock.calls).toEqual([[post.id], [post.id], [post.id]])
+ f.opened.mockClear()
+ const control = f.getByRole("button", { name: /^Archive post$/ })
+ expect(canStartSwipe({ target: control, root: f.root, x: 40, y: 100, kind: "page", enabled: true, pointerType: "touch" })).toBe(false)
+ fireEvent.click(control)
+ fireEvent.keyDown(control, { key: "Enter" })
+ expect(f.archive).toHaveBeenCalledExactlyOnceWith(post.id, ["archived"])
+ expect(f.opened).not.toHaveBeenCalled()
+ } finally { f.restore() }
+ })
+
+ it("keeps the real card outside overlay admission", () => {
+ const f = fixture({ kind: "overlay" })
+ try {
+ expect(canStartSwipe({ target: f.target, root: f.root, x: 40, y: 100, enabled: true, pointerType: "touch" })).toBe(false)
+ touch(f.target, "touchstart", 40, 100)
+ touch(f.target, "touchmove", 360, 300)
+ touch(f.target, "touchend", 360, 400)
+ expect(f.changed).not.toHaveBeenCalled()
+ } finally { f.restore() }
+ })
+
+ it("leaves a vertical drag to the list direction instead of navigating", () => {
+ const f = fixture()
+ const restore = mockElementGeometry(f.getByTestId(tid.forumPostList), { clientHeight: 600, scrollHeight: 1200 })
+ try {
+ touch(f.target, "touchstart", 40, 100, 100)
+ touch(f.target, "touchmove", 40, 300, 160)
+ touch(f.target, "touchmove", 40, 500, 300)
+ touch(f.target, "touchend", 40, 700, 300)
+ expect(f.popup).not.toHaveAttribute("data-swiping")
+ expect(f.changed).not.toHaveBeenCalled()
+ expect(f.opened).not.toHaveBeenCalled()
+ } finally { restore(); f.restore() }
+ })
+})
diff --git a/src/web/src/components/community/channels/forum-view.tsx b/src/web/src/components/community/channels/forum-view.tsx
index 13b58701b..c6e755bc0 100644
--- a/src/web/src/components/community/channels/forum-view.tsx
+++ b/src/web/src/components/community/channels/forum-view.tsx
@@ -308,6 +308,7 @@ export function ForumView({
key={p.id}
role="button"
tabIndex={0}
+ data-page-swipe-navigation-row=""
data-msg-id={p.openerMessageId || undefined}
data-testid={tid.forumThreadCard(p.id)}
onClick={() => onOpenPost(p.id)}
diff --git a/src/web/src/components/ui/swipe-container.dom.test.tsx b/src/web/src/components/ui/swipe-container.dom.test.tsx
index 878fd1c2b..2546a1947 100644
--- a/src/web/src/components/ui/swipe-container.dom.test.tsx
+++ b/src/web/src/components/ui/swipe-container.dom.test.tsx
@@ -198,6 +198,62 @@ describe("shared Drawer interaction", () => {
} finally { restore(); root.remove() }
})
+ it("limits navigation-row admission to the owning page and preserves outer control ownership", () => {
+ const root = document.createElement("div"), row = document.createElement("div"), target = document.createElement("span")
+ row.setAttribute("role", "button")
+ row.appendChild(target); root.appendChild(row); document.body.appendChild(root)
+ const start = { target, root, x: 40, y: 100, enabled: true, pointerType: "touch", kind: "page" as const }
+ const outer = document.createElement("button")
+ try {
+ expect(canStartSwipe(start)).toBe(false)
+ row.setAttribute("data-page-swipe-navigation-row", "")
+ expect(canStartSwipe(start)).toBe(true)
+ expect(canStartSwipe({ ...start, kind: "overlay" })).toBe(false)
+ expect(canStartSwipe({ ...start, root: document.createElement("div") })).toBe(false)
+ document.body.appendChild(outer); outer.appendChild(root)
+ expect(canStartSwipe(start)).toBe(false)
+ } finally { root.remove(); outer.remove() }
+ })
+
+ it.each([
+ '<button><span>Action</span></button>', '<a href="/post"><span>Link</span></a>',
+ '<input aria-label="Edit">', '<div contenteditable="true"><span>Edit</span></div>',
+ '<div draggable="true"><span>Drag</span></div>', '<div data-swipe-ignore><span>Own gesture</span></div>',
+ ])("keeps nested owners inside an opted-in navigation row (%s)", html => {
+ const root = document.createElement("div"), row = document.createElement("div")
+ row.setAttribute("role", "link"); row.setAttribute("data-page-swipe-navigation-row", "")
+ row.innerHTML = html; root.appendChild(row); document.body.appendChild(root)
+ const target = row.querySelector("span") ?? row.firstElementChild!
+ try {
+ expect(canStartSwipe({ target, root, x: 40, y: 100, enabled: true, pointerType: "touch", kind: "page" })).toBe(false)
+ } finally { root.remove() }
+ })
+
+ it("does not use navigation semantics to bypass explicit or horizontal axis owners", () => {
+ const root = document.createElement("div"), row = document.createElement("div"), target = document.createElement("span")
+ row.setAttribute("role", "button"); row.setAttribute("data-page-swipe-navigation-row", "")
+ row.appendChild(target); root.appendChild(row); document.body.appendChild(root)
+ const restore = mockElementGeometry(row, { clientWidth: 100, scrollWidth: 300 })
+ const start = { target, root, x: 40, y: 100, enabled: true, pointerType: "touch", kind: "page" as const }
+ try {
+ row.setAttribute("data-swipe-ignore", "")
+ expect(canStartSwipe(start)).toBe(false)
+ row.removeAttribute("data-swipe-ignore")
+ for (const axis of ["", "x", "y"]) {
+ row.setAttribute("data-base-ui-swipe-ignore", axis)
+ expect(canStartSwipe(start)).toBe(false)
+ }
+ row.removeAttribute("data-base-ui-swipe-ignore")
+ row.style.overflowX = "auto"
+ expect(canStartSwipe(start)).toBe(false)
+ row.style.overflowX = "visible"
+ row.style.overflowY = "auto"
+ expect(canStartSwipe(start)).toBe(true)
+ expect(canStartSwipe({ ...start, x: 120 })).toBe(false)
+ expect(canStartSwipe({ ...start, touches: 2 })).toBe(false)
+ } finally { restore(); root.remove() }
+ })
+
it("does not fabricate native measurements when the Android bridge is unavailable or invalid", () => {
vi.spyOn(navigator, "userAgent", "get").mockReturnValue("Android WebView")
const root = document.createElement("div"), target = document.createElement("span")
diff --git a/src/web/src/components/ui/swipe-gesture-policy.ts b/src/web/src/components/ui/swipe-gesture-policy.ts
index 078714408..dc05efbc2 100644
--- a/src/web/src/components/ui/swipe-gesture-policy.ts
+++ b/src/web/src/components/ui/swipe-gesture-policy.ts
@@ -1,9 +1,10 @@
export type SwipeDirection = "left" | "right" | "up" | "down"
-const INTERACTIVE_START = [
- "button", "a", "input", "textarea", "select", "label", "summary", "audio", "video", "canvas", "iframe",
+const INTERACTIVE_START = "button,a,[role='button'],[role='link']"
+const PROTECTED_START = [
+ "input", "textarea", "select", "label", "summary", "audio", "video", "canvas", "iframe",
"[contenteditable]:not([contenteditable='false'])",
- "[role='button']", "[role='link']", "[role='slider']", "[role='textbox']",
+ "[role='slider']", "[role='textbox']",
"[role='spinbutton']", "[role='combobox']", "[role='tab']", "[role='option']", "[role='menuitem']",
"[draggable='true']", "[data-swipe-ignore]",
"[data-slot='resizable-handle']", "[data-dnd-handle]",
@@ -22,7 +23,11 @@ export function canStartSwipe({
kind?: "page" | "overlay"
}) {
if (!enabled || pointerType !== "touch" || touches !== 1 || !(target instanceof Element)) return false
- if (target.closest(INTERACTIVE_START)) return false
+ if (target.closest(PROTECTED_START)) return false
+ for (let control: Element | null = target; control; control = control.parentElement) {
+ if (control.matches(INTERACTIVE_START)
+ && (kind !== "page" || !root.contains(control) || !control.hasAttribute("data-page-swipe-navigation-row"))) return false
+ }
const document = root.ownerDocument
const view = document.defaultView
const selection = document.getSelection()
diff --git a/src/web/src/test/e2e-ui/40-mobile-server-header-hierarchy.spec.ts b/src/web/src/test/e2e-ui/40-mobile-server-header-hierarchy.spec.ts
index 7640bfb81..871326e79 100644
--- a/src/web/src/test/e2e-ui/40-mobile-server-header-hierarchy.spec.ts
+++ b/src/web/src/test/e2e-ui/40-mobile-server-header-hierarchy.spec.ts
@@ -18,14 +18,14 @@ async function expectMobileBack(page: Page) {
return control
}
-async function expectRootListDuringCancelledSwipe(page: Page, channelId: string) {
+async function expectRootListDuringCancelledSwipe(page: Page, channelId: string, startY = 220) {
const pathname = new URL(page.url()).pathname
const popup = page.locator('[data-slot="mobile-page"][data-open]')
await expect(popup).toHaveCount(1)
await expect(popup).not.toHaveAttribute("data-starting-style")
const session = await page.context().newCDPSession(page)
try {
- const point = (x: number) => [{ x, y: 220, radiusX: 1, radiusY: 1, force: 1, id: 1 }]
+ const point = (x: number) => [{ x, y: startY, radiusX: 1, radiusY: 1, force: 1, id: 1 }]
await session.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: point(80) })
await session.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: point(150) })
await session.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: point(280) })
@@ -86,6 +86,80 @@ test.describe("mobile server header direct hierarchy", () => {
return { serverId, textId, forumId, threadId, postId, threadName, postTitle }
}
+ for (const populated of [false, true]) {
+ test(`Forum ${populated ? "card body" : "empty body"} shares page return and keeps swipe distinct from opening a post`, async ({ caseActors, browserName }) => {
+ test.skip(browserName !== "chromium", "Existing Chromium CDP touch driver; no native-device claim")
+ const actors = await caseActors(["alice"])
+ const serverId = await actors.seed.seedServer("alice", `forum-page-swipe-${Date.now()}`)
+ const channelId = await actors.seed.seedChannel("alice", serverId, "swipe-root-text")
+ const forumId = await actors.seed.seedChannel("alice", serverId, "swipe-forum", "forum")
+ const postId = populated ? await actors.seed.seedForumThread("alice", forumId, "Swipe card", "Swipe body") : null
+ const { page } = await actors.asUser("alice", { viewport: { width: 390, height: 844 }, hasTouch: true })
+ const forumPath = `/c/channels/${serverId}/${forumId}`
+ let childEntries = 0, childReads = 0
+ const requested = (request: Request) => {
+ if (!postId) return
+ const url = new URL(request.url())
+ if (request.method() === "GET" && url.pathname === `/api/community/channels/${postId}/messages` && url.searchParams.get("entry") === "1") childEntries += 1
+ if (request.method() === "PUT" && url.pathname === `/api/community/channels/${postId}/read`) childReads += 1
+ }
+ page.on("request", requested)
+ try {
+ await page.goto(forumPath, { waitUntil: "commit" })
+ await expectMobileBack(page)
+ const foreground = page.locator('[data-mobile-page-active="true"]')
+ const body = postId
+ ? foreground.getByTestId(tid.forumThreadCard(postId)).locator("p")
+ : foreground.getByText("No posts with this tag yet. Start one with New Post.", { exact: true })
+ await expect(body).toBeVisible()
+ const rect = await body.boundingBox()
+ expect(rect).not.toBeNull()
+ const startY = rect!.y + rect!.height / 2
+ expect(80).toBeGreaterThan(rect!.x)
+ expect(80).toBeLessThan(rect!.x + rect!.width)
+ await expectRootListDuringCancelledSwipe(page, channelId, startY)
+ const popup = foreground.locator('[data-slot="mobile-page"][data-open]')
+ const session = await page.context().newCDPSession(page)
+ let touching = false
+ try {
+ const point = (x: number) => [{ x, y: startY, radiusX: 1, radiusY: 1, force: 1, id: 1 }]
+ await session.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: point(80) })
+ touching = true
+ await session.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: point(150) })
+ await session.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: point(360) })
+ await expect(popup).toHaveAttribute("data-swiping")
+ await session.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] })
+ touching = false
+ } finally {
+ try { if (touching) await session.send("Input.dispatchTouchEvent", { type: "touchCancel", touchPoints: [] }) }
+ finally { await session.detach() }
+ }
+ await expect.poll(() => new URL(page.url()).pathname).toBe(`/c/channels/${serverId}`)
+ await expect(page.getByTestId(tid.channelRow(forumId))).toBeVisible()
+ expect(childReads).toBe(0)
+ await test.info().attach("forum-page-swipe-result", { body: JSON.stringify({ populated, forumPath, finalPath: new URL(page.url()).pathname, childEntries, childReads, startY, input: "Chromium CDP touch, not native device" }), contentType: "application/json" })
+ if (postId) {
+ await page.getByTestId(tid.channelRow(forumId)).click()
+ const card = page.locator('[data-mobile-page-active="true"]').getByTestId(tid.forumThreadCard(postId))
+ await expect(card).toBeVisible()
+ await card.tap()
+ await expect.poll(() => new URL(page.url()).pathname).toBe(`/c/channels/${serverId}/${postId}`)
+ await expect(page.locator('[data-mobile-page-active="true"]').getByTestId(tid.composerInput)).toBeVisible()
+ for (const key of ["Enter", "Space"]) {
+ await page.locator('[data-mobile-page-active="true"]').getByRole("banner").getByRole("button", { name: "Back", exact: true }).click()
+ await expect(card).toBeVisible()
+ await card.press(key)
+ await expect.poll(() => new URL(page.url()).pathname).toBe(`/c/channels/${serverId}/${postId}`)
+ await expect(page.locator('[data-mobile-page-active="true"]').getByTestId(tid.composerInput)).toBeVisible()
+ }
+ const metadata = await page.request.get(new URL(`/api/community/channels/${postId}`, page.url()).href)
+ expect(metadata.status()).toBe(200)
+ expect(await metadata.json()).toMatchObject({ id: postId, serverId, parentChannelId: forumId })
+ }
+ } finally { page.off("request", requested) }
+ })
+ }
+
test("top-level text and forum replace directly to the canonical server root", async ({ caseActors }) => {
const actors = await caseActors(["alice"])
const { asUser } = actors