{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pull-refresh-feed",
  "title": "Pull Refresh Feed",
  "description": "A news feed that refreshes on pull or on the Refresh button, prepends new items with a \"2 new stories\" announcement and keeps the reading position when nothing changed. Use this when a phone feed has fresh content on a server and people expect to pull to update it.",
  "registryDependencies": [
    "@tealmac/pull-to-refresh"
  ],
  "files": [
    {
      "path": "registry/patterns/pull-refresh-feed/pull-refresh-feed.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { PullToRefresh } from \"@/components/ui/pull-to-refresh\"\n\nexport interface Story {\n  id: string\n  title: string\n}\n\nexport interface PullRefreshFeedProps {\n  initial: Story[]\n  load: () => Promise<Story[]>\n}\n\nexport function PullRefreshFeed({ initial, load }: PullRefreshFeedProps) {\n  const [stories, setStories] = React.useState(initial)\n  const [fresh, setFresh] = React.useState<Set<string>>(new Set())\n  const [announce, setAnnounce] = React.useState(\"\")\n\n  const refresh = async () => {\n    const incoming = await load()\n    const known = new Set(stories.map((s) => s.id))\n    const added = incoming.filter((s) => !known.has(s.id))\n    if (added.length) {\n      setStories([...added, ...stories])\n      setFresh(new Set(added.map((s) => s.id)))\n    }\n    setAnnounce(\n      added.length\n        ? `${added.length} new ${added.length === 1 ? \"story\" : \"stories\"}`\n        : \"You are up to date\"\n    )\n  }\n\n  return (\n    <div>\n      <PullToRefresh\n        onRefresh={refresh}\n        className=\"h-72 w-full rounded-xl border\"\n      >\n        <ul className=\"divide-y px-4\">\n          {stories.map((story) => (\n            <li\n              key={story.id}\n              className=\"flex items-center justify-between gap-2 py-4\"\n            >\n              {story.title}\n              {fresh.has(story.id) && (\n                <span className=\"bg-primary text-primary-foreground rounded-full px-2 text-xs\">\n                  New\n                </span>\n              )}\n            </li>\n          ))}\n        </ul>\n      </PullToRefresh>\n      <p role=\"status\" className=\"sr-only\">\n        {announce}\n      </p>\n    </div>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}