Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): align forum spacing and platform actions (#1141)

Gener758a31c6ea13
diff --git a/DESIGN.md b/DESIGN.md
index 646fd5c37..3d5ecbb1e 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -111,7 +111,9 @@ Two stages, not three. The split lives at **`640px`** — Tailwind's default `sm
| Stage | Range | Layout shape |
| --- | --- | --- |
| **Mobile** | `< 640px` | Single column with pathname-owned list/detail routing. Back button in detail headers. Popovers may promote to sheets when they'd overflow. |
-| **Desktop** | `≥ 640px` | Multi-column shells — server rail + channel/DM sidebar + main (in community), or app sidebar + workspace (elsewhere). Hover surfaces reveal actions. No back button in headers. |
+| **Desktop** | `≥ 640px` | Multi-column shells — server rail + channel/DM sidebar + main (in community), or app sidebar + workspace (elsewhere). No back button in headers. |
+
+Forum post actions use the client platform independently of these layout checkpoints. Mobile native and mobile Web, including tablet browsers, keep actions visible at every width. Desktop native and desktop Web reveal actions on row hover, row focus or while the corresponding popup is open, including in narrow windows. Unknown/initial hydration keeps actions visible. Actions retain their 32px buttons and layout space; permissions determine which buttons and columns exist. This is the Forum-specific exception to the general touch-target sizing rule below. The first title row is at least 32px even without actions, and grows with content; summaries start below it. Forum lists use horizontal 0 / vertical 8px padding, rows use 16px, and preview margins plus metadata/tag gaps use 8px. Preserve the narrow tag row's 28px author-name alignment and the existing footer order. Selected ordinary filter chips use an inset ring without enlarging the horizontal rail.
For Community server routes, the URL owns selection and the checkpoint owns composition:
diff --git a/src/shared/src/index.ts b/src/shared/src/index.ts
index e36b275f2..3e1c16146 100644
--- a/src/shared/src/index.ts
+++ b/src/shared/src/index.ts
@@ -822,7 +822,7 @@ export { extractMentionedUserIds, MENTION_TYPES, isMentionType, MENTION_IDENTIFI
export type { MentionCandidate, MentionType } from "./utils/community-mentions";
export { parseReleaseVersion, releaseVersionGte, semverGte } from "./semver";
export type { ReleaseVersion } from "./semver";
-export { resolveMode, cliCommand, cliPackageName, updateCommand, daemonCommand, getBaseUrl, isTauri, isDesktop, isMobile, tauriInvoke } from "./mode";
+export { resolveMode, cliCommand, cliPackageName, updateCommand, daemonCommand, getBaseUrl, isTauri, isDesktop, isMobile, getClientPlatform, tauriInvoke } from "./mode";
export type { AlookMode, ModeSignals, BaseUrlSignals } from "./mode";
export { COMMUNITY_BOT_ACTOR_HEADER, COMMUNITY_CONTRACT_HEADER, COMMUNITY_CONTRACT_VERSION, COMMUNITY_RESOURCE_CONTRACT_VERSION, requestedCommunityContract, requestsCommunityContract, type CommunityContract } from "./community-contract";
export * from "./community-resources";
diff --git a/src/shared/src/mode.ts b/src/shared/src/mode.ts
index 847c1291f..29c4292be 100644
--- a/src/shared/src/mode.ts
+++ b/src/shared/src/mode.ts
@@ -45,6 +45,20 @@ export function isMobile(): boolean {
return /(android|iphone|ipad|ipod)/i.test(ua);
}
+export function getClientPlatform(): "mobile" | "desktop" | "unknown" {
+ if (!hasWindow() || typeof window === "undefined" || typeof navigator === "undefined") return "unknown";
+ const ua = navigator.userAgent ?? "";
+ const platform = navigator.userAgentData?.platform ?? navigator.platform ?? "";
+ const identity = `${ua} ${platform}`;
+ if (/(android|iphone|ipad|ipod)/i.test(identity)
+ || navigator.userAgentData?.mobile === true
+ || (/(macintosh|macintel)/i.test(identity) && navigator.maxTouchPoints > 1)) {
+ return "mobile";
+ }
+ if (/(macintosh|macintel|windows|win32|win64|linux|cros|chrome os)/i.test(identity)) return "desktop";
+ return "unknown";
+}
+
export async function tauriInvoke<T>(command: string, args?: Record<string, unknown>): Promise<T> {
if (!isTauri()) {
throw new Error("tauriInvoke called outside of Tauri context");
diff --git a/src/shared/test/mode.test.ts b/src/shared/test/mode.test.ts
index 2faa23018..faeb33586 100644
--- a/src/shared/test/mode.test.ts
+++ b/src/shared/test/mode.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
-import { resolveMode, cliCommand, cliPackageName, updateCommand, daemonCommand, getBaseUrl, isTauri, isDesktop, isMobile, tauriInvoke } from "../src/mode";
+import { resolveMode, cliCommand, cliPackageName, updateCommand, daemonCommand, getBaseUrl, isTauri, isDesktop, isMobile, getClientPlatform, tauriInvoke } from "../src/mode";
describe("resolveMode", () => {
it("production: no signals", () => {
@@ -180,6 +180,52 @@ describe("isMobile", () => {
});
});
+describe("getClientPlatform", () => {
+ afterEach(() => vi.unstubAllGlobals());
+
+ const clients: [string, Record<string, unknown>, string][] = [
+ ["iPhone", { userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 26_5 like Mac OS X)" }, "mobile"],
+ ["iPad", { userAgent: "Mozilla/5.0 (iPad; CPU OS 26_5 like Mac OS X)" }, "mobile"],
+ ["Android phone", { userAgent: "Mozilla/5.0 (Linux; Android 16; Pixel) Mobile" }, "mobile"],
+ ["Android tablet", { userAgent: "Mozilla/5.0 (Linux; Android 16; Tablet)" }, "mobile"],
+ ["desktop-style iPad", { userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15", platform: "MacIntel", maxTouchPoints: 5 }, "mobile"],
+ ["mobile client hint", { userAgent: "Reduced UA", userAgentData: { mobile: true } }, "mobile"],
+ ["Android desktop-style hint", { userAgent: "Mozilla/5.0 (X11; Linux x86_64)", userAgentData: { mobile: false, platform: "Android" } }, "mobile"],
+ ["Mac", { userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X)", platform: "MacIntel", maxTouchPoints: 0 }, "desktop"],
+ ["Windows touch laptop", { userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64)", platform: "Win32", maxTouchPoints: 10 }, "desktop"],
+ ["Linux", { userAgent: "Mozilla/5.0 (X11; Linux x86_64)" }, "desktop"],
+ ["ChromeOS", { userAgent: "Mozilla/5.0 (X11; CrOS x86_64)" }, "desktop"],
+ ["unknown touch client", { userAgent: "Unknown", maxTouchPoints: 5 }, "unknown"],
+ ["missing identity", {}, "unknown"],
+ ];
+
+ it.each(clients)("classifies %s independently of native wrapper and viewport width", (_name, navigatorSignals, expected) => {
+ vi.stubGlobal("navigator", navigatorSignals);
+ for (const native of [false, true]) {
+ for (const width of [390, 1200]) {
+ vi.stubGlobal("window", { innerWidth: width, ...(native ? { __TAURI__: {} } : {}) });
+ expect(getClientPlatform()).toBe(expected);
+ }
+ }
+ });
+
+ it("returns unknown without a browser window or navigator", () => {
+ vi.stubGlobal("navigator", { userAgent: "Mozilla/5.0 (Windows NT 10.0)" });
+ vi.stubGlobal("window", undefined);
+ expect(getClientPlatform()).toBe("unknown");
+ vi.stubGlobal("window", {});
+ vi.stubGlobal("navigator", undefined);
+ expect(getClientPlatform()).toBe("unknown");
+ });
+
+ it("does not change the native-only mobile helper's meaning", () => {
+ vi.stubGlobal("window", {});
+ vi.stubGlobal("navigator", { userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS)" });
+ expect(getClientPlatform()).toBe("mobile");
+ expect(isMobile()).toBe(false);
+ });
+});
+
describe("tauriInvoke", () => {
afterEach(() => {
if ("window" in globalThis) {
diff --git a/src/web/src/components/community/channels/forum-post-list.tsx b/src/web/src/components/community/channels/forum-post-list.tsx
index cdc7dc3ec..3196be650 100644
--- a/src/web/src/components/community/channels/forum-post-list.tsx
+++ b/src/web/src/components/community/channels/forum-post-list.tsx
@@ -16,6 +16,7 @@ import { VirtualRows } from "../messages/virtual-cursor-list"
import { useInitialPositionTransition } from "../messages/initial-position-transition"
const OVERSCAN = 5
+export const FORUM_LIST_SPACING_CLASS = "px-0 py-2"
const forumRangeExtractor = (range: Range) => defaultRangeExtractor({ ...range, overscan: range.overscan + range.endIndex - range.startIndex + 1 })
type Props = {
posts: ForumThread[]
@@ -39,7 +40,7 @@ export function ForumPostList(props: Props) {
function ForumPostListEntry(props: Props) {
const [admitted, setAdmitted] = useState(false)
if (!props.loading && !admitted || props.posts.length > 0 && !admitted) setAdmitted(true)
- if (!admitted && props.loading && !props.posts.length) return <div data-testid={tid.forumPostList} aria-label="Loading forum" aria-busy="true" data-community-conversation-subtype="forum" className="flex-1 overflow-y-auto thin-scrollbar px-0 py-2 sm:px-4">{props.loadingContent}</div>
+ if (!admitted && props.loading && !props.posts.length) return <div data-testid={tid.forumPostList} aria-label="Loading forum" aria-busy="true" data-community-conversation-subtype="forum" className={`flex-1 overflow-y-auto thin-scrollbar ${FORUM_LIST_SPACING_CLASS}`}>{props.loadingContent}</div>
return <ForumPostListOwner {...props} />
}
@@ -118,7 +119,7 @@ function ForumPostListOwner({ posts, loading, observation, hasMore, loadingMore,
return <div className="relative flex min-h-0 flex-1 flex-col">
<div ref={bindScrollRoot} role="main" data-testid={tid.forumPostList} data-community-conversation-subtype="forum"
aria-busy={presentation.showSkeleton || undefined} aria-label={presentation.showSkeleton ? "Loading forum" : undefined}
- className="flex-1 overflow-y-auto thin-scrollbar [overflow-anchor:none] px-0 py-2 sm:px-4">
+ className={`flex-1 overflow-y-auto thin-scrollbar [overflow-anchor:none] ${FORUM_LIST_SPACING_CLASS}`}>
{!posts.length && loading ? <div data-message-list-content aria-hidden="true" inert data-read-position-ready="false" />
: !posts.length ? <div data-message-list-content aria-hidden="false" data-read-position-ready="true"><EmptyState icon={ListChevronsUpDown} label="No posts with this tag yet. Start one with New Post." /></div>
: <VirtualRows directDomUpdatesMode="position" items={posts} virtualizer={virtualizer} renderItem={renderPost}
@@ -126,6 +127,6 @@ function ForumPostListOwner({ posts, loading, observation, hasMore, loadingMore,
"data-read-position-ready": positionReady ? "true" : "false" }} />}
</div>
{presentation.showSkeleton && <div data-forum-positioning-skeleton aria-hidden="true"
- className="pointer-events-none absolute inset-0 overflow-hidden bg-background px-0 py-2 sm:px-4">{loadingContent}</div>}
+ className={`pointer-events-none absolute inset-0 overflow-hidden bg-background ${FORUM_LIST_SPACING_CLASS}`}>{loadingContent}</div>}
</div>
}
diff --git a/src/web/src/components/community/channels/forum-view.platform.dom.test.tsx b/src/web/src/components/community/channels/forum-view.platform.dom.test.tsx
new file mode 100644
index 000000000..6e702059a
--- /dev/null
+++ b/src/web/src/components/community/channels/forum-view.platform.dom.test.tsx
@@ -0,0 +1,65 @@
+import { afterEach, describe, expect, it, vi } from "vitest"
+import { createElement } from "react"
+import { hydrateRoot } from "react-dom/client"
+import { renderToString } from "react-dom/server"
+import { act, fireEvent, render, screen, waitFor } from "@/test/react-dom-harness"
+import type { ForumThread } from "@/lib/community/models/message"
+import { ForumView } from "./forum-view"
+
+vi.mock("@/lib/community-db/projections", () => ({ useCanonicalProfilesByUserId: () => new Map() }))
+vi.mock("./forum-post-list", () => ({
+ FORUM_LIST_SPACING_CLASS: "px-0 py-2",
+ ForumPostList: ({ posts, renderPost }: { posts: ForumThread[]; renderPost: (post: ForumThread, index: number) => React.ReactNode }) => posts.map(renderPost),
+}))
+
+const post: ForumThread = {
+ id: "p1", name: "Forum title", authorId: "author", authorAvatar: null, authorAvatarVersion: 0, messageCount: 1,
+ parent: { authorName: "Author", text: "Opener" }, tags: [], preview: "Preview",
+ participants: [], participantCount: 1, openerMessageId: "opener", lastMessageAt: "2020-01-01T00:00:00.000Z",
+}
+
+function view() {
+ return createElement(ForumView, {
+ forumChannelId: "forum", members: [], posts: [post], tag: "All",
+ onTagChange() {}, onOpenPost() {}, onEditPostTags() {}, canEditPostTags: () => true,
+ onDeletePost() {}, canDeletePost: () => true,
+ })
+}
+
+afterEach(() => vi.unstubAllGlobals())
+
+describe("Forum platform action lifecycle", () => {
+ it("hydrates visible server actions before applying the confirmed desktop policy", async () => {
+ vi.stubGlobal("navigator", { userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X)", platform: "MacIntel", maxTouchPoints: 0 })
+ const html = renderToString(view())
+ expect(html).not.toContain("group-hover/card:opacity-100")
+ const container = document.createElement("div")
+ container.innerHTML = html
+ document.body.appendChild(container)
+ const onRecoverableError = vi.fn()
+ let root: ReturnType<typeof hydrateRoot> | undefined
+ try {
+ await act(async () => { root = hydrateRoot(container, view(), { onRecoverableError }) })
+ const trigger = container.querySelector('button[aria-label="Edit tags"]')!
+ expect(trigger.parentElement!.className).toContain("group-hover/card:opacity-100")
+ expect(onRecoverableError).not.toHaveBeenCalled()
+ } finally {
+ await act(async () => root?.unmount())
+ container.remove()
+ }
+ })
+
+ it("keeps the desktop group visible while its delete confirmation is open", async () => {
+ vi.stubGlobal("navigator", { userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64)", maxTouchPoints: 10 })
+ render(view())
+ const trigger = screen.getByRole("button", { name: "Delete post" })
+ const actions = trigger.parentElement!
+ expect(actions.className).toContain("opacity-0")
+ fireEvent.click(trigger)
+ expect(await screen.findByRole("dialog", { name: "Delete post?" })).toBeInTheDocument()
+ expect(actions.className.split(" ")).toContain("opacity-100")
+ expect(actions.className.split(" ")).not.toContain("opacity-0")
+ fireEvent.click(screen.getByRole("button", { name: "Cancel" }))
+ await waitFor(() => expect(actions.className.split(" ")).toContain("opacity-0"))
+ })
+})
diff --git a/src/web/src/components/community/channels/forum-view.test.ts b/src/web/src/components/community/channels/forum-view.test.ts
index 01944e0f3..cf8153aa1 100644
--- a/src/web/src/components/community/channels/forum-view.test.ts
+++ b/src/web/src/components/community/channels/forum-view.test.ts
@@ -1,4 +1,4 @@
-import { describe, it, expect, vi } from "vitest"
+import { beforeEach, describe, it, expect, vi } from "vitest"
import { readFileSync } from "node:fs"
import { createElement } from "react"
import { renderToStaticMarkup } from "react-dom/server"
@@ -13,6 +13,16 @@ import { tid } from "@/lib/community/testids"
import type { ForumThread } from "@/lib/community/models/message"
const profileState = vi.hoisted(() => ({ map: new Map<string, Record<string, unknown>>() }))
+const platformState = vi.hoisted(() => ({ hydrated: false, platform: "unknown" as "unknown" | "desktop" | "mobile" }))
+vi.mock("@/hooks/use-hydrated-client", () => ({ useHydratedClient: () => platformState.hydrated }))
+vi.mock("@alook/shared", async (importOriginal) => ({
+ ...await importOriginal<typeof import("@alook/shared")>(),
+ getClientPlatform: () => platformState.platform,
+}))
+beforeEach(() => {
+ platformState.hydrated = false
+ platformState.platform = "unknown"
+})
vi.mock("@/lib/community-db/projections", () => ({
useCanonicalProfilesByUserId: () => profileState.map,
}))
@@ -271,8 +281,10 @@ describe("ForumView post delete button", () => {
})
})
-describe("ForumView responsive post actions", () => {
- it("orders tag, archive, and delete actions with responsive geometry", () => {
+describe("ForumView platform post actions", () => {
+ it("orders tag, archive, and delete actions with desktop group reveal and stable geometry", () => {
+ platformState.hydrated = true
+ platformState.platform = "desktop"
const html = renderWithActions(makePost({ parentSeq: 3 }))
const tagIndex = html.indexOf(tid.forumThreadTagBtn("p1"))
const archiveIndex = html.indexOf(tid.forumThreadArchiveBtn("p1"))
@@ -285,14 +297,11 @@ describe("ForumView responsive post actions", () => {
expect(archiveIndex).toBeLessThan(deleteIndex)
for (const button of [tagButton, archiveButton, deleteButton]) {
expect(button).toContain("size-8")
- expect(button).toContain("opacity-100")
expect(button).not.toContain("sm:size-")
- expect(button).toContain("sm:opacity-0")
- expect(button).toContain("sm:group-focus-within/card:opacity-100")
+ expect(button).not.toContain("sm:opacity-0")
expect(button).not.toContain("transition-opacity")
- expect(button).toContain("sm:group-hover/card:opacity-100")
}
- expect(tagButton).toContain("sm:data-popup-open:opacity-100")
+ expect(html).toContain("opacity-0 group-focus-within/card:opacity-100 group-hover/card:opacity-100 has-data-popup-open:opacity-100")
expect(archiveButton).toContain('aria-label="Archive post"')
expect(archiveButton).toContain('aria-pressed="false"')
expect(archiveButton).toContain("disabled:opacity-50")
@@ -300,7 +309,7 @@ describe("ForumView responsive post actions", () => {
expect(html).toContain("grid-cols-[minmax(0,1fr)_auto]")
expect(html).not.toContain("row-span-2")
expect(html).toContain("col-span-full row-start-2")
- expect(html).not.toContain("min-h-8")
+ expect(html).toContain("grid-rows-[minmax(2rem,max-content)_auto]")
expect(html).toContain("w-full min-w-0 max-w-full self-center text-[15px] font-semibold leading-tight")
expect(html).toContain(tid.forumThreadTitle("p1"))
expect(html).toContain(tid.forumThreadTitleText("p1"))
@@ -326,13 +335,13 @@ describe("ForumView responsive post actions", () => {
.toEqual(["bug", "design"])
})
- it("does not render actions or reserve mobile header space without permission", () => {
+ it("does not render actions or reserve an empty action column without permission", () => {
const html = renderWithActions(makePost(), { canEdit: false, canDelete: false })
expect(html).not.toContain(tid.forumThreadTagBtn("p1"))
expect(html).not.toContain(tid.forumThreadArchiveBtn("p1"))
expect(html).not.toContain(tid.forumThreadDeleteBtn("p1"))
- expect(html).not.toContain("min-h-8")
+ expect(html).toContain("grid-rows-[minmax(2rem,max-content)_auto]")
expect(html).toContain("grid-cols-1")
expect(html).not.toContain("grid-cols-[minmax(0,1fr)_auto]")
})
@@ -344,7 +353,32 @@ describe("ForumView responsive post actions", () => {
expect(html).not.toContain(tid.forumThreadArchiveBtn("p1"))
expect(html).toContain(tid.forumThreadDeleteBtn("p1"))
expect(html).toContain("grid-cols-[minmax(0,1fr)_auto]")
- expect(html).not.toContain("min-h-8")
+ expect(html).toContain("grid-rows-[minmax(2rem,max-content)_auto]")
+ })
+
+ it.each([
+ [false, "desktop"],
+ [true, "unknown"],
+ [true, "mobile"],
+ ] as const)("keeps actions visible for hydration=%s platform=%s", (hydrated, platform) => {
+ platformState.hydrated = hydrated
+ platformState.platform = platform
+ const html = renderWithActions(makePost())
+ expect(html).toContain(tid.forumThreadTagBtn("p1"))
+ expect(html).not.toContain("group-hover/card:opacity-100")
+ expect(html).not.toContain("opacity-0")
+ })
+
+ it.each([
+ [false, false, 0],
+ [false, true, 1],
+ [true, false, 2],
+ [true, true, 3],
+ ] as const)("keeps the first title track at least 32px for edit=%s delete=%s (%s actions)", (canEdit, canDelete, count) => {
+ const html = renderWithActions(makePost(), { canEdit, canDelete })
+ expect(html).toContain("grid-rows-[minmax(2rem,max-content)_auto]")
+ expect(html.match(/aria-label="(?:Edit tags|Archive post|Delete post)"/g) ?? []).toHaveLength(count)
+ expect(html).toContain(count ? "grid-cols-[minmax(0,1fr)_auto]" : "grid-cols-1")
})
})
@@ -395,7 +429,7 @@ describe("ForumView filter bar / composer swap", () => {
expect(html).not.toContain(tid.forumTagFadeLeft)
expect(html).not.toContain(tid.forumTagFadeRight)
expect(listMarkup).toContain("px-0")
- expect(listMarkup).toContain("sm:px-4")
+ expect(listMarkup).not.toContain("sm:px-4")
})
it("keeps the tag rail scrollable without a cross-browser scrollbar gutter", () => {
@@ -450,7 +484,20 @@ describe("ForumView filter bar / composer swap", () => {
expect(html).not.toContain("sm:overflow-x-visible")
expect(html.match(/rounded-lg/g)).toHaveLength(4)
expect(html).toContain("pointer-events-none")
- expect(html).toContain("px-0 py-2 sm:px-4")
+ expect(html).toContain("px-0 py-2")
+ expect(html).not.toContain("sm:px-4")
+ expect(html.match(/min-h-8/g)).toHaveLength(3)
+ })
+
+ it("keeps the selected filter ring inside the chip without changing All", () => {
+ const html = renderWithAvailableTags([makePost()], ["bug"], "bug")
+ const chip = html.match(new RegExp(`<button[^>]*data-testid="${tid.forumTagChip("bug")}"[^>]*>`))?.[0]
+ expect(chip).toContain("ring-1 ring-inset ring-current/20")
+ expect(chip).not.toContain("h-")
+ const all = renderWithAvailableTags([makePost()], ["bug"])
+ .match(new RegExp(`<button[^>]*data-testid="${tid.forumTagAll}"[^>]*>`))?.[0]
+ expect(all).toContain("bg-accent text-foreground")
+ expect(all).not.toContain("ring-inset")
})
})
diff --git a/src/web/src/components/community/channels/forum-view.tsx b/src/web/src/components/community/channels/forum-view.tsx
index 1bec1f969..5a2989304 100644
--- a/src/web/src/components/community/channels/forum-view.tsx
+++ b/src/web/src/components/community/channels/forum-view.tsx
@@ -19,8 +19,9 @@ import type { ForumThread } from "@/lib/community/models/message"
import type { Member } from "@/lib/community/models/people"
import { tagColorClassName, tagColorStyle } from "@/lib/community/tag-color"
import { cn } from "@/lib/utils"
-import { FORUM_ARCHIVE_TAG } from "@alook/shared"
-import { ForumPostList } from "./forum-post-list"
+import { FORUM_ARCHIVE_TAG, getClientPlatform } from "@alook/shared"
+import { FORUM_LIST_SPACING_CLASS, ForumPostList } from "./forum-post-list"
+import { useHydratedClient } from "@/hooks/use-hydrated-client"
import type { ConversationListScope } from "@/lib/community/conversation-qualification"
import { useCanonicalProfilesByUserId } from "@/lib/community-db/projections"
import { readCommunityProfile } from "@/lib/community/profile-read"
@@ -32,7 +33,8 @@ import {
const MAX_AVATARS = 5
const MAX_VISIBLE_TAGS = 2
-const POST_ACTION_CLASS = "grid size-8 shrink-0 place-items-center rounded-md text-muted-foreground opacity-100 sm:opacity-0 sm:group-focus-within/card:opacity-100 sm:group-hover/card:opacity-100 sm:data-popup-open:opacity-100 disabled:cursor-not-allowed disabled:opacity-50"
+const POST_ACTION_CLASS = "grid size-8 shrink-0 place-items-center rounded-md text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50"
+const POST_ROW_CLASS = "border-b border-border/50 px-4 py-4"
export function shouldActivateForumRow(event: {
key: string
@@ -52,7 +54,7 @@ function ForumTagSummary({ tags }: { tags: string[] }) {
return (
<div
- className="flex min-w-0 items-center gap-1.5 max-sm:order-last max-sm:basis-full max-sm:pl-7"
+ className="flex min-w-0 items-center gap-2 max-sm:order-last max-sm:basis-full max-sm:pl-7"
onClick={(event) => event.stopPropagation()}
onKeyDown={(event) => event.stopPropagation()}
>
@@ -74,7 +76,7 @@ function ForumTagSummary({ tags }: { tags: string[] }) {
<PopoverContent
side="top"
align="start"
- className="flex w-52 flex-wrap gap-1.5 p-2"
+ className="flex w-52 flex-wrap gap-2 p-2"
onClick={(event) => event.stopPropagation()}
>
{ordinaryTags.map((tag) => (
@@ -166,6 +168,11 @@ export function ForumView({
deletingPost?: string | null
onScrollRoot?: (node: HTMLDivElement | null) => void
}) {
+ const desktopActions = useHydratedClient() && getClientPlatform() === "desktop"
+ const postActionsClassName = cn(
+ "col-start-2 row-start-1 z-10 flex self-center items-center gap-1",
+ desktopActions && "opacity-0 group-focus-within/card:opacity-100 group-hover/card:opacity-100 has-data-popup-open:opacity-100",
+ )
const profilesByUserId = useCanonicalProfilesByUserId()
const [composing, setComposing] = useAtom(useCreateAtom(false))
const [deletingForId, setDeletingForId] = useAtom(useCreateAtom<string | null>(null))
@@ -260,7 +267,7 @@ export function ForumView({
className={cn(
"shrink-0 rounded-lg px-2.75 py-1 text-[13px] leading-5 transition-opacity",
tagColorClassName,
- tag === t ? "opacity-100 ring-1 ring-current/20" : "opacity-70 hover:opacity-100",
+ tag === t ? "opacity-100 ring-1 ring-inset ring-current/20" : "opacity-70 hover:opacity-100",
)}
data-testid={tid.forumTagChip(t)}
onClick={() => onTagChange(t)}
@@ -319,15 +326,16 @@ export function ForumView({
onOpenPost(p.id)
}}
className={cn(
- "group/card relative cursor-pointer rounded border-b border-border/50 px-4.5 py-3.5 text-left transition-colors hover:bg-accent/45",
+ "group/card relative cursor-pointer rounded text-left transition-colors hover:bg-accent/45",
+ POST_ROW_CLASS,
index === posts.length - 1 && "border-b-0",
)}
>
- <div className={cn("grid grid-rows-[max-content_auto] gap-x-2", actionCount > 0 ? "grid-cols-[minmax(0,1fr)_auto]" : "grid-cols-1")}>
+ <div className={cn("grid grid-rows-[minmax(2rem,max-content)_auto] gap-x-2", actionCount > 0 ? "grid-cols-[minmax(0,1fr)_auto]" : "grid-cols-1")}>
<ForumPostTitle name={p.name} postId={p.id} seq={p.parentSeq} />
{(canEdit || canDelete) && (
<div
- className="col-start-2 row-start-1 z-10 flex self-center items-center gap-1"
+ className={cn(postActionsClassName, deletingForId === p.id && "opacity-100")}
onClick={(event) => event.stopPropagation()}
onKeyDown={(event) => event.stopPropagation()}
>
@@ -386,9 +394,9 @@ export function ForumView({
</div>
)}
- <p data-slot="community-forum-post-preview" className="col-span-full row-start-2 mb-2.25 mt-0.75 line-clamp-2 text-[13.5px] text-muted-foreground">{p.preview}</p>
+ <p data-slot="community-forum-post-preview" className="col-span-full row-start-2 my-2 line-clamp-2 text-[13.5px] text-muted-foreground">{p.preview}</p>
</div>
- <div className="flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1.5 text-xs text-muted-foreground">
+ <div className="flex min-w-0 flex-wrap items-center gap-2 text-xs text-muted-foreground">
<Avatar label={author.avatar} seed={p.authorId} size={20} />
<span className="shrink-0 font-medium text-foreground" suppressHydrationWarning>{author.name}</span>
<span className="shrink-0" aria-hidden>·</span>
@@ -443,10 +451,10 @@ function ForumPostSkeleton({ postId, last = false }: { postId?: string; last?: b
data-testid={postId === undefined ? undefined : tid.forumThreadCard(postId)}
aria-busy="true"
aria-label="Loading post"
- className={cn("flex flex-col border-b border-border/50 px-4.5 py-3.5", last && "border-b-0")}
+ className={cn("flex flex-col", POST_ROW_CLASS, last && "border-b-0")}
>
- <Skeleton className="h-4 w-2/3 rounded" />
- <div className="mb-2.25 mt-1.25 space-y-1.5">
+ <div className="flex min-h-8 items-center"><Skeleton className="h-4 w-2/3 rounded" /></div>
+ <div className="my-2 space-y-2">
<Skeleton className="h-3 w-full rounded" />
<Skeleton className="h-3 w-4/5 rounded" />
</div>
@@ -493,7 +501,7 @@ export function ForumViewSkeleton() {
<Skeleton className="h-8 w-25 rounded-md" />
</div>
</div>
- <main className="flex-1 overflow-y-auto thin-scrollbar px-0 py-2 sm:px-4">
+ <main className={`flex-1 overflow-y-auto thin-scrollbar ${FORUM_LIST_SPACING_CLASS}`}>
<ForumListSkeleton />
</main>
</>
diff --git a/src/web/src/components/ui/confirm-dialog.tsx b/src/web/src/components/ui/confirm-dialog.tsx
index f2d4f59d2..6087cb153 100644
--- a/src/web/src/components/ui/confirm-dialog.tsx
+++ b/src/web/src/components/ui/confirm-dialog.tsx
@@ -38,7 +38,7 @@ export function ConfirmDialog({
<DialogContent showCloseButton={false}>
<DialogHeader>
<DialogTitle>{title}</DialogTitle>
- <DialogDescription>{description}</DialogDescription>
+ <DialogDescription className="wrap-anywhere">{description}</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button
diff --git a/src/web/src/test/e2e-ui/26-mobile-forum-post-actions.spec.ts b/src/web/src/test/e2e-ui/26-mobile-forum-post-actions.spec.ts
index bd22bcf88..74580de3b 100644
--- a/src/web/src/test/e2e-ui/26-mobile-forum-post-actions.spec.ts
+++ b/src/web/src/test/e2e-ui/26-mobile-forum-post-actions.spec.ts
@@ -1,5 +1,6 @@
import { communityFixtureFetch } from "./_fixtures/business-contract"
import type { Locator, Page, TestInfo } from "@playwright/test"
+import { devices } from "@playwright/test"
import { test, expect } from "./_fixtures/case-fixture"
import { gotoAfterUserWsAuth } from "./_fixtures/actions"
@@ -34,7 +35,7 @@ async function prepareCase(actors: CaseActors) {
return { seedTags }
}
-const MOBILE_WIDTHS = [320, 390] as const
+const NARROW_WIDTHS = [320, 390] as const
const FILTER_RAIL_WIDTHS = [320, 390, 1280] as const
const ACTION_WIDTHS = [639, 640, 641, 1280] as const
const TAGS = ["alpha-long-tag", "beta-long-tag", "gamma", "delta", "epsilon"]
@@ -191,7 +192,7 @@ function observeClientWrites(page: Page) {
return state
}
-async function expectMobileGeometry(
+async function expectNarrowGeometry(
page: Page,
card: Locator,
postId: string,
@@ -199,12 +200,14 @@ async function expectMobileGeometry(
expectedTitle: string,
titleState: "single" | "truncated",
role: "author" | "manager",
- width: (typeof MOBILE_WIDTHS)[number],
+ width: (typeof NARROW_WIDTHS)[number],
twoLinePreview = false,
): Promise<void> {
await page.setViewportSize({ width, height: 844 })
const tagButton = page.getByTestId(tid.forumThreadTagBtn(postId))
const deleteButton = page.getByTestId(tid.forumThreadDeleteBtn(postId))
+ await card.hover()
+ await expect(tagButton.locator("..")).toHaveCSS("opacity", "1")
await expect(tagButton).toHaveCSS("opacity", "1")
await expect(deleteButton).toHaveCSS("opacity", "1")
@@ -238,7 +241,8 @@ async function expectMobileGeometry(
}
expect(Math.abs(cardRect!.left - listRect!.left), `${role}/${postId}@${width}: edge-to-edge left`).toBeLessThanOrEqual(0.5)
expect(Math.abs(cardRect!.right - listRect!.right), `${role}/${postId}@${width}: edge-to-edge right`).toBeLessThanOrEqual(0.5)
- expect(titleRect!.left - cardRect!.left, `${role}/${postId}@${width}: internal title inset`).toBeGreaterThanOrEqual(16)
+ expect(Math.abs(titleRect!.left - cardRect!.left - 16), `${role}/${postId}@${width}: internal title inset`).toBeLessThanOrEqual(0.5)
+ expect(Math.abs(cardRect!.right - deleteRect!.right - 16), `${role}/${postId}@${width}: internal action inset`).toBeLessThanOrEqual(0.5)
const titleMetrics = await titleText.evaluate((element) => {
const range = document.createRange()
range.selectNodeContents(element)
@@ -572,7 +576,7 @@ test("forum post actions stay discoverable on mobile without changing permission
const route = `/c/channels/${serverId}/${forumId}`
const compactRoute = `/c/channels/${serverId}/${compactForumId}`
- const author = await asUser("bob")
+ const author = await asUser("bob", { ...devices["iPhone 13"] })
await author.page.setViewportSize({ width: 1280, height: 900 })
await gotoAfterUserWsAuth(author.page, route)
const authorCard = author.page.getByTestId(tid.forumThreadCard(primaryPostId))
@@ -585,9 +589,9 @@ test("forum post actions stay discoverable on mobile without changing permission
for (const width of FILTER_RAIL_WIDTHS) {
newPostGeometry.set(width, await expectFilterRail(author.page, width, testInfo))
}
- for (const width of MOBILE_WIDTHS) {
+ for (const width of NARROW_WIDTHS) {
for (const post of postCases) {
- await expectMobileGeometry(
+ await expectNarrowGeometry(
author.page,
author.page.getByTestId(tid.forumThreadCard(post.id)),
post.id,
@@ -604,6 +608,22 @@ test("forum post actions stay discoverable on mobile without changing permission
contentType: "image/png",
})
}
+ const authorTagButton = author.page.getByTestId(tid.forumThreadTagBtn(primaryPostId))
+ const authorActions = authorTagButton.locator("..")
+ for (const width of ACTION_WIDTHS) {
+ await author.page.setViewportSize({ width, height: 900 })
+ await authorCard.scrollIntoViewIfNeeded()
+ await author.page.mouse.move(0, 0)
+ await authorTagButton.evaluate(button => button.blur())
+ await expect(authorActions, `mobile browser actions stay visible@${width}`).toHaveCSS("opacity", "1")
+ for (const button of [authorTagButton, author.page.getByTestId(tid.forumThreadArchiveBtn(primaryPostId)), author.page.getByTestId(tid.forumThreadDeleteBtn(primaryPostId))]) {
+ await expect(button).toBeEnabled()
+ await expect(button).toHaveCSS("opacity", "1")
+ const bounds = await rect(button)
+ expect(bounds?.width, `mobile browser action width@${width}`).toBe(32)
+ expect(bounds?.height, `mobile browser action height@${width}`).toBe(32)
+ }
+ }
authorWrites.active = false
for (const width of FILTER_RAIL_WIDTHS) {
const expectedNewPost = newPostGeometry.get(width)
@@ -627,15 +647,15 @@ test("forum post actions stay discoverable on mobile without changing permission
expect(authorWrites.http).toEqual([])
expect(authorWrites.ws).toEqual([])
- const manager = await asUser("alice")
+ const manager = await asUser("alice", { ...devices["Desktop Chrome"] })
const managerWrites = observeClientWrites(manager.page)
await gotoAfterUserWsAuth(manager.page, route)
const managerCard = manager.page.getByTestId(tid.forumThreadCard(primaryPostId))
await expect(managerCard).toBeVisible({ timeout: 20_000 })
managerWrites.active = true
- for (const width of MOBILE_WIDTHS) {
+ for (const width of NARROW_WIDTHS) {
for (const post of postCases) {
- await expectMobileGeometry(
+ await expectNarrowGeometry(
manager.page,
manager.page.getByTestId(tid.forumThreadCard(post.id)),
post.id,
@@ -653,18 +673,20 @@ test("forum post actions stay discoverable on mobile without changing permission
})
}
await manager.page.setViewportSize({ width: 1280, height: 900 })
- const [desktopListRect, desktopCardRect] = await Promise.all([
+ const [desktopListRect, desktopCardRect, desktopTitleRect] = await Promise.all([
rect(manager.page.getByTestId(tid.forumPostList)),
rect(managerCard),
+ rect(manager.page.getByTestId(tid.forumThreadTitle(primaryPostId))),
])
- expect(desktopCardRect!.left - desktopListRect!.left).toBeGreaterThanOrEqual(15)
- expect(desktopListRect!.right - desktopCardRect!.right).toBeGreaterThanOrEqual(15)
+ expect(Math.abs(desktopCardRect!.left - desktopListRect!.left), "desktop edge-to-edge left").toBeLessThanOrEqual(0.5)
+ expect(Math.abs(desktopListRect!.right - desktopCardRect!.right), "desktop edge-to-edge right").toBeLessThanOrEqual(0.5)
+ expect(Math.abs(desktopTitleRect!.left - desktopCardRect!.left - 16), "desktop internal title inset").toBeLessThanOrEqual(0.5)
await manager.page.mouse.move(0, 0)
const managerTagButton = manager.page.getByTestId(tid.forumThreadTagBtn(primaryPostId))
const managerDeleteButton = manager.page.getByTestId(tid.forumThreadDeleteBtn(primaryPostId))
const managerArchiveButton = manager.page.getByTestId(tid.forumThreadArchiveBtn(primaryPostId))
- await expect(managerTagButton).toHaveCSS("opacity", "0")
- await expect(managerDeleteButton).toHaveCSS("opacity", "0")
+ const managerActions = managerTagButton.locator("..")
+ await expect(managerActions).toHaveCSS("opacity", "0")
for (const button of [managerTagButton, managerDeleteButton]) {
const buttonRect = await rect(button)
expect(buttonRect?.width).toBe(32)
@@ -675,10 +697,12 @@ test("forum post actions stay discoverable on mobile without changing permission
await managerTagButton.evaluate((button) => button.blur())
await manager.page.mouse.move(0, 0)
await managerCard.scrollIntoViewIfNeeded()
+ await expect(managerActions, `desktop browser actions hidden at rest@${width}`).toHaveCSS("opacity", "0")
const titleRect = await rect(manager.page.getByTestId(tid.forumThreadTitle(primaryPostId)))
expect(titleRect, `title geometry@${width}`).not.toBeNull()
for (const button of [managerTagButton, managerArchiveButton, managerDeleteButton]) {
- await expect(button).toHaveCSS("opacity", width < 640 ? "1" : "0")
+ await expect(button).toBeEnabled()
+ await expect(button).toHaveCSS("opacity", "1")
const buttonRect = await rect(button)
expect(buttonRect?.width, `action width@${width}`).toBe(32)
expect(buttonRect?.height, `action height@${width}`).toBe(32)
@@ -686,13 +710,15 @@ test("forum post actions stay discoverable on mobile without changing permission
`title/action vertical centers@${width}`).toBeLessThanOrEqual(0.5)
}
const baseline = await postActionGeometry(managerCard, primaryPostId)
+ const actionsRect = await rect(managerActions)
+ expect(Math.abs(baseline.card.right - actionsRect!.right - 16), `desktop internal action inset@${width}`).toBeLessThanOrEqual(0.5)
await managerCard.hover()
- await expect(managerTagButton).toHaveCSS("opacity", "1")
+ await expect(managerActions).toHaveCSS("opacity", "1")
const hover = await postActionGeometry(managerCard, primaryPostId)
expect(hover, `hover geometry@${width}`).toEqual(baseline)
await manager.page.mouse.move(0, 0)
await managerTagButton.focus()
- await expect(managerTagButton).toHaveCSS("opacity", "1")
+ await expect(managerActions).toHaveCSS("opacity", "1")
const focus = await postActionGeometry(managerCard, primaryPostId)
expect(focus, `focus geometry@${width}`).toEqual(baseline)
await testInfo.attach(`manager-actions-${width}.json`, {
@@ -702,16 +728,19 @@ test("forum post actions stay discoverable on mobile without changing permission
}
await managerTagButton.evaluate((button) => button.blur())
await managerCard.hover()
- await expect(managerTagButton).toHaveCSS("opacity", "1")
+ await expect(managerActions).toHaveCSS("opacity", "1")
await expect(managerDeleteButton).toHaveCSS("opacity", "1")
await manager.page.mouse.move(0, 0)
await managerTagButton.focus()
- await expect(managerTagButton).toHaveCSS("opacity", "1")
+ await expect(managerActions).toHaveCSS("opacity", "1")
await managerTagButton.click()
const managerTagDialog = manager.page.getByTestId(tid.forumTagDialog)
await expect(managerTagDialog).toBeVisible()
await manager.page.mouse.move(0, 0)
- await expect(managerTagButton).toHaveCSS("opacity", "1")
+ const selectedPopupTag = managerTagDialog.getByTestId(tid.forumTagDialogChip(TAGS[0]))
+ await selectedPopupTag.focus()
+ await expect(selectedPopupTag).toBeFocused()
+ await expect(managerActions).toHaveCSS("opacity", "1")
await expect(managerTagDialog).toHaveCSS("opacity", "1")
await testInfo.attach("manager-desktop-popup.png", {
body: await manager.page.screenshot(),
@@ -720,7 +749,54 @@ test("forum post actions stay discoverable on mobile without changing permission
await manager.page.keyboard.press("Escape")
await expect(managerTagDialog).toHaveCount(0)
await managerDeleteButton.focus()
- await expect(managerDeleteButton).toHaveCSS("opacity", "1")
+ await expect(managerActions).toHaveCSS("opacity", "1")
+ await managerDeleteButton.click()
+ const deleteDialog = manager.page.getByRole("dialog", { name: "Delete post?" })
+ await expect(deleteDialog).toBeVisible()
+ await deleteDialog.getByRole("button", { name: "Cancel" }).focus()
+ await manager.page.mouse.move(0, 0)
+ await expect(managerActions).toHaveCSS("opacity", "1")
+ await expect(deleteDialog.locator('[data-slot="dialog-description"]')).toHaveText(
+ `This permanently deletes “${primaryTitle}” and all of its replies. This can't be undone.`,
+ )
+ const deleteGeometry = await deleteDialog.evaluate(dialog => {
+ const bounds = (element: Element) => {
+ const box = element.getBoundingClientRect()
+ return { left: box.left, right: box.right, top: box.top, bottom: box.bottom }
+ }
+ const description = dialog.querySelector<HTMLElement>('[data-slot="dialog-description"]')
+ if (!description) throw new Error("The full delete description is required")
+ return {
+ viewport: { width: window.innerWidth, height: window.innerHeight },
+ popup: bounds(dialog),
+ description: { clientWidth: description.clientWidth, scrollWidth: description.scrollWidth },
+ buttons: Array.from(dialog.querySelectorAll("button")).map(button => {
+ const box = bounds(button)
+ const target = document.elementFromPoint((box.left + box.right) / 2, (box.top + box.bottom) / 2)
+ return { name: button.textContent?.trim(), bounds: box, centerHit: target?.closest("button") === button }
+ }),
+ }
+ })
+ await testInfo.attach("manager-delete-dialog.json", {
+ body: JSON.stringify(deleteGeometry),
+ contentType: "application/json",
+ })
+ expect(deleteGeometry.popup.left).toBeGreaterThanOrEqual(-0.5)
+ expect(deleteGeometry.popup.top).toBeGreaterThanOrEqual(-0.5)
+ expect(deleteGeometry.popup.right).toBeLessThanOrEqual(deleteGeometry.viewport.width + 0.5)
+ expect(deleteGeometry.popup.bottom).toBeLessThanOrEqual(deleteGeometry.viewport.height + 0.5)
+ expect(deleteGeometry.description.scrollWidth).toBeLessThanOrEqual(deleteGeometry.description.clientWidth + 1)
+ expect(deleteGeometry.buttons.map(button => button.name)).toEqual(["Cancel", "Delete post"])
+ for (const button of deleteGeometry.buttons) {
+ expect(button.bounds.left, `${button.name}: inside popup left`).toBeGreaterThanOrEqual(deleteGeometry.popup.left - 0.5)
+ expect(button.bounds.right, `${button.name}: inside popup right`).toBeLessThanOrEqual(deleteGeometry.popup.right + 0.5)
+ expect(button.bounds.top, `${button.name}: inside popup top`).toBeGreaterThanOrEqual(deleteGeometry.popup.top - 0.5)
+ expect(button.bounds.bottom, `${button.name}: inside popup bottom`).toBeLessThanOrEqual(deleteGeometry.popup.bottom + 0.5)
+ expect(button.centerHit, `${button.name}: pointer center hit`).toBe(true)
+ }
+ await deleteDialog.getByRole("button", { name: "Cancel" }).click()
+ await expect(deleteDialog).toHaveCount(0)
+ await expect(managerActions).toHaveCSS("opacity", "1")
managerWrites.active = false
expect(managerWrites.http).toEqual([])
expect(managerWrites.ws).toEqual([])
@@ -736,11 +812,13 @@ test("forum post actions stay discoverable on mobile without changing permission
await expect(unauthorizedCard).toBeVisible({ timeout: 20_000 })
for (const post of postCases) {
await expect(unauthorized.page.getByTestId(tid.forumThreadTagBtn(post.id))).toHaveCount(0)
+ await expect(unauthorized.page.getByTestId(tid.forumThreadArchiveBtn(post.id))).toHaveCount(0)
await expect(unauthorized.page.getByTestId(tid.forumThreadDeleteBtn(post.id))).toHaveCount(0)
}
await unauthorized.page.setViewportSize({ width: 320, height: 844 })
for (const post of postCases) {
await expect(unauthorized.page.getByTestId(tid.forumThreadTagBtn(post.id))).toHaveCount(0)
+ await expect(unauthorized.page.getByTestId(tid.forumThreadArchiveBtn(post.id))).toHaveCount(0)
await expect(unauthorized.page.getByTestId(tid.forumThreadDeleteBtn(post.id))).toHaveCount(0)
}
await testInfo.attach("unauthorized-320.png", {