"use client"; /** * comment-pill-store — the per-page "New comments (n)" pill state * (TASK-0094 R2). * * The pill is driven by `comment.event` frames (created / replied) that * arrive while the comment panel is CLOSED. The panel clears the pill when * it opens (a refetch shows the new comments). The store is keyed by pageId * (one pill per page, the page view mounts at most one). The frame's * `actorId` (the author) and the panel's "new" count are the same figure — * a created/replied frame is exactly one new comment. * * (reacted / resolved / reopened / deleted do NOT bump the pill — those are * state changes on an existing thread, not a new comment; the panel * refetches for them.) */ import { create } from "zustand"; interface CommentPillState { /** pageId → number of new comments since the panel was last opened. */ byPage: Record; /** A created/replied frame arrived (one new comment). */ add: (pageId: string) => void; /** The panel opened → the refetch shows the new comments. */ clear: (pageId: string) => void; } export const useCommentPillStore = create()((set) => ({ byPage: {}, add: (pageId) => set((s) => ({ byPage: { ...s.byPage, [pageId]: (s.byPage[pageId] ?? 0) + 1 } })), clear: (pageId) => set((s) => { if (!(pageId in s.byPage)) return s; const next = { ...s.byPage }; delete next[pageId]; return { byPage: next }; }) }));