From 79d61be7e15dc5d23fb687a5f71e0097088a99ac Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 7 Apr 2024 18:30:00 +0100 Subject: feature: Extract hook logic into separate package and add a new action bar in bookmark preview --- .../dashboard/preview/BookmarkPreview.tsx | 154 +++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 apps/web/components/dashboard/preview/BookmarkPreview.tsx (limited to 'apps/web/components/dashboard/preview/BookmarkPreview.tsx') diff --git a/apps/web/components/dashboard/preview/BookmarkPreview.tsx b/apps/web/components/dashboard/preview/BookmarkPreview.tsx new file mode 100644 index 00000000..bd7881a3 --- /dev/null +++ b/apps/web/components/dashboard/preview/BookmarkPreview.tsx @@ -0,0 +1,154 @@ +"use client"; + +import Link from "next/link"; +import { TagsEditor } from "@/components/dashboard/bookmarks/TagsEditor"; +import { Separator } from "@/components/ui/separator"; +import { Skeleton } from "@/components/ui/skeleton"; +import { + Tooltip, + TooltipContent, + TooltipPortal, + TooltipProvider, + TooltipTrigger, +} from "@/components/ui/tooltip"; +import { + isBookmarkStillCrawling, + isBookmarkStillLoading, +} from "@/lib/bookmarkUtils"; +import { api } from "@/lib/trpc"; +import dayjs from "dayjs"; +import relativeTime from "dayjs/plugin/relativeTime"; +import { CalendarDays, ExternalLink } from "lucide-react"; + +import type { ZBookmark } from "@hoarder/trpc/types/bookmarks"; + +import ActionBar from "./ActionBar"; +import { AssetContentSection } from "./AssetContentSection"; +import { NoteEditor } from "./NoteEditor"; +import { TextContentSection } from "./TextContentSection"; + +dayjs.extend(relativeTime); + +function ContentLoading() { + return ( +
+ + + +
+ ); +} + +function CreationTime({ createdAt }: { createdAt: Date }) { + return ( + + + + + {dayjs(createdAt).fromNow()} + + + + {createdAt.toLocaleString()} + + + + ); +} + +function LinkHeader({ bookmark }: { bookmark: ZBookmark }) { + if (bookmark.content.type !== "link") { + throw new Error("Unexpected content type"); + } + + const title = bookmark.content.title ?? bookmark.content.url; + + return ( +
+ + + +

{title}

+
+ + + {title} + + +
+
+ + View Original + + + +
+ ); +} + +export default function BookmarkPreview({ + initialData, +}: { + initialData: ZBookmark; +}) { + const { data: bookmark } = api.bookmarks.getBookmark.useQuery( + { + bookmarkId: initialData.id, + }, + { + initialData, + refetchInterval: (query) => { + const data = query.state.data; + if (!data) { + return false; + } + // If the link is not crawled or not tagged + if (isBookmarkStillLoading(data)) { + return 1000; + } + return false; + }, + }, + ); + + let content; + switch (bookmark.content.type) { + case "link": + case "text": { + content = ; + break; + } + case "asset": { + content = ; + break; + } + } + + const linkHeader = bookmark.content.type == "link" && ( + + ); + + return ( +
+
+ {isBookmarkStillCrawling(bookmark) ? : content} +
+
+ {linkHeader} + +
+

Tags

+ +
+
+

Note

+ +
+ +
+
+ ); +} -- cgit v1.2.3-70-g09d2