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

---
 .../dashboard/bookmarks/BookmarksGrid.tsx          | 34 ++++++----------------
 1 file changed, 9 insertions(+), 25 deletions(-)

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

diff --git a/apps/web/components/dashboard/bookmarks/BookmarksGrid.tsx b/apps/web/components/dashboard/bookmarks/BookmarksGrid.tsx
index b44dea33..540546fe 100644
--- a/apps/web/components/dashboard/bookmarks/BookmarksGrid.tsx
+++ b/apps/web/components/dashboard/bookmarks/BookmarksGrid.tsx
@@ -11,12 +11,10 @@ import resolveConfig from "tailwindcss/resolveConfig";
 
 import type { ZBookmark } from "@hoarder/shared/types/bookmarks";
 
-import AssetCard from "./AssetCard";
+import BookmarkCard from "./BookmarkCard";
 import EditorCard from "./EditorCard";
-import LinkCard from "./LinkCard";
-import TextCard from "./TextCard";
 
-function BookmarkCard({ children }: { children: React.ReactNode }) {
+function StyledBookmarkCard({ children }: { children: React.ReactNode }) {
   return (
     <Slot className="mb-4 border border-border bg-card duration-300 ease-in hover:shadow-lg hover:transition-all">
       {children}
@@ -36,24 +34,6 @@ function getBreakpointConfig() {
   return breakpointColumnsObj;
 }
 
-function renderBookmark(bookmark: ZBookmark) {
-  let comp;
-  switch (bookmark.content.type) {
-    case "link":
-      comp = <LinkCard bookmark={{ ...bookmark, content: bookmark.content }} />;
-      break;
-    case "text":
-      comp = <TextCard bookmark={{ ...bookmark, content: bookmark.content }} />;
-      break;
-    case "asset":
-      comp = (
-        <AssetCard bookmark={{ ...bookmark, content: bookmark.content }} />
-      );
-      break;
-  }
-  return <BookmarkCard key={bookmark.id}>{comp}</BookmarkCard>;
-}
-
 export default function BookmarksGrid({
   bookmarks,
   hasNextPage = false,
@@ -76,11 +56,15 @@ export default function BookmarksGrid({
 
   const children = [
     showEditorCard && (
-      <BookmarkCard key={"editor"}>
+      <StyledBookmarkCard key={"editor"}>
         <EditorCard />
-      </BookmarkCard>
+      </StyledBookmarkCard>
     ),
-    ...bookmarks.map((b) => renderBookmark(b)),
+    ...bookmarks.map((b) => (
+      <StyledBookmarkCard key={b.id}>
+        <BookmarkCard bookmark={b} />
+      </StyledBookmarkCard>
+    )),
   ];
   return (
     <>
-- 
cgit v1.2.3-70-g09d2

