From a5a7215e09937217a2a70fcf3c52cc002fe7a4ef Mon Sep 17 00:00:00 2001 From: Life Date: Mon, 30 Mar 2026 17:55:11 +0200 Subject: [PATCH] Change pendingActionRef to hold action and itemId Refactor pendingActionRef to store action and itemId as an object instead of a string. --- src/hooks/furni-editor/useFurniEditor.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/hooks/furni-editor/useFurniEditor.ts b/src/hooks/furni-editor/useFurniEditor.ts index 936eb4f..cd95ec4 100644 --- a/src/hooks/furni-editor/useFurniEditor.ts +++ b/src/hooks/furni-editor/useFurniEditor.ts @@ -60,7 +60,7 @@ export const useFurniEditor = () => const [ catalogItems, setCatalogItems ] = useState([]); const [ interactions, setInteractions ] = useState([]); const [ furniDataEntry, setFurniDataEntry ] = useState | null>(null); - const pendingActionRef = useRef(null); + const pendingActionRef = useRef<{ action: string; itemId: number } | null>(null); const { simpleAlert = null } = useNotification(); const clearError = useCallback(() => setError(null), []); @@ -161,7 +161,9 @@ export const useFurniEditor = () => useMessageEvent(FurniEditorResultEvent, (event: FurniEditorResultEvent) => { const parser = event.getParser(); - const action = pendingActionRef.current; + const pending = pendingActionRef.current; + const action = pending?.action ?? null; + const actionItemId = pending?.itemId ?? null; pendingActionRef.current = null; setLoading(false); @@ -182,10 +184,10 @@ export const useFurniEditor = () => if(action === 'update') { - // Auto-reload detail after update - if(selectedItem) + // Auto-reload detail after update using the ID from the original request + if(actionItemId) { - SendMessageComposer(new FurniEditorDetailComposer(selectedItem.id)); + SendMessageComposer(new FurniEditorDetailComposer(actionItemId)); } if(simpleAlert) @@ -231,7 +233,7 @@ export const useFurniEditor = () => { setLoading(true); setError(null); - pendingActionRef.current = 'update'; + pendingActionRef.current = { action: 'update', itemId: id }; SendMessageComposer(new FurniEditorUpdateComposer(id, JSON.stringify(fields))); }, []); @@ -239,7 +241,7 @@ export const useFurniEditor = () => { setLoading(true); setError(null); - pendingActionRef.current = 'delete'; + pendingActionRef.current = { action: 'delete', itemId: id }; SendMessageComposer(new FurniEditorDeleteComposer(id)); }, []);