From a4d5be3a3a031c039568b5cb4e7e2305f8e4f283 Mon Sep 17 00:00:00 2001
From: Mohamed Bassem <me@mbassem.com>
Date: Sun, 13 Apr 2025 14:04:39 +0000
Subject: feat: Allow editing the extracted content of an asset bookmark

---
 .../dashboard/bookmarks/EditBookmarkDialog.tsx     | 35 ++++++++++++++++++----
 1 file changed, 30 insertions(+), 5 deletions(-)

(limited to 'apps/web/components/dashboard/bookmarks/EditBookmarkDialog.tsx')

diff --git a/apps/web/components/dashboard/bookmarks/EditBookmarkDialog.tsx b/apps/web/components/dashboard/bookmarks/EditBookmarkDialog.tsx
index c7745acd..ab5d0364 100644
--- a/apps/web/components/dashboard/bookmarks/EditBookmarkDialog.tsx
+++ b/apps/web/components/dashboard/bookmarks/EditBookmarkDialog.tsx
@@ -35,6 +35,7 @@ import { CalendarIcon } from "lucide-react";
 import { useForm } from "react-hook-form";
 
 import { useUpdateBookmark } from "@karakeep/shared-react/hooks/bookmarks";
+import { getBookmarkTitle } from "@karakeep/shared-react/utils/bookmarkUtils";
 import {
   BookmarkTypes,
   ZBookmark,
@@ -61,11 +62,7 @@ export function EditBookmarkDialog({
   const bookmarkToDefault = (bookmark: ZBookmark) => ({
     bookmarkId: bookmark.id,
     summary: bookmark.summary,
-    title: bookmark.title
-      ? bookmark.title
-      : bookmark.content.type === BookmarkTypes.LINK
-        ? bookmark.content.title
-        : undefined,
+    title: getBookmarkTitle(bookmark),
     createdAt: bookmark.createdAt ?? new Date(),
     // Link specific defaults (only if bookmark is a link)
     url:
@@ -88,6 +85,11 @@ export function EditBookmarkDialog({
       bookmark.content.type === BookmarkTypes.LINK
         ? bookmark.content.datePublished
         : undefined,
+    // Asset specific fields
+    assetContent:
+      bookmark.content.type === BookmarkTypes.ASSET
+        ? bookmark.content.content
+        : undefined,
   });
 
   const form = useForm<ZUpdateBookmarksRequest>({
@@ -130,6 +132,7 @@ export function EditBookmarkDialog({
   }, [bookmark, form, open]);
 
   const isLink = bookmark.content.type === BookmarkTypes.LINK;
+  const isAsset = bookmark.content.type === BookmarkTypes.ASSET;
 
   return (
     <Dialog open={open} onOpenChange={setOpen}>
@@ -215,6 +218,28 @@ export function EditBookmarkDialog({
               />
             )}
 
+            {isAsset && (
+              <FormField
+                control={form.control}
+                name="assetContent"
+                render={({ field }) => (
+                  <FormItem>
+                    <FormLabel>
+                      {t("bookmark_editor.extracted_content")}
+                    </FormLabel>
+                    <FormControl>
+                      <Textarea
+                        placeholder="Extracted Content"
+                        {...field}
+                        value={field.value ?? ""}
+                      />
+                    </FormControl>
+                    <FormMessage />
+                  </FormItem>
+                )}
+              />
+            )}
+
             {isLink && (
               <div className="grid grid-cols-1 gap-4 md:grid-cols-2">
                 <FormField
-- 
cgit v1.2.3-70-g09d2

