diff options
| author | MohamedBassem <me@mbassem.com> | 2024-03-30 04:45:42 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-03-30 04:54:55 +0000 |
| commit | e99dee0b4f7220568c8ffa2755147bc45d35b32b (patch) | |
| tree | 1b79a6378702c314b814e48b4ff2a4d1eeb7d63f /apps/web/components/dashboard/bookmarks/NoteEditor.tsx | |
| parent | 6902c9467f8ffe0bde225024e73384652ff8d66f (diff) | |
| download | karakeep-e99dee0b4f7220568c8ffa2755147bc45d35b32b.tar.zst | |
feature(web): Add support for attaching notes to bookmarks
Diffstat (limited to 'apps/web/components/dashboard/bookmarks/NoteEditor.tsx')
| -rw-r--r-- | apps/web/components/dashboard/bookmarks/NoteEditor.tsx | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/apps/web/components/dashboard/bookmarks/NoteEditor.tsx b/apps/web/components/dashboard/bookmarks/NoteEditor.tsx new file mode 100644 index 00000000..d712d523 --- /dev/null +++ b/apps/web/components/dashboard/bookmarks/NoteEditor.tsx @@ -0,0 +1,48 @@ +import { Textarea } from "@/components/ui/textarea"; +import { toast } from "@/components/ui/use-toast"; +import { useClientConfig } from "@/lib/clientConfig"; +import { api } from "@/lib/trpc"; + +import type { ZBookmark } from "@hoarder/trpc/types/bookmarks"; + +export function NoteEditor({ bookmark }: { bookmark: ZBookmark }) { + const demoMode = !!useClientConfig().demoMode; + + const invalidateBookmarkCache = + api.useUtils().bookmarks.getBookmark.invalidate; + + const updateBookmarkMutator = api.bookmarks.updateBookmark.useMutation({ + onSuccess: () => { + toast({ + description: "The bookmark has been updated!", + }); + }, + onError: () => { + toast({ + description: "Something went wrong while saving the note", + variant: "destructive", + }); + }, + onSettled: () => { + invalidateBookmarkCache({ bookmarkId: bookmark.id }); + }, + }); + + return ( + <Textarea + className="h-44 w-full overflow-auto rounded bg-background p-2 text-sm text-gray-400 dark:text-gray-300" + defaultValue={bookmark.note ?? ""} + disabled={demoMode} + placeholder="Write some notes ..." + onBlur={(e) => { + if (e.currentTarget.value == bookmark.note) { + return; + } + updateBookmarkMutator.mutate({ + bookmarkId: bookmark.id, + note: e.currentTarget.value, + }); + }} + /> + ); +} |
