From 6928800a604f05ef62234cb5c3ee1e60fb27ea1a Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Sun, 9 Jun 2024 21:05:21 +0000
Subject: refactor: Extract the bookmark polling logic into a separate shared
 component

---
 .../components/dashboard/bookmarks/LinkCard.tsx    | 30 +---------------------
 1 file changed, 1 insertion(+), 29 deletions(-)

(limited to 'apps/web/components/dashboard/bookmarks/LinkCard.tsx')

diff --git a/apps/web/components/dashboard/bookmarks/LinkCard.tsx b/apps/web/components/dashboard/bookmarks/LinkCard.tsx
index 1446b031..7212940b 100644
--- a/apps/web/components/dashboard/bookmarks/LinkCard.tsx
+++ b/apps/web/components/dashboard/bookmarks/LinkCard.tsx
@@ -2,13 +2,11 @@
 
 import Image from "next/image";
 import Link from "next/link";
-import { api } from "@/lib/trpc";
 
 import type { ZBookmarkTypeLink } from "@hoarder/shared/types/bookmarks";
 import {
   getBookmarkLinkImageUrl,
   isBookmarkStillCrawling,
-  isBookmarkStillLoading,
 } from "@hoarder/shared-react/utils/bookmarkUtils";
 
 import { BookmarkLayoutAdaptingCard } from "./BookmarkLayoutAdaptingCard";
@@ -80,38 +78,12 @@ function LinkUrl({ bookmark }: { bookmark: ZBookmarkTypeLink }) {
 }
 
 export default function LinkCard({
-  bookmark: initialData,
+  bookmark: bookmarkLink,
   className,
 }: {
   bookmark: ZBookmarkTypeLink;
   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 the link is not crawled or not tagged
-        if (isBookmarkStillLoading(data)) {
-          return 1000;
-        }
-        return false;
-      },
-    },
-  );
-
-  if (bookmark.content.type !== "link") {
-    throw new Error("Invalid bookmark type");
-  }
-
-  const bookmarkLink = { ...bookmark, content: bookmark.content };
-
   return (
     <BookmarkLayoutAdaptingCard
       title={<LinkTitle bookmark={bookmarkLink} />}
-- 
cgit v1.2.3-70-g09d2

