Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat(web): refresh forum with frameless design

Gus991e784f96c6
diff --git a/src/web/src/app/globals.css b/src/web/src/app/globals.css
index da79824de..28024d0f4 100644
--- a/src/web/src/app/globals.css
+++ b/src/web/src/app/globals.css
@@ -360,6 +360,10 @@ body.community-onboarding-active.driver-active :is(
--radius: 0.625rem;
--status-online: oklch(0.72 0.19 145);
--status-offline: oklch(0.65 0.2 25);
+ --forum-tag-text-l: 0.46;
+ --forum-tag-text-c: 0.13;
+ --forum-tag-bg-l: 0.95;
+ --forum-tag-bg-c: 0.035;
--te: oklch(0.55 0.1 250);
--ti: oklch(0.52 0.12 150);
--tc: oklch(0.57 0.15 28);
@@ -408,6 +412,10 @@ body.community-onboarding-active.driver-active :is(
--chart-5: oklch(0.27 0.01 60);
--status-online: oklch(0.75 0.18 145);
--status-offline: oklch(0.7 0.18 25);
+ --forum-tag-text-l: 0.8;
+ --forum-tag-text-c: 0.1;
+ --forum-tag-bg-l: 0.28;
+ --forum-tag-bg-c: 0.04;
--te: oklch(0.72 0.08 250);
--ti: oklch(0.75 0.12 150);
--tc: oklch(0.72 0.14 28);
@@ -425,6 +433,11 @@ body.community-onboarding-active.driver-active :is(
--sidebar-ring: oklch(0.55 0.01 60);
}
+.forum-tag-color {
+ color: oklch(var(--forum-tag-text-l) var(--forum-tag-text-c) var(--forum-tag-hue));
+ background-color: oklch(var(--forum-tag-bg-l) var(--forum-tag-bg-c) var(--forum-tag-hue));
+}
+
/* ── Object-mimicry card grain texture (shared) ── */
.card-grain {
position: relative;
diff --git a/src/web/src/components/community/forum-view.test.ts b/src/web/src/components/community/forum-view.test.ts
index 89b284d9e..ef3b3bd3e 100644
--- a/src/web/src/components/community/forum-view.test.ts
+++ b/src/web/src/components/community/forum-view.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect } from "vitest"
import { createElement } from "react"
import { renderToStaticMarkup } from "react-dom/server"
-import { ForumView } from "./forum-view"
+import { ForumView, shouldActivateForumRow } from "./forum-view"
import { tid } from "@/lib/community/testids"
import type { ForumThread } from "./_types"
@@ -16,9 +16,11 @@ function makePost(over: Partial<ForumThread> = {}): ForumThread {
parent: { authorName: "Alice", text: "root" },
authorId: "usr_alice",
authorAvatar: "A",
+ openerMessageId: "msg_1",
tags: [],
preview: "preview text",
participants: [{ id: "usr_alice", name: "Alice", avatar: "A" }],
+ participantCount: 1,
...over,
}
}
@@ -58,6 +60,30 @@ function renderWithDelete(
}
describe("ForumView post card header", () => {
+ it("only lets the row itself handle Enter or Space, not nested controls", () => {
+ const row = {}
+ const child = {}
+ expect(shouldActivateForumRow({ key: "Enter", target: row, currentTarget: row })).toBe(true)
+ expect(shouldActivateForumRow({ key: " ", target: row, currentTarget: row })).toBe(true)
+ expect(shouldActivateForumRow({ key: "Enter", target: child, currentTarget: row })).toBe(false)
+ expect(shouldActivateForumRow({ key: "Escape", target: row, currentTarget: row })).toBe(false)
+ })
+
+ it("renders the title and opener seq before the creator metadata", () => {
+ const html = render([makePost({ parentSeq: 42 })])
+ expect(html.indexOf("A post title")).toBeLessThan(html.indexOf(">Alice<"))
+ expect(html).toContain('<span class="opacity-60">#</span>42')
+ })
+
+ it("uses a flat hairline row instead of the old bordered card", () => {
+ const html = render([makePost()])
+ const testIdIndex = html.indexOf(tid.forumThreadCard("p1"))
+ const rowMarkup = html.slice(Math.max(0, testIdIndex - 250), testIdIndex + 350)
+ expect(rowMarkup).toContain("border-border/50")
+ expect(rowMarkup).not.toContain("bg-card")
+ expect(rowMarkup).not.toContain("rounded-lg border")
+ })
+
it("solo post renders the creator name and no participant AvatarGroup", () => {
const html = render([makePost()])
expect(html).toContain(">Alice<")
@@ -78,7 +104,7 @@ describe("ForumView post card header", () => {
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))
+ expect(html.indexOf('aria-hidden="true">·</span>')).toBeLessThan(html.indexOf(groupTid))
})
it("falls back to \"Unknown\" when the creator name is empty (deleted creator)", () => {
@@ -88,7 +114,7 @@ describe("ForumView post card header", () => {
it("renders the time separator for both a solo post and a post with others", () => {
const solo = render([makePost()])
- expect(solo).toContain("· ")
+ expect(solo).toContain('aria-hidden="true">·</span>')
const withOthers = render([
makePost({
@@ -98,7 +124,7 @@ describe("ForumView post card header", () => {
],
}),
])
- expect(withOthers).toContain("· ")
+ expect(withOthers).toContain('aria-hidden="true">·</span>')
expect(withOthers).toContain(tid.forumThreadAvatars("p1"))
})
@@ -112,6 +138,14 @@ describe("ForumView post card header", () => {
expect(html).toContain(tid.forumThreadAvatars("p1"))
expect(html).not.toContain(">+1<")
})
+
+ it("shows at most two resting tags and collapses the rest into a touch-safe +N button", () => {
+ const html = render([makePost({ tags: ["alpha", "beta", "gamma", "delta"] })])
+ expect(html).toContain("#alpha")
+ expect(html).toContain("#beta")
+ expect(html).toContain("Show 2 more tags")
+ expect(html).toContain(">+2<")
+ })
})
describe("ForumView post delete button", () => {
diff --git a/src/web/src/components/community/forum-view.tsx b/src/web/src/components/community/forum-view.tsx
index ca25bb11c..d26584f74 100644
--- a/src/web/src/components/community/forum-view.tsx
+++ b/src/web/src/components/community/forum-view.tsx
@@ -6,10 +6,10 @@ import { COMMUNITY_VIRTUALIZER_REACT_OPTIONS } from "@/hooks/community/virtualiz
import { MessagesSquare, ListChevronsUpDown, Plus, Tag, Trash2 } from "lucide-react"
import { Button } from "@/components/ui/button"
import { formatRelativeTime } from "./format-time"
-import { Badge } from "@/components/ui/badge"
import { Skeleton } from "@/components/ui/skeleton"
import { Avatar } from "./avatar"
import { AvatarGroup, AvatarGroupCount } from "@/components/ui/avatar"
+import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
import { EmptyState } from "./empty-state"
import { CreateForumThread, type NewForumThread } from "./create-forum-thread"
import { PostTagDialog } from "./post-tag-dialog"
@@ -18,10 +18,61 @@ import { tid } from "@/lib/community/testids"
import type { ForumThread, Member } from "./_types"
import { VirtualRows } from "./virtual-cursor-list"
import { useVirtualCursorSentinel } from "@/hooks/community/use-virtual-cursor-sentinel"
+import { tagColorClassName, tagColorStyle } from "@/lib/community/tag-color"
+import { cn } from "@/lib/utils"
-// Max member avatars shown in a post card's AvatarGroup before collapsing to a
-// "+N" bubble. Creator is always first.
const MAX_AVATARS = 5
+const MAX_VISIBLE_TAGS = 2
+
+export function shouldActivateForumRow(event: {
+ key: string
+ target: EventTarget | null
+ currentTarget: EventTarget | null
+}) {
+ return event.target === event.currentTarget && (event.key === "Enter" || event.key === " ")
+}
+
+function ForumTagSummary({ tags }: { tags: string[] }) {
+ const shown = tags.slice(0, MAX_VISIBLE_TAGS)
+ const hidden = tags.slice(MAX_VISIBLE_TAGS)
+ if (shown.length === 0) return null
+
+ return (
+ <div
+ className="flex min-w-0 items-center gap-1.5 max-sm:order-last max-sm:basis-full max-sm:pl-7"
+ onClick={(event) => event.stopPropagation()}
+ onKeyDown={(event) => event.stopPropagation()}
+ >
+ {shown.map((tag) => <span key={tag} className="max-w-24 truncate">#{tag}</span>)}
+ {hidden.length > 0 && (
+ <Popover>
+ <PopoverTrigger
+ render={(
+ <button
+ type="button"
+ className="shrink-0 rounded px-1 py-0.5 hover:bg-accent hover:text-foreground"
+ aria-label={`Show ${hidden.length} more tags`}
+ onClick={(event) => event.stopPropagation()}
+ >
+ +{hidden.length}
+ </button>
+ )}
+ />
+ <PopoverContent
+ side="top"
+ align="start"
+ className="flex w-52 flex-wrap gap-1.5 p-2"
+ onClick={(event) => event.stopPropagation()}
+ >
+ {tags.map((tag) => (
+ <span key={tag} className="rounded-md bg-muted px-1.5 py-1 text-xs text-muted-foreground">#{tag}</span>
+ ))}
+ </PopoverContent>
+ </Popover>
+ )}
+ </div>
+ )
+}
// Forum channel body — rendered under the shared ChannelHeader. A feed of posts;
// each post opens as a thread. The filter bar's tag chips are DERIVED from the
@@ -66,7 +117,6 @@ export function ForumView({
deletingPost?: string | null
}) {
const [composing, setComposing] = useState(false)
- const [editingTagsFor, setEditingTagsFor] = useState<ForumThread | null>(null)
const [deletingFor, setDeletingFor] = useState<ForumThread | null>(null)
const newPostTriggerRef = useRef<HTMLButtonElement>(null)
const scrollRef = useRef<HTMLDivElement>(null)
@@ -76,7 +126,7 @@ export function ForumView({
...COMMUNITY_VIRTUALIZER_REACT_OPTIONS,
count: posts.length,
getScrollElement: () => scrollRef.current,
- estimateSize: () => 160,
+ estimateSize: () => 128,
getItemKey: (index) => posts[index]?.id ?? index,
overscan: 5,
initialRect: { width: 0, height: 800 },
@@ -126,17 +176,31 @@ export function ForumView({
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-2">
{filterTags.length > 0 && (
<>
- <Badge variant={tag === "All" ? "default" : "secondary"} className="shrink-0 cursor-pointer" render={<button onClick={() => onTagChange("All")} />}>All</Badge>
+ <button
+ type="button"
+ className={cn(
+ "shrink-0 rounded-lg px-2.75 py-1 text-[13px] leading-5 transition-colors",
+ tag === "All" ? "bg-accent text-foreground" : "text-muted-foreground hover:bg-accent/60 hover:text-foreground",
+ )}
+ onClick={() => onTagChange("All")}
+ >
+ All
+ </button>
{filterTags.map((t) => (
- <Badge
+ <button
key={t}
- variant={tag === t ? "default" : "secondary"}
- className="shrink-0 cursor-pointer"
+ type="button"
+ style={tagColorStyle(t)}
+ 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",
+ )}
data-testid={tid.forumTagChip(t)}
- render={<button onClick={() => onTagChange(t)} />}
+ onClick={() => onTagChange(t)}
>
{`#${t}`}
- </Badge>
+ </button>
))}
</>
)}
@@ -147,7 +211,7 @@ export function ForumView({
</div>
)}
- <div ref={scrollRef} role="main" className="flex-1 overflow-y-auto thin-scrollbar p-4">
+ <div ref={scrollRef} role="main" className="flex-1 overflow-y-auto thin-scrollbar px-4 py-2">
{loading && posts.length === 0 ? (
<ForumListSkeleton />
) : posts.length === 0 ? (
@@ -158,12 +222,13 @@ export function ForumView({
items={posts}
virtualizer={virtualizer}
itemKey={(post) => post.id}
- renderItem={(p) => {
+ renderItem={(p, index) => {
const canEdit = !!onEditPostTags && (canEditPostTags?.(p) ?? false)
const canDelete = !!onDeletePost && (canDeletePost?.(p) ?? false)
const others = p.participants.filter((m) => m.id !== p.authorId)
const shown = others.slice(0, MAX_AVATARS)
- const overflow = Math.max(0, p.participantCount - 1 - shown.length)
+ const participantTotal = p.participantCount ?? others.length + 1
+ const overflow = Math.max(0, participantTotal - 1 - shown.length)
return (
<div
key={p.id}
@@ -171,56 +236,85 @@ export function ForumView({
tabIndex={0}
data-testid={tid.forumThreadCard(p.id)}
onClick={() => onOpenPost(p.id)}
- onKeyDown={(e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); onOpenPost(p.id) } }}
- className="group/card mb-3 flex cursor-pointer flex-col gap-2 rounded-lg border border-border bg-card p-4 text-left transition-colors hover:border-primary/40 hover:bg-accent/40"
+ onKeyDown={(event) => {
+ if (!shouldActivateForumRow(event)) return
+ event.preventDefault()
+ 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",
+ index === posts.length - 1 && "border-b-0",
+ )}
>
- <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 && (
- <>
- <span className="h-4 w-px shrink-0 bg-border" aria-hidden />
- <AvatarGroup data-testid={tid.forumThreadAvatars(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>
- </>
- )}
- {canEdit && (
- <button
- type="button"
- data-testid={tid.forumThreadTagBtn(p.id)}
- onClick={(e) => { e.stopPropagation(); setEditingTagsFor(p) }}
- className="ml-auto grid size-6 shrink-0 place-items-center rounded-md text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-foreground focus-visible:opacity-100 group-hover/card:opacity-100"
- aria-label="Edit tags"
- >
- <Tag className="size-4" />
- </button>
- )}
- {canDelete && (
+ {(canEdit || canDelete) && (
+ <div
+ className="absolute right-3 top-3 z-10 flex items-center gap-1"
+ onClick={(event) => event.stopPropagation()}
+ onKeyDown={(event) => event.stopPropagation()}
+ >
+ {canEdit && (
+ <PostTagDialog
+ trigger={(
+ <button
+ type="button"
+ data-testid={tid.forumThreadTagBtn(p.id)}
+ onClick={(event) => event.stopPropagation()}
+ className="grid size-6 shrink-0 place-items-center rounded-md text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-foreground focus-visible:opacity-100 data-popup-open:opacity-100 group-hover/card:opacity-100"
+ aria-label="Edit tags"
+ >
+ <Tag className="size-4" />
+ </button>
+ )}
+ postName={p.name}
+ current={p.tags}
+ allTags={availableTags}
+ saving={savingTagsFor === p.id}
+ onSave={(tags) => onEditPostTags?.(p.id, tags)}
+ />
+ )}
+ {canDelete && (
<button
type="button"
data-testid={tid.forumThreadDeleteBtn(p.id)}
disabled={deletingPost === p.id}
onClick={(e) => { e.stopPropagation(); setDeletingFor(p) }}
- className={`${canEdit ? "" : "ml-auto "}grid size-6 shrink-0 place-items-center rounded-md text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-destructive focus-visible:opacity-100 group-hover/card:opacity-100 disabled:cursor-not-allowed disabled:opacity-50`}
+ className="grid size-6 shrink-0 place-items-center rounded-md text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-destructive focus-visible:opacity-100 group-hover/card:opacity-100 disabled:cursor-not-allowed disabled:opacity-50"
aria-label="Delete post"
>
<Trash2 className="size-4" />
</button>
+ )}
+ </div>
+ )}
+
+ <div className="flex flex-wrap items-baseline gap-1.75 pr-14">
+ <h3 className="max-w-full text-[15px] font-semibold leading-tight">{p.name}</h3>
+ {p.parentSeq !== undefined && (
+ <span className="shrink-0 font-mono text-[13px] font-medium text-muted-foreground">
+ <span className="opacity-60">#</span>{p.parentSeq}
+ </span>
)}
</div>
- <h3 className="line-clamp-1 text-[15px] font-semibold leading-tight">{p.name}</h3>
- <p className="line-clamp-2 text-sm text-muted-foreground">{p.preview}</p>
- <div className="flex items-center gap-2">
- {p.tags.length > 0 && p.tags.map((t) => (
- <Badge key={t} variant="secondary">#{t}</Badge>
- ))}
- <span className="ml-auto flex items-center gap-1 text-xs text-muted-foreground">
- <MessagesSquare className="size-3.5" /> {Math.max(0, p.messageCount)}
+ <p className="mb-2.25 mt-0.75 line-clamp-2 text-[13.5px] text-muted-foreground">{p.preview}</p>
+ <div className="flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1.5 text-xs text-muted-foreground">
+ <Avatar label={p.authorAvatar} seed={p.authorId} size={20} />
+ <span className="shrink-0 font-medium text-foreground" suppressHydrationWarning>{p.parent.authorName || "Unknown"}</span>
+ <span className="shrink-0" aria-hidden>·</span>
+ <span className="shrink-0" suppressHydrationWarning>{formatRelativeTime(p.lastMessageAt)}</span>
+ {p.tags.length > 0 && <span className="shrink-0 max-sm:hidden" aria-hidden>·</span>}
+ <ForumTagSummary tags={p.tags} />
+ <span className="ml-auto flex shrink-0 items-center gap-2">
+ {others.length > 0 && (
+ <AvatarGroup className="-space-x-1.25" data-testid={tid.forumThreadAvatars(p.id)}>
+ {shown.map((member) => (
+ <Avatar key={member.id} label={member.avatar} seed={member.id} size={19} ringColor="var(--background)" />
+ ))}
+ {overflow > 0 && <AvatarGroupCount className="size-4.75 text-[10px]">+{overflow}</AvatarGroupCount>}
+ </AvatarGroup>
+ )}
+ <span className="flex items-center gap-1">
+ <MessagesSquare className="size-3.5" /> {Math.max(0, p.messageCount)}
+ </span>
</span>
</div>
</div>
@@ -232,18 +326,6 @@ export function ForumView({
)}
</div>
- {editingTagsFor && (
- <PostTagDialog
- open
- onOpenChange={(v) => { if (!v) setEditingTagsFor(null) }}
- postName={editingTagsFor.name}
- current={editingTagsFor.tags}
- allTags={availableTags}
- saving={savingTagsFor === editingTagsFor.id}
- onSave={(tags) => { onEditPostTags?.(editingTagsFor.id, tags); setEditingTagsFor(null) }}
- />
- )}
-
{deletingFor && (
<ConfirmDialog
open
@@ -258,26 +340,21 @@ export function ForumView({
)
}
-// Loading placeholder for the forum post list — three card placeholders that
-// match <ForumView>'s post-card density so the filter bar above doesn't shift
-// when posts arrive.
+// 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 ForumListSkeleton() {
return (
- <div className="flex flex-col gap-3">
+ <div className="flex flex-col">
{Array.from({ length: 3 }).map((_, i) => (
- <div key={i} className="flex flex-col gap-2 rounded-lg border border-border bg-card p-4">
- <div className="flex items-center gap-2">
- <Skeleton className="size-6 shrink-0 rounded-full" />
- <Skeleton className="h-3 w-40 rounded" />
- </div>
+ <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="space-y-2">
+ <div className="mb-2.25 mt-1.25 space-y-1.5">
<Skeleton className="h-3 w-full rounded" />
- <Skeleton className="h-3 w-5/6 rounded" />
+ <Skeleton className="h-3 w-4/5 rounded" />
</div>
<div className="flex items-center gap-2">
- <Skeleton className="h-5 w-14 rounded-full" />
- <Skeleton className="h-5 w-12 rounded-full" />
+ <Skeleton className="size-5 rounded-full" />
+ <Skeleton className="h-3 w-28 rounded" />
<Skeleton className="ml-auto h-3 w-10 rounded" />
</div>
</div>
@@ -304,7 +381,7 @@ export function ForumViewSkeleton() {
<Skeleton className="h-8 w-25 rounded-md" />
</div>
</div>
- <main className="flex-1 overflow-y-auto thin-scrollbar p-4">
+ <main className="flex-1 overflow-y-auto thin-scrollbar px-4 py-2">
<ForumListSkeleton />
</main>
</>
diff --git a/src/web/src/components/community/post-tag-dialog.tsx b/src/web/src/components/community/post-tag-dialog.tsx
index fe5fa2df1..8774a8113 100644
--- a/src/web/src/components/community/post-tag-dialog.tsx
+++ b/src/web/src/components/community/post-tag-dialog.tsx
@@ -1,104 +1,120 @@
"use client"
-import { useState } from "react"
+import { useEffect, useState, type ReactElement } from "react"
import { X } from "lucide-react"
-import {
- Dialog,
- DialogContent,
- DialogHeader,
- DialogTitle,
- DialogDescription,
- DialogFooter,
-} from "@/components/ui/dialog"
-import { Button } from "@/components/ui/button"
-import { Badge } from "@/components/ui/badge"
+import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
import { Input } from "@/components/ui/input"
import { onEnterSubmit } from "@/lib/ime"
import { tid } from "@/lib/community/testids"
+import { tagColorClassName, tagColorStyle } from "@/lib/community/tag-color"
+import { cn } from "@/lib/utils"
-// Per-post tag editor. Opened from the tag icon on a post card. Shows the
-// forum's existing tags (the deduped union across posts, passed as `allTags`)
-// as toggle chips, plus a free-text input to add a brand-new tag. Saving PATCHes
-// the post's tag list. There is no forum-level tag vocabulary anymore — a new
-// tag simply exists on this post and joins the union once it lands.
export function PostTagDialog({
- open,
- onOpenChange,
+ trigger,
postName,
current,
allTags,
onSave,
saving,
}: {
- open: boolean
- onOpenChange: (open: boolean) => void
+ trigger: ReactElement
postName: string
current: string[]
allTags: string[]
onSave: (tags: string[]) => void
saving?: boolean
}) {
+ const [open, setOpen] = useState(false)
const [selected, setSelected] = useState<string[]>(current)
const [draft, setDraft] = useState("")
- const toggle = (t: string) =>
- setSelected((prev) => (prev.includes(t) ? prev.filter((x) => x !== t) : [...prev, t]))
+ useEffect(() => {
+ if (!open) setSelected(current)
+ }, [current, open])
+
+ const toggle = (tag: string) => {
+ setSelected((previous) => previous.includes(tag)
+ ? previous.filter((candidate) => candidate !== tag)
+ : [...previous, tag])
+ }
const addDraft = () => {
- const t = draft.trim().toLowerCase()
+ const tag = draft.trim().toLowerCase()
setDraft("")
- if (!t || selected.includes(t)) return
- setSelected((prev) => [...prev, t])
+ if (!tag || selected.includes(tag)) return
+ setSelected((previous) => [...previous, tag])
+ }
+
+ const close = () => {
+ setOpen(false)
+ const changed = selected.length !== current.length
+ || selected.some((tag, index) => tag !== current[index])
+ if (changed) onSave(selected)
}
- // The chip set is the union of the forum's known tags and anything selected
- // (so a freshly-typed tag shows as an active chip too), stable-sorted.
const chips = [...new Set([...allTags, ...selected])].sort()
return (
- <Dialog open={open} onOpenChange={onOpenChange}>
- <DialogContent className="max-w-sm" data-testid={tid.forumTagDialog}>
- <DialogHeader>
- <DialogTitle>Edit tags</DialogTitle>
- <DialogDescription>Tag “{postName}” to help others find it.</DialogDescription>
- </DialogHeader>
+ <Popover
+ open={open}
+ onOpenChange={(nextOpen) => {
+ if (nextOpen) {
+ setSelected(current)
+ setDraft("")
+ setOpen(true)
+ return
+ }
+ close()
+ }}
+ >
+ <PopoverTrigger render={trigger} />
+ <PopoverContent
+ side="bottom"
+ align="end"
+ className="w-64 space-y-3 p-3"
+ data-testid={tid.forumTagDialog}
+ aria-label={`Edit tags for ${postName}`}
+ onClick={(event) => event.stopPropagation()}
+ >
+ <p className="text-[11px] font-medium tracking-[0.12em] text-muted-foreground">TAGS</p>
- <div className="flex flex-wrap items-center gap-2">
+ <div className="flex flex-wrap items-center gap-1.5">
{chips.length === 0 ? (
- <p className="text-sm text-muted-foreground">No tags yet. Add the first one below.</p>
- ) : (
- chips.map((t) => (
- <Badge
- key={t}
- variant={selected.includes(t) ? "default" : "secondary"}
- className="cursor-pointer"
- render={<button type="button" onClick={() => toggle(t)} />}
+ <p className="text-xs text-muted-foreground">No tags yet</p>
+ ) : chips.map((tag) => {
+ const active = selected.includes(tag)
+ return (
+ <button
+ key={tag}
+ type="button"
+ style={tagColorStyle(tag)}
+ className={cn(
+ "inline-flex items-center rounded-lg px-2 py-1 text-xs transition-opacity",
+ tagColorClassName,
+ active ? "opacity-100 ring-1 ring-current/20" : "opacity-55 hover:opacity-80",
+ )}
+ onClick={() => toggle(tag)}
>
- {`#${t}`}
- {selected.includes(t) && <X className="ml-1 size-3" />}
- </Badge>
- ))
- )}
+ #{tag}
+ {active && <X className="ml-1 size-3" />}
+ </button>
+ )
+ })}
</div>
- <div className="flex items-center gap-2">
- <Input
- value={draft}
- onChange={(e) => setDraft(e.target.value)}
- onKeyDown={onEnterSubmit(addDraft)}
- placeholder="new-tag"
- className="h-9"
- />
- <Button type="button" variant="secondary" size="sm" onClick={addDraft} disabled={!draft.trim()}>
- Add
- </Button>
- </div>
+ <Input
+ value={draft}
+ onChange={(event) => setDraft(event.target.value)}
+ onKeyDown={onEnterSubmit(addDraft)}
+ placeholder="Add a tag…"
+ className="h-8 text-sm"
+ disabled={saving}
+ />
- <DialogFooter>
- <Button variant="ghost" onClick={() => onOpenChange(false)}>Cancel</Button>
- <Button data-testid={tid.forumTagDialogSave} onClick={() => onSave(selected)} disabled={saving}>Save tags</Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
+ <p className="text-[11px] text-muted-foreground">
+ {saving ? "Saving…" : "↵ to add · saves on close"}
+ </p>
+ </PopoverContent>
+ </Popover>
)
}
diff --git a/src/web/src/hooks/community/use-forum-feed.test.ts b/src/web/src/hooks/community/use-forum-feed.test.ts
index 785c873d9..fd1c23469 100644
--- a/src/web/src/hooks/community/use-forum-feed.test.ts
+++ b/src/web/src/hooks/community/use-forum-feed.test.ts
@@ -65,7 +65,7 @@ describe("mapForumActivityPages", () => {
],
included: {
parentMessages: [
- { id: "m2", channelId: "forum_1", content: " Opener title ", authorId: "u2", authorName: "Alice", authorImage: null },
+ { id: "m2", channelId: "forum_1", seq: 42, content: " Opener title ", authorId: "u2", authorName: "Alice", authorImage: null },
],
firstMessages: [{ channelId: "t2", content: "First reply preview" }],
tags: [{ messageId: "m2", tag: "bug" }, { messageId: "m2", tag: "help" }],
@@ -101,6 +101,7 @@ describe("mapForumActivityPages", () => {
expect(result.map((thread) => thread.id)).toEqual(["t2", "t1"])
expect(result[0]).toMatchObject({
name: " Opener title ",
+ parentSeq: 42,
authorId: "u2",
authorAvatar: "A",
preview: "First reply preview",
diff --git a/src/web/src/hooks/community/use-forum-feed.ts b/src/web/src/hooks/community/use-forum-feed.ts
index 5218938fb..4cd896265 100644
--- a/src/web/src/hooks/community/use-forum-feed.ts
+++ b/src/web/src/hooks/community/use-forum-feed.ts
@@ -24,6 +24,7 @@ type ActivityThread = {
type IncludedMessage = {
id: string
channelId: string
+ seq: number
content: string
authorId: string
authorName: string
@@ -108,6 +109,7 @@ export function mapForumActivityPages(pages: ForumActivityPage[]): ForumThread[]
authorId: opener?.authorId ?? thread.creatorId ?? "",
authorAvatar: opener?.authorImage ?? avatarInitial(opener?.authorName ?? ""),
openerMessageId: thread.parentMessageId ?? "",
+ ...(opener ? { parentSeq: opener.seq } : {}),
tags: thread.parentMessageId ? tagsByMessage.get(thread.parentMessageId) ?? [] : [],
preview: (first?.content ?? "").slice(0, 100),
participants: participantsByChannel.get(thread.id) ?? [],
diff --git a/src/web/src/lib/community/tag-color.test.ts b/src/web/src/lib/community/tag-color.test.ts
new file mode 100644
index 000000000..ee573cf52
--- /dev/null
+++ b/src/web/src/lib/community/tag-color.test.ts
@@ -0,0 +1,22 @@
+import { describe, expect, it } from "vitest"
+import { tagColorClassName, tagColorStyle, tagHue } from "./tag-color"
+
+describe("forum tag color", () => {
+ it("is deterministic and confined to the curated hue palette", () => {
+ const palette = [8, 30, 55, 95, 145, 175, 205, 250, 290, 330]
+ expect(tagHue("design")).toBe(tagHue("design"))
+ for (const tag of ["design", "bug", "help", "ideas", "urgent"]) {
+ expect(palette).toContain(tagHue(tag))
+ }
+ })
+
+ it("keeps theme values in CSS and exposes only the selected hue inline", () => {
+ expect(tagColorStyle("design")).toEqual({ "--forum-tag-hue": tagHue("design") })
+ expect(tagColorClassName).toBe("forum-tag-color")
+ })
+
+ it("does not collapse representative tags onto one hue", () => {
+ const hues = new Set(["design", "bug", "help", "ideas", "urgent"].map(tagHue))
+ expect(hues.size).toBeGreaterThan(2)
+ })
+})
diff --git a/src/web/src/lib/community/tag-color.ts b/src/web/src/lib/community/tag-color.ts
new file mode 100644
index 000000000..b29623271
--- /dev/null
+++ b/src/web/src/lib/community/tag-color.ts
@@ -0,0 +1,17 @@
+import type { CSSProperties } from "react"
+
+const TAG_HUES = [8, 30, 55, 95, 145, 175, 205, 250, 290, 330] as const
+
+export function tagHue(tag: string): number {
+ let hash = 5381
+ for (const character of tag) {
+ hash = ((hash << 5) + hash + character.charCodeAt(0)) >>> 0
+ }
+ return TAG_HUES[hash % TAG_HUES.length]
+}
+
+export function tagColorStyle(tag: string): CSSProperties {
+ return { "--forum-tag-hue": tagHue(tag) } as CSSProperties
+}
+
+export const tagColorClassName = "forum-tag-color"
diff --git a/src/web/src/lib/community/testids.ts b/src/web/src/lib/community/testids.ts
index 5041feeee..307dc24d1 100644
--- a/src/web/src/lib/community/testids.ts
+++ b/src/web/src/lib/community/testids.ts
@@ -20,7 +20,6 @@ export const tid = {
machinePairCopy: "community-machine-pair-copy",
forumTagDialog: "community-forum-tag-dialog",
- forumTagDialogSave: "community-forum-tag-dialog-save",
message: (id: string) => `community-message-${id}`,
channelRow: (id: string) => `community-channel-row-${id}`,
diff --git a/src/web/src/test/e2e-ui/14-forum-post-tags-presence.spec.ts b/src/web/src/test/e2e-ui/14-forum-post-tags-presence.spec.ts
index 2e7f722f6..33b937f14 100644
--- a/src/web/src/test/e2e-ui/14-forum-post-tags-presence.spec.ts
+++ b/src/web/src/test/e2e-ui/14-forum-post-tags-presence.spec.ts
@@ -46,10 +46,11 @@ test.describe.serial("forum post tags + participant avatars", () => {
await page.getByTestId(tid.forumThreadTagBtn(threadId)).click()
await expect(page.getByTestId(tid.forumTagDialog)).toBeVisible({ timeout: 10_000 })
for (const t of ["alpha", "beta"]) {
- await page.getByPlaceholder("new-tag").fill(t)
- await page.getByRole("button", { name: "Add", exact: true }).click()
+ await page.getByPlaceholder("Add a tag…").fill(t)
+ await page.getByPlaceholder("Add a tag…").press("Enter")
}
- await page.getByTestId(tid.forumTagDialogSave).click()
+ await page.keyboard.press("Escape")
+ await expect(page.getByTestId(tid.forumTagDialog)).toHaveCount(0)
// The card now shows the tags AND the filter bar derives them as the union.
await expect(page.getByTestId(tid.forumTagChip("alpha"))).toBeVisible({ timeout: 15_000 })
@@ -60,9 +61,10 @@ test.describe.serial("forum post tags + participant avatars", () => {
await page.getByTestId(tid.forumThreadTagBtn(threadId)).click()
await expect(page.getByTestId(tid.forumTagDialog)).toBeVisible({ timeout: 10_000 })
// The active (selected) chips carry a remove affordance; click #beta to
- // deselect, then save.
+ // deselect, then close to save.
await page.getByTestId(tid.forumTagDialog).getByRole("button", { name: "#beta" }).click()
- await page.getByTestId(tid.forumTagDialogSave).click()
+ await page.keyboard.press("Escape")
+ await expect(page.getByTestId(tid.forumTagDialog)).toHaveCount(0)
await expect(page.getByTestId(tid.forumTagChip("beta"))).toHaveCount(0, { timeout: 15_000 })
await expect(page.getByTestId(tid.forumTagChip("alpha"))).toBeVisible()