support for creating copy and remixing states, sending these requests to storage

This commit is contained in:
Ben Wheeler committed 2018-10-28 01:02:35 -04:00
1 parent 1bca98c868
commit e10bcb1338
2 files changed
+48 -10

No files matched your search

+38 -6
View File
@@ -9,7 +9,9 @@ import {
createProject,
doneCreatingProject,
doneUpdatingProject,
getIsCreating,
getIsCreatingCopy,
getIsCreatingNew,
getIsRemixing,
getIsShowingProject,
getIsShowingWithoutId,
getIsUpdating,
@@ -41,16 +43,41 @@ const ProjectSaverHOC = function (WrappedComponent) {
});
}
// TODO: distinguish between creating new, remixing, and saving as a copy
if (this.props.isCreating && !prevProps.isCreating) {
if (this.props.isCreatingNew && !prevProps.isCreatingNew) {
this.storeProject()
.then(response => {
this.props.onCreatedProject(response.id.toString(), this.props.loadingState);
})
.catch(err => {
// NOTE: should throw up a notice for user
this.props.onProjectError(`Creating a new project failed with error: ${err}`);
});
}
if (this.props.isCreatingCopy && !prevProps.isCreatingCopy) {
this.storeProject(undefined, {
original_id: this.props.reduxProjectId,
is_copy: 1,
title: encodeURIComponent(this.props.reduxProjectTitle)
})
.then(response => {
this.props.onCreatedProject(response.id.toString(), this.props.loadingState);
})
.catch(err => {
this.props.onProjectError(`Creating a project copy failed with error: ${err}`);
});
}
if (this.props.isRemixing && !prevProps.isRemixing) {
this.storeProject(undefined, {
original_id: this.props.reduxProjectId,
is_remix: 1,
title: encodeURIComponent(this.props.reduxProjectTitle)
})
.then(response => {
this.props.onCreatedProject(response.id.toString(), this.props.loadingState);
})
.catch(err => {
this.props.onProjectError(`Remixing a project failed with error: ${err}`);
});
}
// check if the project state, and user capabilities, have changed so as to indicate
// that we should create or update project
@@ -74,7 +101,7 @@ const ProjectSaverHOC = function (WrappedComponent) {
* @param {number|string|undefined} projectId defined value causes PUT/update; undefined causes POST/create
* @return {Promise} resolves with json object containing project's existing or new id
*/
storeProject (projectId) {
storeProject (projectId, urlOptions) {
return this.props.vm.saveProjectSb3()
.then(content => {
const assetType = storage.AssetType.Project;
@@ -87,7 +114,8 @@ const ProjectSaverHOC = function (WrappedComponent) {
assetType,
dataFormat,
body,
projectId
projectId,
urlOptions
);
});
}
@@ -129,17 +157,21 @@ const ProjectSaverHOC = function (WrappedComponent) {
onUpdateProject: PropTypes.func,
onUpdatedProject: PropTypes.func,
reduxProjectId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
reduxProjectTitle: PropTypes.string,
vm: PropTypes.instanceOf(VM).isRequired
};
const mapStateToProps = state => {
const loadingState = state.scratchGui.projectState.loadingState;
return {
isCreating: getIsCreating(loadingState),
isCreatingCopy: getIsCreatingCopy(loadingState),
isCreatingNew: getIsCreatingNew(loadingState),
isRemixing: getIsRemixing(loadingState),
isShowingWithId: getIsShowingProject(loadingState),
isShowingWithoutId: getIsShowingWithoutId(loadingState),
isUpdating: getIsUpdating(loadingState),
loadingState: loadingState,
reduxProjectId: state.scratchGui.projectState.projectId,
reduxProjectTitle: state.scratchGui.projectTitle,
vm: state.scratchGui.vm
};
};
+10 -4
View File
@@ -54,11 +54,15 @@ const getIsLoadingWithId = loadingState => (
loadingState === LoadingState.LOADING_VM_WITH_ID ||
loadingState === LoadingState.LOADING_VM_NEW_DEFAULT
);
const getIsCreating = loadingState => (
loadingState === LoadingState.CREATING_NEW ||
loadingState === LoadingState.REMIXING ||
const getIsCreatingNew = loadingState => (
loadingState === LoadingState.CREATING_NEW
);
const getIsCreatingCopy = loadingState => (
loadingState === LoadingState.CREATING_COPY
);
const getIsRemixing = loadingState => (
loadingState === LoadingState.REMIXING
);
const getIsUpdating = loadingState => (
loadingState === LoadingState.UPDATING ||
loadingState === LoadingState.UPDATING_BEFORE_NEW
@@ -401,11 +405,13 @@ export {
defaultProjectId,
doneCreatingProject,
doneUpdatingProject,
getIsCreating,
getIsCreatingCopy,
getIsCreatingNew,
getIsError,
getIsFetchingWithId,
getIsFetchingWithoutId,
getIsLoadingWithId,
getIsRemixing,
getIsShowingProject,
getIsShowingWithId,
getIsShowingWithoutId,