1"use client"; 2 3/** 4 * comment-pill-store — the per-page "New comments (n)" pill state 5 * (TASK-0094 R2). 6 * 7 * The pill is driven by `comment.event` frames (created / replied) that 8 * arrive while the comment panel is CLOSED. The panel clears the pill when 9 * it opens (a refetch shows the new comments). The store is keyed by pageId 10 * (one pill per page, the page view mounts at most one). The frame's 11 * `actorId` (the author) and the panel's "new" count are the same figure — 12 * a created/replied frame is exactly one new comment. 13 * 14 * (reacted / resolved / reopened / deleted do NOT bump the pill — those are 15 * state changes on an existing thread, not a new comment; the panel 16 * refetches for them.) 17 */ 18import { create } from "zustand"; 19 20interface CommentPillState { 21 /** pageId → number of new comments since the panel was last opened. */ 22 byPage: Record<string, number>; 23 /** A created/replied frame arrived (one new comment). */ 24 add: (pageId: string) => void; 25 /** The panel opened → the refetch shows the new comments. */ 26 clear: (pageId: string) => void; 27} 28 29export const useCommentPillStore = create<CommentPillState>()((set) => ({ 30 byPage: {}, 31 add: (pageId) => 32 set((s) => ({ byPage: { ...s.byPage, [pageId]: (s.byPage[pageId] ?? 0) + 1 } })), 33 clear: (pageId) => 34 set((s) => { 35 if (!(pageId in s.byPage)) return s; 36 const next = { ...s.byPage }; 37 delete next[pageId]; 38 return { byPage: next }; 39 }) 40})); 41