Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): preserve forum card layout and action readiness (#1107)

Generee8520890e6b
diff --git a/src/web/src/components/community/channels/forum-channel-surface.dom.test.ts b/src/web/src/components/community/channels/forum-channel-surface.dom.test.ts
index 6bf8ef992..f0cd5311f 100644
--- a/src/web/src/components/community/channels/forum-channel-surface.dom.test.ts
+++ b/src/web/src/components/community/channels/forum-channel-surface.dom.test.ts
@@ -164,6 +164,32 @@ describe("ForumChannelSurface ownership", () => {
expect(renderer!.container.querySelector('[data-manage-dialog="true"]')).toBeInTheDocument()
})
+ it("keeps other-post permission pending until the qualified viewer role resolves", () => {
+ const node = (viewerRole: "admin" | "member" | undefined) => React.createElement(
+ ForumChannelSurface, surfaceProps({ viewerRole }),
+ )
+ const view = render(node(undefined))
+ const pending = mockedForumSurface.mock.calls.at(-1)![0]
+ const ownPost = { id: "own", authorId: "viewer_1", openerMessageId: "own-opener", tags: [] } as Parameters<NonNullable<typeof pending.canEditPostTags>>[0]
+ const otherPost = { ...ownPost, id: "other", authorId: "other_1" }
+ expect(pending.canEditPostTags?.(ownPost)).toBe(true)
+ expect(pending.canDeletePost?.(ownPost)).toBe(true)
+ expect(pending.canEditPostTags?.(otherPost)).toBeUndefined()
+ expect(pending.canDeletePost?.(otherPost)).toBeUndefined()
+ view.rerender(node("member"))
+ const denied = mockedForumSurface.mock.calls.at(-1)![0]
+ expect(denied.canEditPostTags?.(otherPost)).toBe(false)
+ expect(denied.canDeletePost?.(otherPost)).toBe(false)
+ view.rerender(node("admin"))
+ const allowed = mockedForumSurface.mock.calls.at(-1)![0]
+ expect(allowed.canEditPostTags?.(otherPost)).toBe(true)
+ expect(allowed.canDeletePost?.(otherPost)).toBe(true)
+ view.rerender(node(undefined))
+ const retired = mockedForumSurface.mock.calls.at(-1)![0]
+ expect(retired.canEditPostTags?.(otherPost)).toBeUndefined()
+ expect(retired.canDeletePost?.(otherPost)).toBeUndefined()
+ })
+
it("allows server managers to edit and delete other authors' posts", () => {
act(() => {
render(React.createElement(ForumChannelSurface, surfaceProps({ viewerRole: "admin" })))
diff --git a/src/web/src/components/community/channels/forum-channel-surface.tsx b/src/web/src/components/community/channels/forum-channel-surface.tsx
index e06eb191e..2882d3472 100644
--- a/src/web/src/components/community/channels/forum-channel-surface.tsx
+++ b/src/web/src/components/community/channels/forum-channel-surface.tsx
@@ -125,7 +125,7 @@ export function ForumChannelSurface({
mentionCandidates={composerMentionCandidates}
onOpenPost={onOpenPost}
onCreatePost={createForumThread}
- canEditPostTags={(post) => canManage || post.authorId === viewer.id}
+ canEditPostTags={(post) => post.authorId === viewer.id ? true : viewerRole === undefined ? undefined : canManage}
savingTagsFor={updatePostTagsMut.isPending ? updatePostTagsMut.variables?.threadId ?? null : null}
onEditPostTags={async (post, tags) => {
const assertActive = source.capture()
@@ -142,7 +142,7 @@ export function ForumChannelSurface({
{ onError: (error) => toastApiError(error, "Failed to update tags", assertActive) },
)
}}
- canDeletePost={(post) => canManage || post.authorId === viewer.id}
+ canDeletePost={(post) => post.authorId === viewer.id ? true : viewerRole === undefined ? undefined : canManage}
deletingPost={deleteForumThreadMut.isPending ? deleteForumThreadMut.variables?.threadId ?? null : null}
onDeletePost={(post) => {
const assertActive = source.capture()
diff --git a/src/web/src/components/community/channels/forum-surface.tsx b/src/web/src/components/community/channels/forum-surface.tsx
index 182a9244f..218dac62e 100644
--- a/src/web/src/components/community/channels/forum-surface.tsx
+++ b/src/web/src/components/community/channels/forum-surface.tsx
@@ -25,10 +25,10 @@ export function ForumSurface({ serverId, forumChannelId, routeTag, onSelectTag,
onOpenPost: (id: string) => void
onCreatePost?: (post: NewForumThread) => Promise<void>
onEditPostTags?: (post: ForumThread, tags: string[]) => Promise<void> | void
- canEditPostTags?: (post: ForumThread) => boolean
+ canEditPostTags?: (post: ForumThread) => boolean | undefined
savingTagsFor?: string | null
onDeletePost?: (post: ForumThread) => void
- canDeletePost?: (post: ForumThread) => boolean
+ canDeletePost?: (post: ForumThread) => boolean | undefined
deletingPost?: string | null
}) {
const feed = useForumFeed(serverId, forumChannelId, { routeTag, onSelectTag })
diff --git a/src/web/src/components/community/channels/forum-view.native-layout.dom.test.tsx b/src/web/src/components/community/channels/forum-view.native-layout.dom.test.tsx
index 4be25d252..4675c8972 100644
--- a/src/web/src/components/community/channels/forum-view.native-layout.dom.test.tsx
+++ b/src/web/src/components/community/channels/forum-view.native-layout.dom.test.tsx
@@ -78,6 +78,54 @@ it.each([{ kind: "short", name: "Short title" }, { kind: "long", name: "Long tit
expect(remove).not.toHaveBeenCalled()
})
+it("reveals each card only after its own action decisions settle", () => {
+ const cards = posts.slice(0, 3)
+ const decisions = new Map<string, boolean | undefined>([[cards[0].id, true], [cards[1].id, undefined], [cards[2].id, undefined]])
+ const open = vi.fn()
+ const edit = vi.fn()
+ const permission = (post: ForumThread) => decisions.get(post.id)
+ const node = () => createElement(ForumView, {
+ forumChannelId: "forum-pending-actions", members: [], posts: cards, tag: "All",
+ onTagChange: () => {}, onOpenPost: open, onEditPostTags: edit, onDeletePost: vi.fn(),
+ canEditPostTags: permission, canDeletePost: permission,
+ onScrollRoot: (root: HTMLDivElement | null) => {
+ if (root) mockElementGeometry(root, { clientHeight: 751, clientWidth: 390 })
+ },
+ })
+ const view = render(node())
+ const readyPeer = view.getByTestId(tid.forumThreadCard(cards[0].id))
+ for (const post of cards.slice(1)) {
+ const pending = view.getByTestId(tid.forumThreadCard(post.id))
+ expect(pending).toHaveAttribute("aria-busy", "true")
+ expect(pending).not.toHaveAttribute("role")
+ expect(pending).not.toHaveAttribute("tabindex")
+ expect(pending).not.toHaveAttribute("data-msg-id")
+ expect(pending.querySelector("button")).toBeNull()
+ expect(view.queryByTestId(tid.forumThreadTitle(post.id))).toBeNull()
+ fireEvent.click(pending)
+ fireEvent.keyDown(pending, { key: "Enter" })
+ }
+ expect(open).not.toHaveBeenCalled()
+ decisions.set(cards[1].id, false)
+ view.rerender(node())
+ const denied = view.getByTestId(tid.forumThreadCard(cards[1].id))
+ expect(denied).not.toHaveAttribute("aria-busy", "true")
+ expect(view.getByTestId(tid.forumThreadTitle(cards[1].id))).toBeInTheDocument()
+ expect(denied.querySelectorAll("button")).toHaveLength(0)
+ expect(view.getByTestId(tid.forumThreadCard(cards[2].id))).toHaveAttribute("aria-busy", "true")
+ expect(view.getByTestId(tid.forumThreadCard(cards[0].id))).toBe(readyPeer)
+ decisions.set(cards[2].id, true)
+ view.rerender(node())
+ const allowed = view.getByTestId(tid.forumThreadCard(cards[2].id))
+ expect(allowed).not.toHaveAttribute("aria-busy", "true")
+ expect(allowed.querySelectorAll("button")).toHaveLength(3)
+ expect(view.getByTestId(tid.forumThreadCard(cards[1].id))).toBe(denied)
+ expect(view.getByTestId(tid.forumThreadCard(cards[0].id))).toBe(readyPeer)
+ fireEvent.click(view.getByTestId(tid.forumThreadArchiveBtn(cards[2].id)))
+ expect(edit).toHaveBeenCalledWith(cards[2].id, ["archived"])
+ expect(open).not.toHaveBeenCalled()
+})
+
it("keeps native forum rows positioned without individual transforms across scrolling and append", () => {
const onLoadMore = vi.fn()
const onScrollRoot = (node: HTMLDivElement | null) => {
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 60b588a4f..c07ecfa86 100644
--- a/src/web/src/components/community/channels/forum-view.test.ts
+++ b/src/web/src/components/community/channels/forum-view.test.ts
@@ -298,7 +298,8 @@ describe("ForumView responsive post actions", () => {
expect(archiveButton).toContain("disabled:opacity-50")
expect(deleteButton).toContain("disabled:opacity-50")
expect(html).toContain("grid-cols-[minmax(0,1fr)_auto]")
- expect(html).toContain("row-span-2")
+ 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("w-full min-w-0 max-w-full self-start text-[15px] font-semibold leading-tight")
expect(html).toContain(tid.forumThreadTitle("p1"))
diff --git a/src/web/src/components/community/channels/forum-view.tsx b/src/web/src/components/community/channels/forum-view.tsx
index af52ecd60..bc70f182c 100644
--- a/src/web/src/components/community/channels/forum-view.tsx
+++ b/src/web/src/components/community/channels/forum-view.tsx
@@ -155,13 +155,13 @@ export function ForumView({
// Save handler for a single post's tags. Absent → tag editing disabled.
onEditPostTags?: (threadId: string, tags: string[]) => Promise<void> | void
// Whether the current user may edit a given post's tags (creator or manager).
- canEditPostTags?: (post: ForumThread) => boolean
+ canEditPostTags?: (post: ForumThread) => boolean | undefined
// The post id whose tag save is in flight, if any.
savingTagsFor?: string | null
// Delete handler for a single post. Absent → delete disabled.
onDeletePost?: (post: ForumThread) => void
// Whether the current user may delete a given post (creator or manager).
- canDeletePost?: (post: ForumThread) => boolean
+ canDeletePost?: (post: ForumThread) => boolean | undefined
// The post id whose delete is in flight, if any.
deletingPost?: string | null
onScrollRoot?: (node: HTMLDivElement | null) => void
@@ -289,8 +289,9 @@ export function ForumView({
hasMore={hasMore} loadingMore={loadingMore} isFetching={isFetching} isError={isError}
onLoadMore={onLoadMore} onScrollRoot={onScrollRoot} loadingContent={<ForumListSkeleton />}
renderPost={(p, index) => {
- const canEdit = !!onEditPostTags && (canEditPostTags?.(p) ?? false)
- const canDelete = !!onDeletePost && (canDeletePost?.(p) ?? false)
+ const canEdit = onEditPostTags && canEditPostTags ? canEditPostTags(p) : false
+ const canDelete = onDeletePost && canDeletePost ? canDeletePost(p) : false
+ if (canEdit === undefined || canDelete === undefined) return <ForumPostSkeleton key={p.id} postId={p.id} last={index === posts.length - 1} />
const archived = p.tags.includes(FORUM_ARCHIVE_TAG)
const hasOrdinaryTags = p.tags.some((postTag) => postTag !== FORUM_ARCHIVE_TAG)
const savingTags = savingTagsFor === p.id
@@ -326,7 +327,7 @@ export function ForumView({
<ForumPostTitle name={p.name} postId={p.id} seq={p.parentSeq} />
{(canEdit || canDelete) && (
<div
- className="col-start-2 row-span-2 row-start-1 z-10 flex items-start gap-1"
+ className="col-start-2 row-start-1 z-10 flex items-start gap-1"
onClick={(event) => event.stopPropagation()}
onKeyDown={(event) => event.stopPropagation()}
>
@@ -385,7 +386,7 @@ export function ForumView({
</div>
)}
- <p data-slot="community-forum-post-preview" className="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 mb-2.25 mt-0.75 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">
<Avatar label={author.avatar} seed={p.authorId} size={20} />
@@ -435,23 +436,33 @@ export function ForumView({
// Loading placeholder for the forum post list. It mirrors the flat rows so the
// page does not flash back to the old card treatment while data is loading.
+function ForumPostSkeleton({ postId, last = false }: { postId?: string; last?: boolean }) {
+ return (
+ <div
+ data-slot="community-forum-post-skeleton"
+ 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")}
+ >
+ <Skeleton className="h-4 w-2/3 rounded" />
+ <div className="mb-2.25 mt-1.25 space-y-1.5">
+ <Skeleton className="h-3 w-full rounded" />
+ <Skeleton className="h-3 w-4/5 rounded" />
+ </div>
+ <div className="flex items-center gap-2">
+ <Skeleton className="size-5 rounded-full" />
+ <Skeleton className="h-3 w-28 rounded" />
+ <Skeleton className="ml-auto h-3 w-10 rounded" />
+ </div>
+ </div>
+ )
+}
+
function ForumListSkeleton() {
return (
<div className="flex flex-col">
- {Array.from({ length: 3 }).map((_, i) => (
- <div key={i} className="flex flex-col border-b border-border/50 px-4.5 py-3.5 last:border-b-0">
- <Skeleton className="h-4 w-2/3 rounded" />
- <div className="mb-2.25 mt-1.25 space-y-1.5">
- <Skeleton className="h-3 w-full rounded" />
- <Skeleton className="h-3 w-4/5 rounded" />
- </div>
- <div className="flex items-center gap-2">
- <Skeleton className="size-5 rounded-full" />
- <Skeleton className="h-3 w-28 rounded" />
- <Skeleton className="ml-auto h-3 w-10 rounded" />
- </div>
- </div>
- ))}
+ {Array.from({ length: 3 }).map((_, i) => <ForumPostSkeleton key={i} last={i === 2} />)}
</div>
)
}