mirror of https://github.com/usememos/memos.git
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:
parent
f9bf903eea
commit
e7605d90da
|
|
@ -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({
|
||||
|
|
|
|||
Loading…
Reference in New Issue