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/AssetCard.tsx   | 36 ++--------------------
 1 file changed, 3 insertions(+), 33 deletions(-)

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

diff --git a/apps/web/components/dashboard/bookmarks/AssetCard.tsx b/apps/web/components/dashboard/bookmarks/AssetCard.tsx
index f110e0c4..c235e4c8 100644
--- a/apps/web/components/dashboard/bookmarks/AssetCard.tsx
+++ b/apps/web/components/dashboard/bookmarks/AssetCard.tsx
@@ -2,14 +2,9 @@
 
 import Image from "next/image";
 import Link from "next/link";
-import { api } from "@/lib/trpc";
 
-import type {
-  ZBookmark,
-  ZBookmarkTypeAsset,
-} from "@hoarder/shared/types/bookmarks";
+import type { ZBookmarkTypeAsset } from "@hoarder/shared/types/bookmarks";
 import { getAssetUrl } from "@hoarder/shared-react/utils/assetUtils";
-import { isBookmarkStillTagging } from "@hoarder/shared-react/utils/bookmarkUtils";
 
 import { BookmarkLayoutAdaptingCard } from "./BookmarkLayoutAdaptingCard";
 
@@ -51,37 +46,12 @@ function AssetImage({
 }
 
 export default function AssetCard({
-  bookmark: initialData,
+  bookmark: bookmarkedAsset,
   className,
 }: {
-  bookmark: ZBookmark;
+  bookmark: ZBookmarkTypeAsset;
   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 (isBookmarkStillTagging(data)) {
-          return 1000;
-        }
-        return false;
-      },
-    },
-  );
-
-  if (bookmark.content.type != "asset") {
-    throw new Error("Unexpected bookmark type");
-  }
-
-  const bookmarkedAsset = { ...bookmark, content: bookmark.content };
-
   return (
     <BookmarkLayoutAdaptingCard
       title={bookmarkedAsset.title ?? bookmarkedAsset.content.fileName}
-- 
cgit v1.2.3-70-g09d2

