Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(community): bind forum post creator name to creator avatar (#386)

Gener1fceecec001f
diff --git a/src/web/src/components/community/forum-view.test.ts b/src/web/src/components/community/forum-view.test.ts
new file mode 100644
index 000000000..665830473
--- /dev/null
+++ b/src/web/src/components/community/forum-view.test.ts
@@ -0,0 +1,76 @@
+import { describe, it, expect } from "vitest"
+import { createElement } from "react"
+import { renderToStaticMarkup } from "react-dom/server"
+import { ForumView } from "./forum-view"
+import { tid } from "@/lib/community/testids"
+import type { ForumPost } from "./_types"
+
+const LAST_AT = "2020-01-01T00:00:00.000Z"
+
+function makePost(over: Partial<ForumPost> = {}): ForumPost {
+ return {
+ id: "p1",
+ name: "A post title",
+ messageCount: 3,
+ lastMessageAt: LAST_AT,
+ parent: { authorName: "Alice", text: "root" },
+ authorId: "usr_alice",
+ authorAvatar: "A",
+ tags: [],
+ preview: "preview text",
+ participants: [{ id: "usr_alice", name: "Alice", avatar: "A" }],
+ ...over,
+ }
+}
+
+function render(posts: ForumPost[]): string {
+ return renderToStaticMarkup(
+ createElement(ForumView, { posts, onOpenPost: () => {} })
+ )
+}
+
+describe("ForumView post card header", () => {
+ it("solo post renders the creator name and no participant AvatarGroup", () => {
+ const html = render([makePost()])
+ expect(html).toContain(">Alice<")
+ expect(html).not.toContain(tid.forumPostAvatars("p1"))
+ })
+
+ it("renders the creator name and time before the participant AvatarGroup in markup order", () => {
+ const html = render([
+ makePost({
+ participants: [
+ { id: "usr_alice", name: "Alice", avatar: "A" },
+ { id: "usr_bob", name: "Bob", avatar: "B" },
+ { id: "usr_cara", name: "Cara", avatar: "C" },
+ ],
+ }),
+ ])
+ const groupTid = tid.forumPostAvatars("p1")
+ expect(html).toContain(groupTid)
+ expect(html.indexOf(">Alice<")).toBeGreaterThanOrEqual(0)
+ expect(html.indexOf(">Alice<")).toBeLessThan(html.indexOf(groupTid))
+ expect(html.indexOf("· ")).toBeLessThan(html.indexOf(groupTid))
+ })
+
+ it("falls back to \"Unknown\" when the creator name is empty (deleted creator)", () => {
+ const html = render([makePost({ parent: { authorName: "", text: "root" } })])
+ expect(html).toContain(">Unknown<")
+ })
+
+ it("renders the time separator for both a solo post and a post with others", () => {
+ const solo = render([makePost()])
+ expect(solo).toContain("· ")
+
+ const withOthers = render([
+ makePost({
+ participants: [
+ { id: "usr_alice", name: "Alice", avatar: "A" },
+ { id: "usr_bob", name: "Bob", avatar: "B" },
+ ],
+ }),
+ ])
+ expect(withOthers).toContain("· ")
+ expect(withOthers).toContain(tid.forumPostAvatars("p1"))
+ })
+})
diff --git a/src/web/src/components/community/forum-view.tsx b/src/web/src/components/community/forum-view.tsx
index 1d7db07de..e2398aab4 100644
--- a/src/web/src/components/community/forum-view.tsx
+++ b/src/web/src/components/community/forum-view.tsx
@@ -105,17 +105,19 @@ export function ForumView({
>
<div className="flex items-center gap-2">
<Avatar label={p.authorAvatar} seed={p.authorId} size={24} />
+ <span className="text-xs font-medium text-foreground" suppressHydrationWarning>{p.parent.authorName || "Unknown"}</span>
+ <span className="text-xs text-muted-foreground" suppressHydrationWarning>· {formatRelativeTime(p.lastMessageAt)}</span>
{others.length > 0 && (
- <AvatarGroup data-testid={tid.forumPostAvatars(p.id)}>
- {shown.map((m) => (
- <Avatar key={m.id} label={m.avatar} seed={m.id} size={24} ringColor="var(--card)" />
- ))}
- {overflow > 0 && <AvatarGroupCount className="size-6 text-[11px]">+{overflow}</AvatarGroupCount>}
- </AvatarGroup>
+ <>
+ <span className="h-4 w-px shrink-0 bg-border" aria-hidden />
+ <AvatarGroup data-testid={tid.forumPostAvatars(p.id)}>
+ {shown.map((m) => (
+ <Avatar key={m.id} label={m.avatar} seed={m.id} size={24} ringColor="var(--card)" />
+ ))}
+ {overflow > 0 && <AvatarGroupCount className="size-6 text-[11px]">+{overflow}</AvatarGroupCount>}
+ </AvatarGroup>
+ </>
)}
- <span className="text-xs text-muted-foreground" suppressHydrationWarning>
- <span className="font-medium text-foreground">{p.parent.authorName}</span> · {formatRelativeTime(p.lastMessageAt)}
- </span>
{canEdit && (
<button
type="button"