1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
"use client";
import { ZBookmark } from "@/lib/types/api/bookmarks";
import BookmarkOptions from "./BookmarkOptions";
import { api } from "@/lib/trpc";
import { Maximize2, Star } from "lucide-react";
import { cn } from "@/lib/utils";
import TagList from "./TagList";
import Markdown from "react-markdown";
import { useState } from "react";
import { BookmarkedTextViewer } from "./BookmarkedTextViewer";
import { Button } from "@/components/ui/button";
import Link from "next/link";
function isStillTagging(bookmark: ZBookmark) {
return (
bookmark.taggingStatus == "pending" &&
Date.now().valueOf() - bookmark.createdAt.valueOf() < 30 * 1000
);
}
export default function TextCard({
bookmark: initialData,
className,
}: {
bookmark: ZBookmark;
className?: string;
}) {
const { data: bookmark } = api.bookmarks.getBookmark.useQuery(
{
bookmarkId: initialData.id,
},
{
initialData,
refetchInterval: (query) => {
const data = query.state.data;
if (!data) {
return false;
}
if (isStillTagging(data)) {
return 1000;
}
return false;
},
},
);
const [previewModalOpen, setPreviewModalOpen] = useState(false);
const bookmarkedText = bookmark.content;
if (bookmarkedText.type != "text") {
throw new Error("Unexpected bookmark type");
}
return (
<>
<BookmarkedTextViewer
content={bookmarkedText.text}
open={previewModalOpen}
setOpen={setPreviewModalOpen}
/>
<div
className={cn(
className,
cn(
"flex h-min max-h-96 flex-col gap-y-1 overflow-hidden rounded-lg p-2 shadow-md",
),
)}
>
<Markdown className="prose grow overflow-hidden">
{bookmarkedText.text}
</Markdown>
<div className="mt-4 flex flex-none flex-wrap gap-1 overflow-hidden">
<TagList bookmark={bookmark} loading={isStillTagging(bookmark)} />
</div>
<div className="flex w-full justify-between">
<div />
<div className="flex gap-0 text-gray-500">
<div>
{bookmark.favourited && (
<Star
className="my-1 size-8 rounded p-1"
color="#ebb434"
fill="#ebb434"
/>
)}
</div>
<Link
className="my-auto block px-2"
href={`/dashboard/preview/${bookmark.id}`}
>
<Maximize2 size="20" />
</Link>
<BookmarkOptions bookmark={bookmark} />
</div>
</div>
</div>
</>
);
}
|