From 8af2d396ab7907fd93dd22c947a6cf038cb7e695 Mon Sep 17 00:00:00 2001 From: chengyongru <2755839590@qq.com> Date: Sat, 24 Oct 2026 18:19:51 +0800 Subject: [PATCH] fix(webui): tighten mobile chat layout and soften transcript edges --- webui/browser/fixture.tsx | 5 +- webui/browser/mobile-chat-layout-fixture.tsx | 52 ++++++++++++++ webui/browser/mobile-chat-layout.spec.ts | 70 +++++++++++++++++++ webui/browser/workspace-alignment.spec.ts | 17 +++-- .../thread/ComposerUsagePopover.tsx | 11 ++- .../src/components/thread/ThreadComposer.tsx | 21 +++--- .../src/components/thread/ThreadViewport.tsx | 2 +- .../components/workbench/PaneWorkbench.tsx | 2 +- webui/src/globals.css | 24 +++++-- webui/src/tests/thread-composer.test.tsx | 5 +- 10 files changed, 183 insertions(+), 26 deletions(-) create mode 100644 webui/browser/mobile-chat-layout-fixture.tsx create mode 100644 webui/browser/mobile-chat-layout.spec.ts diff --git a/webui/browser/fixture.tsx b/webui/browser/fixture.tsx index a07f2fc5b..cd90a3671 100644 --- a/webui/browser/fixture.tsx +++ b/webui/browser/fixture.tsx @@ -35,6 +35,7 @@ import { FileEditPathFixture } from "./file-edit-path-fixture"; import { QueuedGuidanceFixture } from "./queued-guidance-fixture"; import { WorkspaceAlignmentFixture } from "./workspace-alignment-fixture"; import { ComposerActionFixture } from "./composer-action-fixture"; +import { MobileChatLayoutFixture } from "./mobile-chat-layout-fixture"; const history: UIMessage[] = [ { id: "question", role: "user", content: "Earlier question", createdAt: 1_700_000_000_000 }, @@ -186,7 +187,9 @@ if (parameters.get("case") === "skeleton-additions") installSkeletonPreviewApi() if (parameters.get("case") === "idle-compaction") installIdleCompactionApi(); await initializeI18n(); createRoot(document.getElementById("root")!).render( - {parameters.get("case") === "composer-action" + {parameters.get("case") === "mobile-chat-layout" + ? + : parameters.get("case") === "composer-action" ? : parameters.get("case") === "workspace-alignment" ? diff --git a/webui/browser/mobile-chat-layout-fixture.tsx b/webui/browser/mobile-chat-layout-fixture.tsx new file mode 100644 index 000000000..7d7c000dc --- /dev/null +++ b/webui/browser/mobile-chat-layout-fixture.tsx @@ -0,0 +1,52 @@ +import { useEffect, useState } from "react"; +import { CalendarClock, ListFilter } from "lucide-react"; +import { ThreadComposer } from "@/components/thread/ThreadComposer"; +import { ThreadHeader } from "@/components/thread/ThreadHeader"; +import { ThreadViewport } from "@/components/thread/ThreadViewport"; +import { Button } from "@/components/ui/button"; +import type { UIMessage, WorkspaceScopePayload, WorkspacesPayload } from "@/lib/types"; + +const messages: UIMessage[] = [ + { id: "layout-question-1", role: "user", content: "手机上的聊天布局,能不能再紧凑自然一些?", createdAt: 1_700_000_000_000 }, + { id: "layout-answer-1", role: "assistant", content: "可以。先把空间分给真正需要阅读的消息,再整理输入框附近的辅助信息。\n\n工作区、上下文用量和权限都很有用,但不需要各占一行;减少空白,也不等于缩小按钮的点击范围。", createdAt: 1_700_000_001_000 }, + { id: "layout-question-2", role: "user", content: "Context 出现时不要把输入框顶上去,顶部的文字也别切得那么生硬。", createdAt: 1_700_000_002_000 }, + { id: "layout-answer-2", role: "assistant", content: "这版保留熟悉的输入方式,只调整空间和边缘。\n\n**辅助信息合成一行**\n\n工作区在左,上下文用量与权限在右。手机上用圆环和百分比表示 Context,详细用量仍可点开查看。\n\n**把空间还给消息**\n\n输入框下方不再堆两层状态,底部只保留舒适的安全间距,按钮仍然容易点击。\n\n**顶部自然收边**\n\n靠近顶栏的内容轻轻淡出,不再突然截成半行;正文仍然可以自由滚动。", createdAt: 1_700_000_003_000 }, +]; +const initialScope: WorkspaceScopePayload = { project_path: "/projects/nanobot", project_name: "nanobot", access_mode: "full" }; +const catalog: WorkspacesPayload = { + schema_version: 1, + default_access_mode: "full", + default_scope: initialScope, + recent_projects: [{ path: "/projects/nanobot", name: "nanobot" }], + controls: { can_change_project: true }, +}; + +export function MobileChatLayoutFixture({ parameters }: { parameters: URLSearchParams }) { + const [dark, setDark] = useState(parameters.has("dark")); + const [scope, setScope] = useState(() => parameters.has("long-project") + ? { ...initialScope, project_name: "nanobot-mobile-layout-preview" } + : initialScope); + useEffect(() => { document.documentElement.classList.toggle("dark", dark); }, [dark]); + return ( +
+ {}} onToggleTheme={() => setDark(value => !value)} + sessionInfoAction={} + promptNavigatorAction={} + /> + {}} + modelLabel="6.1-max" modelProvider="openai-codex" onTranscribeAudio={async () => ""} + contextUsage={parameters.has("no-context") ? null : { contextTokens: 44_000, contextWindowTokens: 200_000 }} + workspaceScope={scope} workspaceDefaultScope={initialScope} workspaceControls={catalog.controls} + workspaceProjectLocked={!parameters.has("project")} + onWorkspaceScopeChange={setScope} onLoadWorkspaceProjects={async () => catalog} + onResolveWorkspaceProject={async path => ({ path, name: "nanobot" })} + onFavoriteWorkspaceProject={async () => []} + onBrowseWorkspaceDirectories={async path => ({ path, parent: null, entries: [], truncated: false, host: "preview", platform: "Linux" })} + />} + /> +
+ ); +} diff --git a/webui/browser/mobile-chat-layout.spec.ts b/webui/browser/mobile-chat-layout.spec.ts new file mode 100644 index 000000000..5fda9927c --- /dev/null +++ b/webui/browser/mobile-chat-layout.spec.ts @@ -0,0 +1,70 @@ +import { expect, test } from "@playwright/test"; + +for (const { width, dark } of [{ width: 360, dark: false }, { width: 314, dark: true }, { width: 600, dark: false }]) { + test.describe(`mobile transcript at ${width}px`, () => { + test.use({ viewport: { width, height: 740 }, hasTouch: true, reducedMotion: "reduce" }); + test("keeps metadata tappable on one row and the top fade fixed while scrolling", async ({ page }) => { + await page.addInitScript(() => localStorage.setItem("nanobot.locale", "en")); + await page.route("**/api/**", route => route.fulfill({ json: {} })); + await page.goto(`/browser/fixture.html?case=mobile-chat-layout&project&long-project${dark ? "&dark" : ""}`); + const workspace = page.getByRole("button", { name: "Switch directory" }); + const usage = page.getByRole("button", { name: "Context 22%. Open context usage" }); + const access = page.getByRole("button", { name: "Workspace access mode: Full Access" }); + await expect(usage).toHaveText("22%"); + const boxes = await Promise.all([workspace, usage, access].map(control => control.boundingBox())); + const [directoryBox, usageBox, accessBox] = boxes.map(box => box!); + for (const box of boxes) { + expect(box!.height).toBeGreaterThanOrEqual(44); + expect(box!.width).toBeGreaterThanOrEqual(44); + expect(box!.y).toBeCloseTo(accessBox.y, 1); + } + expect(directoryBox.x + directoryBox.width).toBeLessThanOrEqual(usageBox.x); + expect(usageBox.x + usageBox.width).toBeLessThanOrEqual(accessBox.x); + expect(accessBox.x + accessBox.width).toBeLessThanOrEqual(width); + expect(740 - accessBox.y - accessBox.height).toBeCloseTo(8, 1); + expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBe(width); + + await usage.click(); + const details = page.getByRole("dialog", { name: "Context usage" }); + await expect(details.getByRole("progressbar", { name: "Context 22%" })).toHaveAttribute("aria-valuenow", "22"); + await page.keyboard.press("Escape"); + await expect(usage).toBeFocused(); + + const scroller = page.locator(".thread-message-viewport"); + await expect(scroller).toHaveCSS("--thread-top-clearance", "6px"); + await expect(scroller).toHaveCSS("--thread-top-fade-height", "22px"); + const mask = await scroller.evaluate(node => getComputedStyle(node).maskImage); + expect(mask).toContain("6px"); + expect(mask).toContain("22px"); + expect(mask).toContain("calc(100% - 36px)"); + await page.evaluate(() => document.fonts.ready); + await expect.poll(() => scroller.evaluate(node => node.scrollHeight - node.clientHeight)).toBeGreaterThan(100); + await expect.poll(() => scroller.evaluate(node => node.scrollHeight - node.clientHeight - node.scrollTop)).toBeLessThanOrEqual(1); + const before = (await scroller.boundingBox())!; + const initialScrollTop = await scroller.evaluate(node => node.scrollTop); + await page.mouse.move(before.x + before.width / 2, before.y + before.height / 2); + await page.mouse.wheel(0, -100); + await expect.poll(() => scroller.evaluate(node => node.scrollTop)).toBeLessThan(initialScrollTop - 50); + expect((await scroller.boundingBox())!.y).toBeCloseTo(before.y, 1); + expect(await scroller.evaluate(node => getComputedStyle(node).maskImage)).toBe(mask); + }); + }); +} + +test.describe("desktop transcript spacing", () => { + test.use({ viewport: { width: 1440, height: 900 }, reducedMotion: "reduce" }); + test("preserves desktop footer spacing and the bottom-only fade", async ({ page }) => { + await page.addInitScript(() => localStorage.setItem("nanobot.locale", "en")); + await page.route("**/api/**", route => route.fulfill({ json: {} })); + await page.goto("/browser/fixture.html?case=mobile-chat-layout&project"); + const access = page.getByRole("button", { name: "Workspace access mode: Full Access" }); + await expect(access).toBeVisible(); + expect(await access.evaluate(node => !!node.closest(".thread-composer-footer-primary"))).toBe(true); + const meta = (await page.locator(".thread-composer-meta").boundingBox())!; + expect(900 - meta.y - meta.height).toBeCloseTo(18, 1); + const scroller = page.locator(".thread-message-viewport"); + await expect(scroller).toHaveCSS("--thread-top-clearance", "0px"); + await expect(scroller).toHaveCSS("--thread-top-fade-height", "0px"); + expect(await scroller.evaluate(node => getComputedStyle(node).maskImage)).toContain("calc(100% - 36px)"); + }); +}); diff --git a/webui/browser/workspace-alignment.spec.ts b/webui/browser/workspace-alignment.spec.ts index dfe88d91e..624e4a957 100644 --- a/webui/browser/workspace-alignment.spec.ts +++ b/webui/browser/workspace-alignment.spec.ts @@ -58,9 +58,9 @@ for (const variant of ["hero", "thread"]) for (const width of [280, 320, 390, 60 }); } -for (const variant of ["hero", "thread"]) { - test.describe(`${variant} mobile permission with usage`, () => { - test.use({ viewport: { width: 320, height: 900 }, hasTouch: true, reducedMotion: "reduce" }); +for (const variant of ["hero", "thread"]) for (const width of [320, 600]) { + test.describe(`${variant} mobile permission with usage at ${width}px`, () => { + test.use({ viewport: { width, height: 900 }, hasTouch: true, reducedMotion: "reduce" }); test("keeps access on the lower right when context usage appears", async ({ page }) => { await page.addInitScript(() => localStorage.setItem("nanobot.locale", "en")); await page.route("**/api/commands", route => route.fulfill({ json: { commands: [] } })); @@ -69,11 +69,14 @@ for (const variant of ["hero", "thread"]) { const access = (await page.getByRole("button", { name: "Workspace access mode: Full Access" }).boundingBox())!; const usage = (await page.getByTestId("composer-context-usage").boundingBox())!; expect(Math.abs(access.y - workspace.y)).toBeLessThan(1); - expect(usage.y + usage.height).toBeLessThanOrEqual(access.y); - expect(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth)).toBe(false); - await page.getByTestId("composer-context-usage").focus(); + expect(Math.abs(usage.y - access.y)).toBeLessThan(1); + expect(workspace.x + workspace.width).toBeLessThanOrEqual(usage.x); + expect(usage.x + usage.width).toBeLessThanOrEqual(access.x); + expect(access.x + access.width).toBeLessThanOrEqual(width); + expect(await page.getByTestId("composer-context-usage").textContent()).toBe("50%"); + await page.getByRole("button", { name: "Switch directory" }).focus(); await page.keyboard.press("Tab"); - await expect(page.getByRole("button", { name: "Switch directory" })).toBeFocused(); + await expect(page.getByTestId("composer-context-usage")).toBeFocused(); await page.keyboard.press("Tab"); await expect(page.getByRole("button", { name: "Workspace access mode: Full Access" })).toBeFocused(); }); diff --git a/webui/src/components/thread/ComposerUsagePopover.tsx b/webui/src/components/thread/ComposerUsagePopover.tsx index d03698ba5..8f07d066e 100644 --- a/webui/src/components/thread/ComposerUsagePopover.tsx +++ b/webui/src/components/thread/ComposerUsagePopover.tsx @@ -59,11 +59,13 @@ export function ComposerUsagePopover({ context, rounds, showLabel = false, + compactLabel = false, bottomSheet = false, }: { context: ComposerContextUsage | null; rounds: readonly ComposerRoundUsage[]; showLabel?: boolean; + compactLabel?: boolean; bottomSheet?: boolean; }) { const { t, i18n } = useTranslation(); @@ -123,6 +125,7 @@ export function ComposerUsagePopover({ const RoundTrigger = bottomSheet ? PopoverTrigger : TooltipTrigger; const RoundContent = bottomSheet ? PopoverContent : TooltipContent; const RoundBar = bottomSheet ? "button" : "span"; + const showTextLabel = showLabel && (!compactLabel || contextPercentage !== null); const trigger = ( ); diff --git a/webui/src/components/thread/ThreadComposer.tsx b/webui/src/components/thread/ThreadComposer.tsx index 3a1c5d873..f2869dc02 100644 --- a/webui/src/components/thread/ThreadComposer.tsx +++ b/webui/src/components/thread/ThreadComposer.tsx @@ -2547,8 +2547,9 @@ export function ThreadComposer({ onClick={modelNeedsSetup ? onModelBadgeClick : undefined} /> ) : null; + const usageInMeta = mobileWorkspaceControls || compactControls; const usageControl = !voiceRecorder.isRecording && (contextUsage || recentRoundUsage.length) ? ( - + ) : null; const inputTextClasses = cn( // Keep the overlay's CJK/Latin spacing aligned with the native textarea caret. @@ -2610,7 +2611,7 @@ export function ThreadComposer({ "thread-composer-form relative w-full [--composer-action-margin:0px]", isHero ? "px-0 [--composer-action-size:2rem] [--composer-footer-inset:0.75rem] sm:[--composer-footer-inset:1rem]" - : "px-1 pb-1.5 pt-1 [--composer-action-size:2.25rem] [--composer-footer-inset:0.625rem] sm:px-0 sm:[--composer-footer-inset:0.75rem]", + : "px-1 pb-0 pt-1 [--composer-action-size:2.25rem] [--composer-footer-inset:0.625rem] sm:px-0 sm:pb-1.5 sm:[--composer-footer-inset:0.75rem]", compactWhenIdle && "thread-composer-collapsible-layout", paletteBeside && "grid grid-cols-2 items-start gap-2 p-0", )} @@ -2838,7 +2839,7 @@ export function ThreadComposer({ )} > {modelControl} - {!compactControls ? usageControl : null} + {!usageInMeta ? usageControl : null} @@ -2899,18 +2900,22 @@ export function ThreadComposer({ - {workspaceControl || mobileWorkspaceControls && accessControl || compactControls && usageControl ? ( + {workspaceControl || mobileWorkspaceControls && accessControl || usageInMeta && usageControl ? (
- {mobileWorkspaceControls && compactControls && usageControl ?
{usageControl}
: null}
{workspaceControl}
- {!mobileWorkspaceControls && compactControls && usageControl ?
{usageControl}
: null} - {mobileWorkspaceControls && accessControl ?
{accessControl}
: null} + {usageInMeta && usageControl || mobileWorkspaceControls && accessControl ? ( +
+ {usageInMeta ? usageControl : null} + {mobileWorkspaceControls ? accessControl : null} +
+ ) : null}
) : null} diff --git a/webui/src/components/thread/ThreadViewport.tsx b/webui/src/components/thread/ThreadViewport.tsx index 87c20f3e5..49249c080 100644 --- a/webui/src/components/thread/ThreadViewport.tsx +++ b/webui/src/components/thread/ThreadViewport.tsx @@ -1213,7 +1213,7 @@ export const ThreadViewport = forwardRef diff --git a/webui/src/components/workbench/PaneWorkbench.tsx b/webui/src/components/workbench/PaneWorkbench.tsx index d75f236a0..e80d3f2f4 100644 --- a/webui/src/components/workbench/PaneWorkbench.tsx +++ b/webui/src/components/workbench/PaneWorkbench.tsx @@ -830,7 +830,7 @@ export function PaneWorkbench({ {chrome ? ( -