From 93a63e05ed219e836bc2be854714e448454174d7 Mon Sep 17 00:00:00 2001 From: Bill Date: Thu, 24 Mar 2022 12:05:14 -0400 Subject: [PATCH] Fix wired saving --- src/components/wired/views/WiredBaseView.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/wired/views/WiredBaseView.tsx b/src/components/wired/views/WiredBaseView.tsx index fd862e89..c8f3ca79 100644 --- a/src/components/wired/views/WiredBaseView.tsx +++ b/src/components/wired/views/WiredBaseView.tsx @@ -19,21 +19,28 @@ export const WiredBaseView: FC = props => const { wiredType = '', requiresFurni = WiredFurniType.STUFF_SELECTION_OPTION_NONE, save = null, validate = null, children = null, hasSpecialInput = false } = props; const [ wiredName, setWiredName ] = useState(null); const [ wiredDescription, setWiredDescription ] = useState(null); + const [ needsSave, setNeedsSave ] = useState(false); const { trigger = null, setTrigger = null, setIntParams = null, setStringParam = null, setFurniIds = null, saveWired = null } = useWiredContext(); + const close = () => setTrigger(null); + const onSave = () => { if(validate && !validate()) return; if(save) save(); - saveWired(); + setNeedsSave(true); } - const close = () => + useEffect(() => { - setTrigger(null); - } + if(!needsSave) return; + + saveWired(); + + setNeedsSave(false); + }, [ needsSave, saveWired ]); useEffect(() => { @@ -83,6 +90,7 @@ export const WiredBaseView: FC = props => { BatchUpdates(() => { + setNeedsSave(false); setIntParams([]); setStringParam(null); setFurniIds(prevValue =>