fix(webui): tighten mobile chat layout and soften transcript edges

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-24 19:29:24 +08:00
1 parent ce885fa31e
commit 8af2d396ab
10 files changed
+183 -26

No files matched your search

+4 -1
View File
@@ -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(<TooltipProvider>
{parameters.get("case") === "composer-action"
{parameters.get("case") === "mobile-chat-layout"
? <ClientProvider client={railClient} token="fixture"><MobileChatLayoutFixture parameters={parameters} /></ClientProvider>
: parameters.get("case") === "composer-action"
? <ComposerActionFixture parameters={parameters} />
: parameters.get("case") === "workspace-alignment"
? <WorkspaceAlignmentFixture parameters={parameters} />
@@ -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<WorkspaceScopePayload>(() => parameters.has("long-project")
? { ...initialScope, project_name: "nanobot-mobile-layout-preview" }
: initialScope);
useEffect(() => { document.documentElement.classList.toggle("dark", dark); }, [dark]);
return (
<main className="thread-workspace relative flex min-w-0 flex-col overflow-hidden bg-background" style={{ height: "100dvh" }}>
<ThreadHeader title="Mobile layout preview" hideTitle theme={dark ? "dark" : "light"}
onToggleSidebar={() => {}} onToggleTheme={() => setDark(value => !value)}
sessionInfoAction={<Button variant="ghost" size="icon" aria-label="Session details"><CalendarClock className="h-3.5 w-3.5" /></Button>}
promptNavigatorAction={<Button variant="ghost" size="icon" aria-label="Conversation navigation"><ListFilter className="h-3.5 w-3.5" /></Button>}
/>
<ThreadViewport messages={messages} isStreaming={false} conversationReady conversationKey="websocket:mobile-layout-preview"
hasMoreBefore={false} showScrollToBottomButton
composer={<ThreadComposer variant="thread" onSend={() => {}}
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" })}
/>}
/>
</main>
);
}
+70
View File
@@ -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)");
});
});
+10 -7
View File
@@ -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();
});