{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "activity-feed-03",
  "description": "Notifications in All, Mentions and Unread tabs, with each marked read when opened or all at once.",
  "registryDependencies": [
    "card",
    "button",
    "tabs",
    "https://www.dashboardblocks.com/r/radix/activity-feed.json",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/tag.json",
    "https://www.dashboardblocks.com/r/radix/team.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/activity-feed/activity-feed-03.tsx",
      "content": "'use client'\n\nimport {\n  ActivityFeed,\n  ActivityFeedItem,\n  ActivityTime,\n  MarkAllReadButton,\n  UnreadDot,\n} from '@/registry/components/dashboardblocks/activity-feed'\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { Tag } from '@/registry/components/dashboardblocks/tag'\nimport { type Person, PersonAvatar } from '@/registry/components/dashboardblocks/team'\nimport { formatNumber } from '@/registry/lib/dashboardblocks/format'\nimport { useState } from 'react'\n\nimport { Card, CardContent } from '@/components/ui/card'\nimport { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'\n\nimport { cn } from '@/lib/utils'\n\ninterface Notification {\n  action: string\n  actor: Pick<Person, 'avatar' | 'name'>\n  at: Date\n  id: string\n  mention?: boolean\n  preview?: string\n  read?: boolean\n  target: string\n}\n\ninterface ActivityFeed3Props extends BlockStateProps {\n  /** Newest first. Leave out, or pass none, to show the empty state. */\n  notifications?: Notification[]\n  /** Pass a fixed date, so the block renders the same on the server and in the browser. */\n  now: Date\n  onRead?: (ids: string[]) => void\n  timeZone?: string\n  title: string\n}\n\nconst NOW = new Date(Date.UTC(2026, 8, 26, 15, 0))\nconst minutesAgo = (minutes: number) => new Date(NOW.getTime() - minutes * 60_000)\n\nconst exampleProps: ActivityFeed3Props = {\n  notifications: [\n    {\n      action: 'mentioned you in',\n      actor: { avatar: '/images/avatar-02.webp', name: 'Priya Nair' },\n      at: minutesAgo(3),\n      id: 'n1',\n      mention: true,\n      preview: 'Can you check the copy on the annual plan before we ship?',\n      target: 'Q4 pricing page',\n    },\n    {\n      action: 'assigned you',\n      actor: { name: 'Kenji Watanabe' },\n      at: minutesAgo(26),\n      id: 'n2',\n      target: 'Fix invoice rounding',\n    },\n    {\n      action: 'replied to your comment on',\n      actor: { avatar: '/images/avatar-10.webp', name: 'Mei Tanaka' },\n      at: minutesAgo(80),\n      id: 'n3',\n      preview: 'Good catch, updated the empty state.',\n      target: 'Onboarding flow',\n    },\n    {\n      action: 'mentioned you in',\n      actor: { name: 'Jonah Fischer' },\n      at: minutesAgo(60 * 7),\n      id: 'n4',\n      mention: true,\n      read: true,\n      target: 'Launch plan',\n    },\n    {\n      action: 'shared a file with you',\n      actor: { name: 'Amara Okafor' },\n      at: minutesAgo(60 * 26),\n      id: 'n5',\n      read: true,\n      target: 'Brand guidelines.pdf',\n    },\n  ],\n  now: NOW,\n  title: 'Notifications',\n}\n\ntype Filter = 'all' | 'mentions' | 'unread'\n\nconst describe = (unread: Notification[]) => {\n  if (unread.length === 0) return \"You're all caught up.\"\n  const mentions = unread.filter((item) => item.mention).length\n  const count = `${unread.length} unread`\n  return mentions === 0 ? `${count}.` : `${count}, ${mentions} mentioning you.`\n}\n\nconst ActivityFeed3 = (props: ActivityFeed3Props) => {\n  const {\n    notifications = [],\n    now,\n    onRead,\n    errorMessage,\n    status,\n    timeZone = 'UTC',\n    title,\n  } = props\n  const [filter, setFilter] = useState<Filter>('all')\n  const [markedRead, setMarkedRead] = useState<ReadonlySet<string>>(() => new Set())\n  const state = getBlockState(status, notifications)\n\n  const isRead = (item: Notification) => item.read || markedRead.has(item.id)\n  const unread = notifications.filter((item) => !isRead(item))\n  const markRead = (ids: string[]) => {\n    const fresh = ids.filter((id) => unread.some((item) => item.id === id))\n    if (fresh.length === 0) return\n    setMarkedRead(new Set([...markedRead, ...fresh]))\n    onRead?.(fresh)\n  }\n\n  const filters: { items: Notification[]; label: string; value: Filter }[] = [\n    { items: notifications, label: 'All', value: 'all' },\n    {\n      items: notifications.filter((item) => item.mention),\n      label: 'Mentions',\n      value: 'mentions',\n    },\n    { items: unread, label: 'Unread', value: 'unread' },\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 items-start justify-between gap-3'>\n              <div className='flex min-w-0 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'>{describe(unread)}</p>\n                </BlockReady>\n              </div>\n              <MarkAllReadButton\n                disabled={Boolean(state) || unread.length === 0}\n                onClick={() => markRead(unread.map((item) => item.id))}\n              />\n            </header>\n            <Tabs value={filter} onValueChange={(value) => setFilter(value as Filter)}>\n              <TabsList>\n                {filters.map((item) => (\n                  <TabsTrigger key={item.value} value={item.value}>\n                    {item.label}\n                    {!state && item.value !== 'all' && item.items.length > 0 && (\n                      <Tag>{formatNumber(item.items.length)}</Tag>\n                    )}\n                  </TabsTrigger>\n                ))}\n              </TabsList>\n              {filters.map((item) => (\n                <TabsContent key={item.value} value={item.value} className='mt-2'>\n                  {state ? (\n                    <div className='border-t'>\n                      <BlockStateRows rows={5} />\n                    </div>\n                  ) : item.items.length === 0 ? (\n                    <p className='text-muted-foreground border-t py-8 text-center text-sm'>\n                      {item.value === 'unread'\n                        ? \"You're all caught up.\"\n                        : 'Nothing here yet.'}\n                    </p>\n                  ) : (\n                    <ActivityFeed className='border-t'>\n                      {item.items.map((notification) => {\n                        const isUnread = !isRead(notification)\n                        return (\n                          <ActivityFeedItem\n                            key={notification.id}\n                            className='border-b last:border-b-0'\n                          >\n                            <button\n                              type='button'\n                              onClick={() => markRead([notification.id])}\n                              className='hover:bg-muted/50 focus-visible:ring-ring/50 flex w-full items-start gap-3 px-2 py-3 text-left outline-none focus-visible:ring-[3px]'\n                            >\n                              <PersonAvatar person={notification.actor} />\n                              <span className='flex min-w-0 flex-1 flex-col gap-1'>\n                                <span className='flex items-baseline justify-between gap-3'>\n                                  <span\n                                    className={cn(\n                                      'text-sm',\n                                      !isUnread && 'text-muted-foreground',\n                                    )}\n                                  >\n                                    <span className='font-medium'>\n                                      {notification.actor.name}\n                                    </span>{' '}\n                                    <span className='text-muted-foreground'>\n                                      {notification.action}\n                                    </span>{' '}\n                                    <span className='font-medium'>\n                                      {notification.target}\n                                    </span>\n                                  </span>\n                                  <ActivityTime\n                                    className='tabular-nums'\n                                    date={notification.at}\n                                    now={now}\n                                    timeZone={timeZone}\n                                  />\n                                </span>\n                                {notification.preview && (\n                                  <span className='text-muted-foreground border-l-2 pl-2 text-sm'>\n                                    <span className='line-clamp-2'>\n                                      {notification.preview}\n                                    </span>\n                                  </span>\n                                )}\n                              </span>\n                              <span className='flex h-5 w-2 items-center'>\n                                {isUnread && <UnreadDot />}\n                              </span>\n                            </button>\n                          </ActivityFeedItem>\n                        )\n                      })}\n                    </ActivityFeed>\n                  )}\n                </TabsContent>\n              ))}\n            </Tabs>\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  ActivityFeed3,\n  exampleProps as activityFeed3ExampleProps,\n  type ActivityFeed3Props,\n  type Notification,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/activity-feed/activity-feed-03.tsx"
    }
  ],
  "meta": {
    "shows": "Notifications in All, Mentions and Unread tabs, with each marked read when opened or all at once.",
    "size": "half",
    "usedWith": [
      "activity-feed-01",
      "alerts-01"
    ],
    "component": "ActivityFeed3",
    "props": "{ notifications?: { action: string; actor: { avatar?: string; name: string }; at: Date; id: string; mention?: boolean; preview?: string; read?: boolean; target: string }[]; now: Date; onRead?: (ids: string[]) => void; timeZone?: string; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
