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) --- .../bookmarks/BookmarkLayoutAdaptingCard.tsx | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx (limited to 'apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx') diff --git a/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx b/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx new file mode 100644 index 00000000..3d7b93f3 --- /dev/null +++ b/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx @@ -0,0 +1,131 @@ +import type { BookmarksLayoutTypes } from "@/lib/userLocalSettings/types"; +import React from "react"; +import Link from "next/link"; +import { isBookmarkStillTagging } from "@/lib/bookmarkUtils"; +import { + bookmarkLayoutSwitch, + useBookmarkLayout, +} from "@/lib/userLocalSettings/bookmarksLayout"; +import { cn } from "@/lib/utils"; +import dayjs from "dayjs"; + +import type { ZBookmark } from "@hoarder/trpc/types/bookmarks"; + +import BookmarkActionBar from "./BookmarkActionBar"; +import TagList from "./TagList"; + +interface Props { + bookmark: ZBookmark; + image: (layout: BookmarksLayoutTypes, className: string) => React.ReactNode; + title?: React.ReactNode; + content?: React.ReactNode; + footer?: React.ReactNode; + className?: string; + fitHeight?: boolean; + wrapTags: boolean; +} + +function BottomRow({ + footer, + bookmark, +}: { + footer?: React.ReactNode; + bookmark: ZBookmark; +}) { + return ( +
+
+ {footer && <>{footer}•} + + {dayjs(bookmark.createdAt).format("MMM DD")} + +
+ +
+ ); +} + +function ListView({ + bookmark, + image, + title, + content, + footer, + className, +}: Props) { + return ( +
+
+ {image("list", "object-cover rounded-lg size-32")} +
+
+
+ {title &&
{title}
} + {content &&
{content}
} +
+ +
+
+ +
+
+ ); +} + +function GridView({ + bookmark, + image, + title, + content, + footer, + className, + wrapTags, + layout, + fitHeight = false, +}: Props & { layout: BookmarksLayoutTypes }) { + const img = image("grid", "h-56 min-h-56 w-full object-cover rounded-t-lg"); + + return ( +
+ {img &&
{img}
} +
+
+ {title &&
{title}
} + {content &&
{content}
} +
+ +
+
+ +
+
+ ); +} + +export function BookmarkLayoutAdaptingCard(props: Props) { + const layout = useBookmarkLayout(); + + return bookmarkLayoutSwitch(layout, { + masonry: , + grid: , + list: , + }); +} -- cgit v1.3-1-g0d28