From ee253ea4f1a0baae9819f64ed19077454346ef42 Mon Sep 17 00:00:00 2001 From: mickr777 <115216705+mickr777@users.noreply.github.com> Date: Thu, 13 Jul 2023 19:35:19 +1000 Subject: [PATCH 1/3] add useCallback --- .../features/nodes/components/ui/ClearNodesButton.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/invokeai/frontend/web/src/features/nodes/components/ui/ClearNodesButton.tsx b/invokeai/frontend/web/src/features/nodes/components/ui/ClearNodesButton.tsx index 22845dd362..c5de45a826 100644 --- a/invokeai/frontend/web/src/features/nodes/components/ui/ClearNodesButton.tsx +++ b/invokeai/frontend/web/src/features/nodes/components/ui/ClearNodesButton.tsx @@ -13,9 +13,9 @@ import { makeToast } from 'app/components/Toaster'; import { RootState } from 'app/store/store'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import IAIIconButton from 'common/components/IAIIconButton'; -import { clearNodes } from 'features/nodes/store/nodesSlice'; +import { nodeEditorReset } from 'features/nodes/store/nodesSlice'; import { addToast } from 'features/system/store/systemSlice'; -import { memo, useRef } from 'react'; +import { memo, useRef, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { FaTrash } from 'react-icons/fa'; @@ -27,8 +27,8 @@ const ClearNodesButton = () => { const nodes = useAppSelector((state: RootState) => state.nodes.nodes); - const handleConfirmClear = () => { - dispatch(clearNodes()); + const handleConfirmClear = useCallback(() => { + dispatch(nodeEditorReset()); dispatch( addToast( @@ -40,7 +40,7 @@ const ClearNodesButton = () => { ); onClose(); - }; + }, [dispatch, t, onClose]); return ( <> From b5e7384f09efee6ae7ca8d4c564a0d0dac34ea4c Mon Sep 17 00:00:00 2001 From: mickr777 <115216705+mickr777@users.noreply.github.com> Date: Thu, 13 Jul 2023 19:37:56 +1000 Subject: [PATCH 2/3] Delete clearnodes and change nodeEditorReset --- .../frontend/web/src/features/nodes/store/nodesSlice.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts b/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts index b2825db783..1d9835f598 100644 --- a/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts +++ b/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts @@ -121,8 +121,9 @@ const nodesSlice = createSlice({ ) => { state.invocationTemplates = action.payload; }, - nodeEditorReset: () => { - return { ...initialNodesState }; + nodeEditorReset: (state) => { + state.nodes = []; + state.edges = []; }, setEditorInstance: (state, action) => { state.editorInstance = action.payload; @@ -133,10 +134,6 @@ const nodesSlice = createSlice({ loadFileEdges: (state, action: PayloadAction) => { state.edges = action.payload; }, - clearNodes: (state) => { - state.nodes = []; - state.edges = []; - }, }, extraReducers: (builder) => { builder.addCase(receivedOpenAPISchema.fulfilled, (state, action) => { From 3cf75e48c5139a2af4a165611392d37adee6bfdf Mon Sep 17 00:00:00 2001 From: mickr777 <115216705+mickr777@users.noreply.github.com> Date: Thu, 13 Jul 2023 19:42:38 +1000 Subject: [PATCH 3/3] remove clearnode export --- invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts b/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts index 1d9835f598..91b6f685e6 100644 --- a/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts +++ b/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts @@ -157,7 +157,6 @@ export const { setEditorInstance, loadFileNodes, loadFileEdges, - clearNodes, } = nodesSlice.actions; export default nodesSlice.reducer;