"use client"; import Link from "next/link"; import { BookmarkTagsEditor } from "@/components/dashboard/bookmarks/BookmarkTagsEditor"; import { FullPageSpinner } from "@/components/ui/full-page-spinner"; import { Separator } from "@/components/ui/separator"; import { Skeleton } from "@/components/ui/skeleton"; import { Tooltip, TooltipContent, TooltipPortal, TooltipTrigger, } from "@/components/ui/tooltip"; import useRelativeTime from "@/lib/hooks/relative-time"; import { useTranslation } from "@/lib/i18n/client"; import { api } from "@/lib/trpc"; import { CalendarDays, ExternalLink } from "lucide-react"; import { getSourceUrl, isBookmarkStillCrawling, isBookmarkStillLoading, } from "@hoarder/shared-react/utils/bookmarkUtils"; import { BookmarkTypes, ZBookmark } from "@hoarder/shared/types/bookmarks"; import SummarizeBookmarkArea from "../bookmarks/SummarizeBookmarkArea"; import ActionBar from "./ActionBar"; import { AssetContentSection } from "./AssetContentSection"; import AttachmentBox from "./AttachmentBox"; import { EditableTitle } from "./EditableTitle"; import HighlightsBox from "./HighlightsBox"; import LinkContentSection from "./LinkContentSection"; import { NoteEditor } from "./NoteEditor"; import { TextContentSection } from "./TextContentSection"; function ContentLoading() { return (
); } function CreationTime({ createdAt }: { createdAt: Date }) { const { fromNow, localCreatedAt } = useRelativeTime(createdAt); return ( {fromNow} {localCreatedAt} ); } export default function BookmarkPreview({ bookmarkId, initialData, }: { bookmarkId: string; initialData?: ZBookmark; }) { const { t } = useTranslation(); const { data: bookmark } = api.bookmarks.getBookmark.useQuery( { bookmarkId, }, { 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; }, }, ); if (!bookmark) { return ; } let content; switch (bookmark.content.type) { case BookmarkTypes.LINK: { content = ; break; } case BookmarkTypes.TEXT: { content = ; break; } case BookmarkTypes.ASSET: { content = ; break; } } const sourceUrl = getSourceUrl(bookmark); return (
{isBookmarkStillCrawling(bookmark) ? : content}
{sourceUrl && ( {t("preview.view_original")} )}

{t("common.tags")}

{t("common.note")}

); }