Skip to content
Snippets Groups Projects
Commit 53997619 authored by Ben Wheeler's avatar Ben Wheeler
Browse files

got rid of uses of undefined

parent e10bcb13
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,7 @@ const ProjectSaverHOC = function (WrappedComponent) { ...@@ -44,7 +44,7 @@ const ProjectSaverHOC = function (WrappedComponent) {
} }
// TODO: distinguish between creating new, remixing, and saving as a copy // TODO: distinguish between creating new, remixing, and saving as a copy
if (this.props.isCreatingNew && !prevProps.isCreatingNew) { if (this.props.isCreatingNew && !prevProps.isCreatingNew) {
this.storeProject() this.storeProject(null)
.then(response => { .then(response => {
this.props.onCreatedProject(response.id.toString(), this.props.loadingState); this.props.onCreatedProject(response.id.toString(), this.props.loadingState);
}) })
...@@ -53,10 +53,9 @@ const ProjectSaverHOC = function (WrappedComponent) { ...@@ -53,10 +53,9 @@ const ProjectSaverHOC = function (WrappedComponent) {
}); });
} }
if (this.props.isCreatingCopy && !prevProps.isCreatingCopy) { if (this.props.isCreatingCopy && !prevProps.isCreatingCopy) {
this.storeProject(undefined, { this.storeProject(null, {
original_id: this.props.reduxProjectId, original_id: this.props.reduxProjectId,
is_copy: 1, is_copy: 1
title: encodeURIComponent(this.props.reduxProjectTitle)
}) })
.then(response => { .then(response => {
this.props.onCreatedProject(response.id.toString(), this.props.loadingState); this.props.onCreatedProject(response.id.toString(), this.props.loadingState);
...@@ -66,10 +65,9 @@ const ProjectSaverHOC = function (WrappedComponent) { ...@@ -66,10 +65,9 @@ const ProjectSaverHOC = function (WrappedComponent) {
}); });
} }
if (this.props.isRemixing && !prevProps.isRemixing) { if (this.props.isRemixing && !prevProps.isRemixing) {
this.storeProject(undefined, { this.storeProject(null, {
original_id: this.props.reduxProjectId, original_id: this.props.reduxProjectId,
is_remix: 1, is_remix: 1
title: encodeURIComponent(this.props.reduxProjectTitle)
}) })
.then(response => { .then(response => {
this.props.onCreatedProject(response.id.toString(), this.props.loadingState); this.props.onCreatedProject(response.id.toString(), this.props.loadingState);
...@@ -98,10 +96,11 @@ const ProjectSaverHOC = function (WrappedComponent) { ...@@ -98,10 +96,11 @@ const ProjectSaverHOC = function (WrappedComponent) {
} }
/** /**
* storeProject: * storeProject:
* @param {number|string|undefined} projectId defined value causes PUT/update; undefined causes POST/create * @param {number|string|undefined} projectId - defined value will PUT/update; undefined/null will POST/create
* @return {Promise} resolves with json object containing project's existing or new id * @return {Promise} - resolves with json object containing project's existing or new id
* @param {?object} urlParams - object of params to add to querystring
*/ */
storeProject (projectId, urlOptions) { storeProject (projectId, urlParams) {
return this.props.vm.saveProjectSb3() return this.props.vm.saveProjectSb3()
.then(content => { .then(content => {
const assetType = storage.AssetType.Project; const assetType = storage.AssetType.Project;
...@@ -115,14 +114,16 @@ const ProjectSaverHOC = function (WrappedComponent) { ...@@ -115,14 +114,16 @@ const ProjectSaverHOC = function (WrappedComponent) {
dataFormat, dataFormat,
body, body,
projectId, projectId,
urlOptions urlParams
); );
}); });
} }
render () { render () {
const { const {
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
isCreating: isCreatingProp, isCreatingCopy: isCreatingCopyProp,
isCreatingNew: isCreatingNewProp,
isRemixing: isRemixingProp,
isShowingWithId: isShowingWithIdProp, isShowingWithId: isShowingWithIdProp,
isShowingWithoutId: isShowingWithoutIdProp, isShowingWithoutId: isShowingWithoutIdProp,
isUpdating: isUpdatingProp, isUpdating: isUpdatingProp,
...@@ -146,7 +147,9 @@ const ProjectSaverHOC = function (WrappedComponent) { ...@@ -146,7 +147,9 @@ const ProjectSaverHOC = function (WrappedComponent) {
ProjectSaverComponent.propTypes = { ProjectSaverComponent.propTypes = {
canCreateNew: PropTypes.bool, canCreateNew: PropTypes.bool,
canSave: PropTypes.bool, canSave: PropTypes.bool,
isCreating: PropTypes.bool, isCreatingCopy: PropTypes.bool,
isCreatingNew: PropTypes.bool,
isRemixing: PropTypes.bool,
isShowingWithId: PropTypes.bool, isShowingWithId: PropTypes.bool,
isShowingWithoutId: PropTypes.bool, isShowingWithoutId: PropTypes.bool,
isUpdating: PropTypes.bool, isUpdating: PropTypes.bool,
...@@ -157,7 +160,6 @@ const ProjectSaverHOC = function (WrappedComponent) { ...@@ -157,7 +160,6 @@ const ProjectSaverHOC = function (WrappedComponent) {
onUpdateProject: PropTypes.func, onUpdateProject: PropTypes.func,
onUpdatedProject: PropTypes.func, onUpdatedProject: PropTypes.func,
reduxProjectId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), reduxProjectId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
reduxProjectTitle: PropTypes.string,
vm: PropTypes.instanceOf(VM).isRequired vm: PropTypes.instanceOf(VM).isRequired
}; };
const mapStateToProps = state => { const mapStateToProps = state => {
...@@ -171,7 +173,6 @@ const ProjectSaverHOC = function (WrappedComponent) { ...@@ -171,7 +173,6 @@ const ProjectSaverHOC = function (WrappedComponent) {
isUpdating: getIsUpdating(loadingState), isUpdating: getIsUpdating(loadingState),
loadingState: loadingState, loadingState: loadingState,
reduxProjectId: state.scratchGui.projectState.projectId, reduxProjectId: state.scratchGui.projectState.projectId,
reduxProjectTitle: state.scratchGui.projectTitle,
vm: state.scratchGui.vm vm: state.scratchGui.vm
}; };
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment