{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "comments-01",
  "description": "Discussion threads with replies, reactions and resolved threads, and a box to start a new one.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/comments.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/comments/comments-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  CommentAvatar,\n  type CommentAuthor,\n  CommentComposer,\n  CommentThread,\n  type ThreadComment,\n  toggleReaction,\n  updateComment,\n} from '@/registry/components/dashboardblocks/comments'\nimport { startTransition, useRef, useState } from 'react'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Comments1Props extends BlockStateProps {\n  /** Leave out, or pass none, to show the empty state. */\n  comments?: ThreadComment[]\n  currentUser: CommentAuthor\n  /** Pass a fixed date, so times render the same on the server and in the browser. */\n  now: Date\n  onDelete?: (commentId: string) => void\n  onEdit?: (commentId: string, body: string) => Promise<void>\n  onReact?: (commentId: string, emoji: string) => void\n  onResolve?: (commentId: string, resolved: boolean) => void\n  /** Posts a comment, or a reply when `parentId` is set. */\n  onSubmit?: (body: string, options: { parentId?: string }) => Promise<void>\n  people: CommentAuthor[]\n  title: string\n}\n\nconst exampleNow = new Date(Date.UTC(2026, 8, 26, 12))\nconst hoursAgo = (hours: number) => new Date(exampleNow.getTime() - hours * 3_600_000)\n\nconst amara = { name: 'Amara Okafor' }\nconst priya = { avatar: '/images/avatar-02.webp', name: 'Priya Nair' }\nconst lena = { avatar: '/images/avatar-03.webp', name: 'Lena Fischer' }\nconst mateo = { name: 'Mateo Silva' }\nconst jonas = { avatar: '/images/avatar-07.webp', name: 'Jonas Weber' }\n\nconst exampleProps: Comments1Props = {\n  comments: [\n    {\n      at: hoursAgo(3),\n      author: priya,\n      body: 'Enterprise ARR jumped 18% in August. @Lena Fischer is that the Northwind renewal landing early?',\n      id: 'c1',\n      reactions: [{ count: 2, emoji: '👀', reacted: false }],\n      replies: [\n        {\n          at: hoursAgo(2.5),\n          author: lena,\n          body: 'Yes, they signed on Aug 28 instead of Sep 15. I’ll add a note to the chart.',\n          id: 'c1-1',\n          reactions: [{ count: 3, emoji: '👍', reacted: true }],\n        },\n        {\n          at: hoursAgo(1),\n          author: mateo,\n          body: 'Worth splitting renewals from new business here, otherwise September will look flat.',\n          id: 'c1-2',\n        },\n      ],\n    },\n    {\n      at: hoursAgo(26),\n      author: amara,\n      body: 'SMB churn is back under 3% for the first time since March. Nice work on the onboarding emails, @Mateo Silva 🎉',\n      edited: true,\n      id: 'c2',\n      reactions: [\n        { count: 4, emoji: '🎉', reacted: false },\n        { count: 1, emoji: '❤️', reacted: false },\n      ],\n    },\n    {\n      at: hoursAgo(50),\n      author: jonas,\n      body: 'The EU revenue tile includes VAT, so it doesn’t match the finance report.',\n      id: 'c3',\n      replies: [\n        {\n          at: hoursAgo(47),\n          author: lena,\n          body: 'Fixed in the model. Revenue is net of VAT everywhere now.',\n          id: 'c3-1',\n        },\n      ],\n      resolved: true,\n    },\n  ],\n  currentUser: amara,\n  now: exampleNow,\n  people: [priya, lena, mateo, jonas],\n  title: 'Q3 revenue review',\n}\n\nconst noComments: ThreadComment[] = []\n\nasync function save() {\n  await new Promise((resolve) => setTimeout(resolve, 500))\n}\n\nconst Comments1 = (props: Comments1Props) => {\n  const {\n    comments: initialComments = noComments,\n    currentUser,\n    now,\n    onDelete = () => {},\n    onEdit = save,\n    onReact = () => {},\n    onResolve = () => {},\n    onSubmit = save,\n    people,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const [comments, setComments] = useState(initialComments)\n  const [loaded, setLoaded] = useState(initialComments)\n  if (initialComments !== loaded) {\n    setLoaded(initialComments)\n    setComments(initialComments)\n  }\n  const state = getBlockState(status, comments)\n  const composerRef = useRef<HTMLDivElement>(null)\n  const open = comments.filter((comment) => !comment.resolved).length\n  const resolved = comments.length - open\n\n  async function post(body: string, parentId?: string) {\n    await onSubmit(body, { parentId })\n    startTransition(() => {\n      setComments((current) => {\n        const comment: ThreadComment = {\n          at: now,\n          author: currentUser,\n          body,\n          id: `${Date.now()}`,\n        }\n        return parentId\n          ? updateComment(current, parentId, (parent) => ({\n              ...parent,\n              replies: [...(parent.replies ?? []), comment],\n            }))\n          : [...current, comment]\n      })\n    })\n  }\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <BlockReady className='text-sm'>\n                <p className='text-muted-foreground text-sm'>\n                  {open} open {open === 1 ? 'thread' : 'threads'} in the discussion\n                  {resolved > 0 && `, ${resolved} resolved`}.\n                </p>\n              </BlockReady>\n            </header>\n            <div className='flex flex-col divide-y border-t'>\n              <BlockStateRows className='pb-4' rows={4} />\n              {!state &&\n                comments.map((comment) => (\n                  <CommentThread\n                    key={comment.id}\n                    className='py-4'\n                    comment={comment}\n                    currentUser={currentUser}\n                    now={now}\n                    people={people}\n                    onReply={(body) => post(body, comment.id)}\n                    onReact={(commentId, emoji) => {\n                      onReact(commentId, emoji)\n                      setComments((current) =>\n                        updateComment(current, commentId, (item) => ({\n                          ...item,\n                          reactions: toggleReaction(item.reactions, emoji),\n                        })),\n                      )\n                    }}\n                    onResolve={(resolved) => {\n                      onResolve(comment.id, resolved)\n                      setComments((current) =>\n                        updateComment(current, comment.id, (item) => ({\n                          ...item,\n                          resolved,\n                        })),\n                      )\n                    }}\n                    onEdit={async (commentId, body) => {\n                      await onEdit(commentId, body)\n                      startTransition(() =>\n                        setComments((current) =>\n                          updateComment(current, commentId, (item) => ({\n                            ...item,\n                            body,\n                            edited: true,\n                          })),\n                        ),\n                      )\n                    }}\n                    onDelete={(commentId) => {\n                      onDelete(commentId)\n                      setComments((current) =>\n                        updateComment(current, commentId, () => null),\n                      )\n                      if (commentId === comment.id) {\n                        requestAnimationFrame(() =>\n                          composerRef.current?.querySelector('textarea')?.focus(),\n                        )\n                      }\n                    }}\n                  />\n                ))}\n            </div>\n            <div ref={composerRef} className='-mt-4 flex gap-3 border-t pt-4'>\n              <CommentAvatar author={currentUser} className='self-start' />\n              <CommentComposer\n                className='min-w-0 flex-1'\n                disabled={state === 'loading' || state === 'error'}\n                people={people}\n                placeholder='Add to the discussion'\n                onSubmit={(body) => post(body)}\n              />\n            </div>\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Comments1, exampleProps as comments1ExampleProps, type Comments1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/comments/comments-01.tsx"
    }
  ],
  "meta": {
    "shows": "Discussion threads with replies, reactions and resolved threads, and a box to start a new one.",
    "size": "half",
    "usedWith": [
      "comments-02",
      "activity-feed-01"
    ],
    "component": "Comments1",
    "props": "{ comments?: { at: Date; author: { avatar?: string; name: string }; body: string; edited?: boolean; id: string; reactions?: { count: number; emoji: string; reacted: boolean }[]; replies?: ThreadComment[]; resolved?: boolean }[]; currentUser: { avatar?: string; name: string }; now: Date; onDelete?: (commentId: string) => void; onEdit?: (commentId: string, body: string) => Promise<void>; onReact?: (commentId: string, emoji: string) => void; onResolve?: (commentId: string, resolved: boolean) => void; onSubmit?: (body: string, options: { parentId?: string }) => Promise<void>; people: { avatar?: string; name: string }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
