From 79d61be7e15dc5d23fb687a5f71e0097088a99ac Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Sun, 7 Apr 2024 18:30:00 +0100
Subject: feature: Extract hook logic into separate package and add a new
 action bar in bookmark preview

---
 .../components/dashboard/preview/NoteEditor.tsx    | 42 ++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 apps/web/components/dashboard/preview/NoteEditor.tsx

(limited to 'apps/web/components/dashboard/preview/NoteEditor.tsx')

diff --git a/apps/web/components/dashboard/preview/NoteEditor.tsx b/apps/web/components/dashboard/preview/NoteEditor.tsx
new file mode 100644
index 00000000..6011e89d
--- /dev/null
+++ b/apps/web/components/dashboard/preview/NoteEditor.tsx
@@ -0,0 +1,42 @@
+import { Textarea } from "@/components/ui/textarea";
+import { toast } from "@/components/ui/use-toast";
+import { useClientConfig } from "@/lib/clientConfig";
+
+import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
+import { useUpdateBookmark } from "@hoarder/shared-react/hooks/bookmarks";
+
+export function NoteEditor({ bookmark }: { bookmark: ZBookmark }) {
+  const demoMode = !!useClientConfig().demoMode;
+
+  const updateBookmarkMutator = useUpdateBookmark({
+    onSuccess: () => {
+      toast({
+        description: "The bookmark has been updated!",
+      });
+    },
+    onError: () => {
+      toast({
+        description: "Something went wrong while saving the note",
+        variant: "destructive",
+      });
+    },
+  });
+
+  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,
+        });
+      }}
+    />
+  );
+}
-- 
cgit v1.2.3-70-g09d2

