diff options
| author | MohamedBassem <me@mbassem.com> | 2024-06-09 21:05:21 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-06-09 21:05:21 +0000 |
| commit | 6928800a604f05ef62234cb5c3ee1e60fb27ea1a (patch) | |
| tree | 4c0f7c395a25b6db23f6cc6a4fc9c65c6f5ee1a4 /apps/web/components/dashboard/bookmarks/BookmarkCard.tsx | |
| parent | 546139e82f151b35d6492b7cbf2ac89dbfd5d0b5 (diff) | |
| download | karakeep-6928800a604f05ef62234cb5c3ee1e60fb27ea1a.tar.zst | |
refactor: Extract the bookmark polling logic into a separate shared component
Diffstat (limited to 'apps/web/components/dashboard/bookmarks/BookmarkCard.tsx')
| -rw-r--r-- | apps/web/components/dashboard/bookmarks/BookmarkCard.tsx | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/apps/web/components/dashboard/bookmarks/BookmarkCard.tsx b/apps/web/components/dashboard/bookmarks/BookmarkCard.tsx new file mode 100644 index 00000000..76316de7 --- /dev/null +++ b/apps/web/components/dashboard/bookmarks/BookmarkCard.tsx @@ -0,0 +1,59 @@ +import { api } from "@/lib/trpc"; + +import type { ZBookmark } from "@hoarder/shared/types/bookmarks"; +import { isBookmarkStillLoading } from "@hoarder/shared-react/utils/bookmarkUtils"; + +import AssetCard from "./AssetCard"; +import LinkCard from "./LinkCard"; +import TextCard from "./TextCard"; + +export default function BookmarkCard({ + bookmark: initialData, + className, +}: { + bookmark: ZBookmark; + className?: string; +}) { + const { data: bookmark } = api.bookmarks.getBookmark.useQuery( + { + bookmarkId: initialData.id, + }, + { + initialData, + refetchInterval: (query) => { + const data = query.state.data; + if (!data) { + return false; + } + if (isBookmarkStillLoading(data)) { + return 1000; + } + return false; + }, + }, + ); + + switch (bookmark.content.type) { + case "link": + return ( + <LinkCard + className={className} + bookmark={{ ...bookmark, content: bookmark.content }} + /> + ); + case "text": + return ( + <TextCard + className={className} + bookmark={{ ...bookmark, content: bookmark.content }} + /> + ); + case "asset": + return ( + <AssetCard + className={className} + bookmark={{ ...bookmark, content: bookmark.content }} + /> + ); + } +} |
