fix: shortcut edit button opens create dialog instead of edit dialog

Fixed issue #5576 where clicking the edit button on a shortcut would
incorrectly open a create dialog instead of an edit dialog.

The root cause was an incorrect useEffect that was watching the shortcut
state itself instead of the initialShortcut prop. When the dialog was
opened for editing, the state wasn't properly reinitializing with the
existing shortcut data.

Changed the useEffect to:
- Watch initialShortcut as the dependency
- Reinitialize the shortcut state when initialShortcut changes
- Properly distinguishes between create (initialShortcut undefined) and
  edit (initialShortcut has data) modes
This commit is contained in:
Steven 2026-02-04 20:03:53 +08:00
parent f9bf903eea
commit e7605d90da
1 changed files with 8 additions and 4 deletions

View File

@ -37,10 +37,14 @@ function CreateShortcutDialog({ open, onOpenChange, shortcut: initialShortcut, o
const isCreating = shortcut.name === "";
useEffect(() => {
if (shortcut.name) {
setShortcut(shortcut);
}
}, [shortcut.name, shortcut.title, shortcut.filter]);
setShortcut(
create(ShortcutSchema, {
name: initialShortcut?.name || "",
title: initialShortcut?.title || "",
filter: initialShortcut?.filter || "",
}),
);
}, [initialShortcut]);
const onShortcutTitleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setPartialState({