From 04572a8e5081b1e4871e273cde9dbaaa44c52fe0 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Wed, 13 Mar 2024 21:43:44 +0000 Subject: structure: Create apps dir and copy tooling dir from t3-turbo repo --- .../dashboard/bookmarks/BookmarkPreview.tsx | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 apps/web/components/dashboard/bookmarks/BookmarkPreview.tsx (limited to 'apps/web/components/dashboard/bookmarks/BookmarkPreview.tsx') diff --git a/apps/web/components/dashboard/bookmarks/BookmarkPreview.tsx b/apps/web/components/dashboard/bookmarks/BookmarkPreview.tsx new file mode 100644 index 00000000..2a8ae1b1 --- /dev/null +++ b/apps/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