"use client"; import { useEffect, useState } from "react"; 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 { api } from "@/lib/trpc"; import dayjs from "dayjs"; import relativeTime from "dayjs/plugin/relativeTime"; 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 LinkContentSection from "./LinkContentSection"; import { NoteEditor } from "./NoteEditor"; import { TextContentSection } from "./TextContentSection"; dayjs.extend(relativeTime); function ContentLoading() { return (
); } function CreationTime({ createdAt }: { createdAt: Date }) { const [fromNow, setFromNow] = useState(""); const [localCreatedAt, setLocalCreatedAt] = useState(""); // This is to avoid hydration errors when server and clients are in different timezones useEffect(() => { setFromNow(dayjs(createdAt).fromNow()); setLocalCreatedAt(createdAt.toLocaleString()); }, [createdAt]); return ( {fromNow} {localCreatedAt} ); } export default function BookmarkPreview({ bookmarkId, initialData, }: { bookmarkId: string; initialData?: ZBookmark; }) { 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 && ( View Original )}

Tags

Note

); }