From f53ad0a1bf373e4064ff3e142bfce4b27e4ef9d5 Mon Sep 17 00:00:00 2001 From: Adrian-Ryan Acala Date: Sat, 7 Jun 2025 08:29:50 -0700 Subject: 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 --- .../web/components/dashboard/bookmarks/EditBookmarkDialog.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 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 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; -- cgit v1.2.3-70-g09d2