"use client"; import Image from "next/image"; import Link from "next/link"; import { BackButton } from "@/components/ui/back-button"; import { Skeleton } from "@/components/ui/skeleton"; import { isBookmarkStillCrawling } from "@/lib/bookmarkUtils"; import { api } from "@/lib/trpc"; import { ArrowLeftCircle, CalendarDays, ExternalLink } from "lucide-react"; import Markdown from "react-markdown"; import type { ZBookmark } from "@hoarder/trpc/types/bookmarks"; 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; } case "asset": { switch (bookmark.content.assetType) { case "image": { content = (
asset
); } } break; } } return (
{bookmark.createdAt.toLocaleString()}

{linkHeader}
{isBookmarkStillCrawling(bookmark) ? (
) : ( content )}
); }