Skip to content

Commit

Permalink
Slight changes and added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ag-m2ms committed Jan 19, 2021
1 parent afb2397 commit e6747f6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export const restoreFromCurrentSnapshot = ({ nglViewList }) => (dispatch, getSta

export const restoreSnapshotActions = ({ nglViewList, projectId, snapshotId, history }) => (dispatch, getState) => {
dispatch(resetRestoringState(nglViewList));
// Trigger react-router to get rid of snapshot just saved flag
history.replace(`${URLS.projects}${projectId}/${snapshotId}`);
};

Expand Down
1 change: 1 addition & 0 deletions js/components/routes/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const Routes = memo(() => {
};

useEffect(() => {
// Reset the snapshot just saved flag on each route change
dispatch(setSnapshotJustSaved(undefined));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [location]);
Expand Down
77 changes: 38 additions & 39 deletions js/components/snapshot/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,46 +259,45 @@ export const createNewSnapshot = ({
selectedSnapshotToSwitch === null ? res.data.id : selectedSnapshotToSwitch
}`
);
api({ url: `${base_url}/api/session-projects/${session_project}/` }).then(projectResponse => {
api({ url: `${base_url}/api/snapshots/?session_project=${session_project}` }).then(response => {
const length = response.data.results.length;
if (length === 0) {
dispatch(resetCurrentSnapshot());
} else if (response.data.results[length - 1] !== undefined) {
dispatch(
setCurrentSnapshot({
id: response.data.results[length - 1].id,
type: response.data.results[length - 1].type,
title: response.data.results[length - 1].title,
author: response.data.results[length - 1].author,
description: response.data.results[length - 1].description,
created: response.data.results[length - 1].created,
children: response.data.results[length - 1].children,
parent: response.data.results[length - 1].parent,
data: '[]'
})
);
dispatch(
setCurrentProject({
projectID: projectResponse.data.id,
authorID: (projectResponse.data.author && projectResponse.data.author.id) || null,
title: projectResponse.data.title,
description: projectResponse.data.description,
targetID: projectResponse.data.target.id,
tags: JSON.parse(projectResponse.data.tags)
})
);
dispatch(loadSnapshotTree(projectResponse.data.id)).catch(error => {
throw new Error(error);
});
dispatch(setOpenSnapshotSavingDialog(false));
dispatch(setIsLoadingSnapshotDialog(false));
dispatch(setSnapshotJustSaved(projectResponse.data.id));
}
})
.catch(error => {
api({ url: `${base_url}/api/session-projects/${session_project}/` }).then(async projectResponse => {
const response = await api({ url: `${base_url}/api/snapshots/?session_project=${session_project}` });
const length = response.data.results.length;
if (length === 0) {
dispatch(resetCurrentSnapshot());
})
} else if (response.data.results[length - 1] !== undefined) {
// If the tree fails to load, bail out first without modifying the store
dispatch(loadSnapshotTree(projectResponse.data.id));
// Pick the latest snapshot which should be the last one
dispatch(
setCurrentSnapshot({
id: response.data.results[length - 1].id,
type: response.data.results[length - 1].type,
title: response.data.results[length - 1].title,
author: response.data.results[length - 1].author,
description: response.data.results[length - 1].description,
created: response.data.results[length - 1].created,
children: response.data.results[length - 1].children,
parent: response.data.results[length - 1].parent,
data: '[]'
})
);
dispatch(
setCurrentProject({
projectID: projectResponse.data.id,
authorID: (projectResponse.data.author && projectResponse.data.author.id) || null,
title: projectResponse.data.title,
description: projectResponse.data.description,
targetID: projectResponse.data.target.id,
tags: JSON.parse(projectResponse.data.tags)
})
);
dispatch(setOpenSnapshotSavingDialog(false));
dispatch(setIsLoadingSnapshotDialog(false));
dispatch(setSnapshotJustSaved(projectResponse.data.id));
}
}).catch(error => {
dispatch(resetCurrentSnapshot());
dispatch(setIsLoadingSnapshotDialog(false));
});
} else {
dispatch(setOpenSnapshotSavingDialog(false));
Expand Down
7 changes: 3 additions & 4 deletions js/components/snapshot/withSnapshotManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ export const withSnapshotManagement = WrappedComponent => {
const currentProject = useSelector(state => state.projectReducers.currentProject);
const currentSnapshot = useSelector(state => state.projectReducers.currentSnapshot);
const directDisplay = useSelector(state => state.apiReducers.direct_access);


const projectId = currentProject.projectID;
const snapshotJustSaved = useSelector(state => state.snapshotReducers.snapshotJustSaved);
let projectId = currentProject.projectID;
/*let projectId = match && match.params && match.params.projectId;
projectId = snapshotJustSaved || projectId;*/
let target = match && match.params && match.params.target;
// Check whether the snapshot was just saved
target = snapshotJustSaved ? undefined : target;
//const disableUserInteraction = useDisableUserInteraction();

Expand Down

0 comments on commit e6747f6

Please sign in to comment.