Skip to content

Commit

Permalink
Fix bug in Study modal's redux call
Browse files Browse the repository at this point in the history
  • Loading branch information
ubbn committed May 18, 2024
1 parent a9b0561 commit 13beb32
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/blog/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Post = () => {

const saveNeuron = () => {
if (item) {
dispatch(thunkUpdateNeuron(item))
dispatch(thunkUpdateNeuron(item, true))
setPristine(true);
setInitial(item)
}
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/neuron/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/redux/neuronSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 13beb32

Please sign in to comment.