blob: e7fea2c32b54cba7777a896a92dd6e95b4e7ab8c (
plain) (
blame)
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
|
import MarkdownEditor from "@/components/ui/markdown/markdown-editor";
import { MarkdownReadonly } from "@/components/ui/markdown/markdown-readonly";
import { toast } from "@/components/ui/use-toast";
import { useUpdateBookmark } from "@karakeep/shared-react/hooks/bookmarks";
export function BookmarkMarkdownComponent({
children: bookmark,
readOnly = true,
}: {
children: {
id: string;
content: {
text: string;
};
};
readOnly?: boolean;
}) {
const { mutate: updateBookmarkMutator, isPending } = useUpdateBookmark({
onSuccess: () => {
toast({
description: "Note updated!",
});
},
onError: () => {
toast({ description: "Something went wrong", variant: "destructive" });
},
});
const onSave = (text: string) => {
updateBookmarkMutator({
bookmarkId: bookmark.id,
text,
});
};
return (
<div className="h-full">
{readOnly ? (
<MarkdownReadonly onSave={onSave}>
{bookmark.content.text}
</MarkdownReadonly>
) : (
<MarkdownEditor onSave={onSave} isSaving={isPending}>
{bookmark.content.text}
</MarkdownEditor>
)}
</div>
);
}
|