From 13beb3223e9dca50fc1940b601fbba82c27275d8 Mon Sep 17 00:00:00 2001 From: ubbn Date: Sat, 18 May 2024 08:15:06 +0200 Subject: [PATCH] Fix bug in Study modal's redux call --- frontend/src/components/blog/Post.tsx | 2 +- frontend/src/components/neuron/index.tsx | 5 +---- frontend/src/redux/neuronSlice.ts | 9 +++++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/blog/Post.tsx b/frontend/src/components/blog/Post.tsx index 9105922..4d27a33 100644 --- a/frontend/src/components/blog/Post.tsx +++ b/frontend/src/components/blog/Post.tsx @@ -39,7 +39,7 @@ const Post = () => { const saveNeuron = () => { if (item) { - dispatch(thunkUpdateNeuron(item)) + dispatch(thunkUpdateNeuron(item, true)) setPristine(true); setInitial(item) } diff --git a/frontend/src/components/neuron/index.tsx b/frontend/src/components/neuron/index.tsx index e8bfc90..014b5af 100644 --- a/frontend/src/components/neuron/index.tsx +++ b/frontend/src/components/neuron/index.tsx @@ -88,10 +88,7 @@ const Ilearn = () => { }; const onSave = (neuron: Neuron) => { - if (showEditModal) { - // Only set if it is edit modal - dispatch(thunkUpdateNeuron(neuron)); - } + dispatch(thunkUpdateNeuron(neuron, showEditModal)); // Update redux only if it is edit modal setStudyList(studyList.map((v) => (v.id === neuron.id ? neuron : v))); setHasChanged(true); openNotification(neuron); diff --git a/frontend/src/redux/neuronSlice.ts b/frontend/src/redux/neuronSlice.ts index fcb0386..c12ad12 100644 --- a/frontend/src/redux/neuronSlice.ts +++ b/frontend/src/redux/neuronSlice.ts @@ -144,13 +144,18 @@ export const thunkFetchConnectedNeurons = (treeId: any): AppThunk => { } }; -export const thunkUpdateNeuron = (item: Neuron): AppThunk => { +export const thunkUpdateNeuron = ( + item: Neuron, + updateRedix?: boolean +): AppThunk => { return (dispatch) => { dispatch(actionStart()); return axios .post(url(), { user: getUserEmail(), ...item }) .then(({ data }) => { - dispatch(setNeuron(data)); + if (updateRedix) { + dispatch(setNeuron(data)); + } dispatch(actionFinish()); }) .catch(handleError(dispatch));