"use client";
import { useEffect, useState } from "react";
import Link from "next/link";
import { TagsEditor } from "@/components/dashboard/bookmarks/TagsEditor";
import { Separator } from "@/components/ui/separator";
import { Skeleton } from "@/components/ui/skeleton";
import {
Tooltip,
TooltipContent,
TooltipPortal,
TooltipTrigger,
} from "@/components/ui/tooltip";
import {
isBookmarkStillCrawling,
isBookmarkStillLoading,
} from "@/lib/bookmarkUtils";
import { api } from "@/lib/trpc";
import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";
import { CalendarDays, ExternalLink } from "lucide-react";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";
import ActionBar from "./ActionBar";
import { AssetContentSection } from "./AssetContentSection";
import { EditableTitle } from "./EditableTitle";
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({
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 (isBookmarkStillLoading(data)) {
return 1000;
}
return false;
},
},
);
let content;
switch (bookmark.content.type) {
case "link":
case "text": {
content = ;
break;
}
case "asset": {
content = ;
break;
}
}
return (
{isBookmarkStillCrawling(bookmark) ? : content}
{bookmark.content.type == "link" && (
View Original
)}
);
}