From d6dd76021226802adf5295b3243d6f2ae4fa5cc2 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 10 Mar 2024 17:59:58 +0000 Subject: refactor: Move all components to the top level directory --- .../dashboard/bookmarks/BookmarkPreview.tsx | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 packages/web/components/dashboard/bookmarks/BookmarkPreview.tsx (limited to 'packages/web/components/dashboard/bookmarks/BookmarkPreview.tsx') diff --git a/packages/web/components/dashboard/bookmarks/BookmarkPreview.tsx b/packages/web/components/dashboard/bookmarks/BookmarkPreview.tsx new file mode 100644 index 00000000..2a8ae1b1 --- /dev/null +++ b/packages/web/components/dashboard/bookmarks/BookmarkPreview.tsx @@ -0,0 +1,101 @@ +"use client"; + +import { BackButton } from "@/components/ui/back-button"; +import { Skeleton } from "@/components/ui/skeleton"; +import { isBookmarkStillCrawling } from "@/lib/bookmarkUtils"; +import { api } from "@/lib/trpc"; +import { ZBookmark } from "@hoarder/trpc/types/bookmarks"; +import { ArrowLeftCircle, CalendarDays, ExternalLink } from "lucide-react"; +import Link from "next/link"; +import Markdown from "react-markdown"; + +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 (isBookmarkStillCrawling(data)) { + return 1000; + } + return false; + }, + }, + ); + + const linkHeader = bookmark.content.type == "link" && ( +
+

+ {bookmark.content.title || bookmark.content.url} +

+ + View Original + + +
+ ); + + let content; + switch (bookmark.content.type) { + case "link": { + if (!bookmark.content.htmlContent) { + content = ( +
Failed to fetch link content ...
+ ); + } else { + content = ( +
+ ); + } + break; + } + case "text": { + content = {bookmark.content.text}; + break; + } + } + + return ( +
+
+ + + +
+ + {bookmark.createdAt.toLocaleString()} + +
+
+
+ {linkHeader} +
+ {isBookmarkStillCrawling(bookmark) ? ( +
+ + + +
+ ) : ( + content + )} +
+
+ ); +} -- cgit v1.2.3-70-g09d2