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/TextCard.tsx    | 29 +++-------------------
 1 file changed, 3 insertions(+), 26 deletions(-)

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

diff --git a/apps/web/components/dashboard/bookmarks/TextCard.tsx b/apps/web/components/dashboard/bookmarks/TextCard.tsx
index b18efc3d..ffaa18a4 100644
--- a/apps/web/components/dashboard/bookmarks/TextCard.tsx
+++ b/apps/web/components/dashboard/bookmarks/TextCard.tsx
@@ -2,46 +2,23 @@
 
 import { useState } from "react";
 import { MarkdownComponent } from "@/components/ui/markdown-component";
-import { api } from "@/lib/trpc";
 import { bookmarkLayoutSwitch } from "@/lib/userLocalSettings/bookmarksLayout";
 import { cn } from "@/lib/utils";
 
-import type { ZBookmark } from "@hoarder/shared/types/bookmarks";
-import { isBookmarkStillTagging } from "@hoarder/shared-react/utils/bookmarkUtils";
+import type { ZBookmarkTypeText } from "@hoarder/shared/types/bookmarks";
 
 import { BookmarkedTextViewer } from "./BookmarkedTextViewer";
 import { BookmarkLayoutAdaptingCard } from "./BookmarkLayoutAdaptingCard";
 
 export default function TextCard({
-  bookmark: initialData,
+  bookmark,
   className,
 }: {
-  bookmark: ZBookmark;
+  bookmark: ZBookmarkTypeText;
   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;
-      },
-    },
-  );
   const [previewModalOpen, setPreviewModalOpen] = useState(false);
   const bookmarkedText = bookmark.content;
-  if (bookmarkedText.type != "text") {
-    throw new Error("Unexpected bookmark type");
-  }
 
   return (
     <>
-- 
cgit v1.2.3-70-g09d2

