diff options
| author | Adrian-Ryan Acala <github@adrianacala.com> | 2025-06-07 08:29:50 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-07 16:29:50 +0100 |
| commit | f53ad0a1bf373e4064ff3e142bfce4b27e4ef9d5 (patch) | |
| tree | d6c73b00fdfe19ee7f4d30b3a9481a5c72fc240d /apps/web/components/dashboard/bookmarks | |
| parent | 090c0d1c3c1b6bf2f569eb4c9e1164523f048319 (diff) | |
| download | karakeep-f53ad0a1bf373e4064ff3e142bfce4b27e4ef9d5.tar.zst | |
fix: preserve unsaved title changes when modifying bookmark tags in the edit dialog (#1515)
* feat: preserve unsaved title changes when modifying bookmark tags
Prevents loss of unsaved title edits when users interact with tag
selectors or other UI elements. Adds useDialogFormReset hook to
maintain form state consistency across component re-renders.
Fixes #1339
* Revert unnecessary modifications
---------
Co-authored-by: Mohamed Bassem <me@mbassem.com>
Diffstat (limited to 'apps/web/components/dashboard/bookmarks')
| -rw-r--r-- | apps/web/components/dashboard/bookmarks/EditBookmarkDialog.tsx | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/apps/web/components/dashboard/bookmarks/EditBookmarkDialog.tsx b/apps/web/components/dashboard/bookmarks/EditBookmarkDialog.tsx index f0ede24e..021a7b05 100644 --- a/apps/web/components/dashboard/bookmarks/EditBookmarkDialog.tsx +++ b/apps/web/components/dashboard/bookmarks/EditBookmarkDialog.tsx @@ -27,6 +27,7 @@ import { } from "@/components/ui/popover"; import { Textarea } from "@/components/ui/textarea"; import { toast } from "@/components/ui/use-toast"; +import { useDialogFormReset } from "@/lib/hooks/useDialogFormReset"; import { useTranslation } from "@/lib/i18n/client"; import { cn } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; @@ -124,12 +125,10 @@ export function EditBookmarkDialog({ updateBookmarkMutate(payload); } - // Reset form when bookmark data changes externally or dialog reopens - React.useEffect(() => { - if (open) { - form.reset(bookmarkToDefault(bookmark)); - } - }, [bookmark, form, open]); + // Reset form only when dialog is initially opened to preserve unsaved changes + // This prevents losing unsaved title edits when tags are updated, which would + // cause the bookmark prop to change and trigger a form reset + useDialogFormReset(open, form, bookmarkToDefault(bookmark)); const isLink = bookmark.content.type === BookmarkTypes.LINK; const isAsset = bookmark.content.type === BookmarkTypes.ASSET; |
