From 4f17ea61cbb11a72712a1ea8c98904a1cc513e41 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 14 Apr 2024 00:51:56 +0300 Subject: feature(web): Allow changing the bookmark grid layout (#98) --- .../dashboard/bookmarks/BookmarksGrid.tsx | 44 ++++++++++++++++------ 1 file changed, 33 insertions(+), 11 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 bace3435..01f18815 100644 --- a/apps/web/components/dashboard/bookmarks/BookmarksGrid.tsx +++ b/apps/web/components/dashboard/bookmarks/BookmarksGrid.tsx @@ -1,5 +1,9 @@ import { useMemo } from "react"; import { ActionButton } from "@/components/ui/action-button"; +import { + bookmarkLayoutSwitch, + useBookmarkLayout, +} from "@/lib/userLocalSettings/bookmarksLayout"; import tailwindConfig from "@/tailwind.config"; import { Slot } from "@radix-ui/react-slot"; import Masonry from "react-masonry-css"; @@ -36,13 +40,15 @@ function renderBookmark(bookmark: ZBookmark) { let comp; switch (bookmark.content.type) { case "link": - comp = ; + comp = ; break; case "text": - comp = ; + comp = ; break; case "asset": - comp = ; + comp = ( + + ); break; } return {comp}; @@ -61,20 +67,36 @@ export default function BookmarksGrid({ isFetchingNextPage?: boolean; fetchNextPage?: () => void; }) { + const layout = useBookmarkLayout(); const breakpointConfig = useMemo(() => getBreakpointConfig(), []); + if (bookmarks.length == 0 && !showEditorCard) { return

No bookmarks

; } + + const children = [ + showEditorCard && ( + + + + ), + ...bookmarks.map((b) => renderBookmark(b)), + ]; return ( <> - - {showEditorCard && ( - - - - )} - {bookmarks.map((b) => renderBookmark(b))} - + {bookmarkLayoutSwitch(layout, { + masonry: ( + + {children} + + ), + grid: ( + + {children} + + ), + list:
{children}
, + })} {hasNextPage && (