mirror of
https://github.com/jsmorabito/obsidian-commander.git
synced 2026-07-22 06:40:31 +00:00
fix: replace this.forceUpdate() with useState rerender in MacroViewer
Same root cause as the command list fix: MacroViewer is a Preact functional component, so this.forceUpdate() throws (this is undefined), leaving the macro list stale after add/edit/delete. Use a useState counter to trigger re-renders.
This commit is contained in:
parent
ecc9c06fd9
commit
0f352bc56c
1 changed files with 5 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { Platform } from "obsidian";
|
||||
import { Fragment, h } from "preact";
|
||||
import { useState } from "preact/hooks";
|
||||
import t from "src/l10n";
|
||||
import CommanderPlugin from "src/main";
|
||||
import { Macro } from "src/types";
|
||||
|
|
@ -16,6 +17,8 @@ export default function MacroViewer({
|
|||
plugin,
|
||||
macros,
|
||||
}: MacroBuilderProps): h.JSX.Element {
|
||||
const [, rerender] = useState(0);
|
||||
const forceUpdate = (): void => rerender((n) => n + 1);
|
||||
const handleBuilder = (macro: Macro, idx?: number): void => {
|
||||
const onClose = (updatedMacro: Macro): void => {
|
||||
macros.splice(
|
||||
|
|
@ -25,7 +28,7 @@ export default function MacroViewer({
|
|||
);
|
||||
|
||||
plugin.saveSettings();
|
||||
this.forceUpdate();
|
||||
forceUpdate();
|
||||
updateMacroCommands(plugin);
|
||||
modal.close();
|
||||
};
|
||||
|
|
@ -36,7 +39,7 @@ export default function MacroViewer({
|
|||
const handleDelete = (idx: number): void => {
|
||||
macros.splice(idx, 1);
|
||||
plugin.saveSettings();
|
||||
this.forceUpdate();
|
||||
forceUpdate();
|
||||
updateMacroCommands(plugin);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue