From 6928800a604f05ef62234cb5c3ee1e60fb27ea1a Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 9 Jun 2024 21:05:21 +0000 Subject: refactor: Extract the bookmark polling logic into a separate shared component --- .../dashboard/bookmarks/BookmarkCard.tsx | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 apps/web/components/dashboard/bookmarks/BookmarkCard.tsx (limited to 'apps/web/components/dashboard/bookmarks/BookmarkCard.tsx') 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 ( + + ); + case "text": + return ( + + ); + case "asset": + return ( + + ); + } +} -- cgit v1.2.3-70-g09d2