diff options
| author | MohamedBassem <me@mbassem.com> | 2024-06-09 21:05:21 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-06-09 21:05:21 +0000 |
| commit | 6928800a604f05ef62234cb5c3ee1e60fb27ea1a (patch) | |
| tree | 4c0f7c395a25b6db23f6cc6a4fc9c65c6f5ee1a4 /apps/web/components/dashboard/bookmarks/BookmarksGrid.tsx | |
| parent | 546139e82f151b35d6492b7cbf2ac89dbfd5d0b5 (diff) | |
| download | karakeep-6928800a604f05ef62234cb5c3ee1e60fb27ea1a.tar.zst | |
refactor: Extract the bookmark polling logic into a separate shared component
Diffstat (limited to 'apps/web/components/dashboard/bookmarks/BookmarksGrid.tsx')
| -rw-r--r-- | apps/web/components/dashboard/bookmarks/BookmarksGrid.tsx | 34 |
1 files changed, 9 insertions, 25 deletions
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 ( <> |
