Skip to content

Commit ed4c063

Browse files
committed
stripped title handling from sb file uploader; updated more projectState related names
1 parent f6d7325 commit ed4c063

File tree

8 files changed

+33
-34
lines changed

8 files changed

+33
-34
lines changed

src/components/menu-bar/menu-bar.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,7 @@ class MenuBar extends React.Component {
328328
</MenuItemTooltip>
329329
</MenuSection>
330330
<MenuSection>
331-
<SBFileUploader
332-
onUpdateProjectTitle={this.props.onUpdateProjectTitle}
333-
>
331+
<SBFileUploader>
334332
{(renderFileInput, loadProject) => (
335333
<MenuItem
336334
onClick={loadProject}
@@ -654,7 +652,7 @@ MenuBar.propTypes = {
654652
};
655653

656654
const mapStateToProps = state => {
657-
const loadingState = state.scratchGui.projectId.loadingState;
655+
const loadingState = state.scratchGui.projectState.loadingState;
658656
const user = state.session && state.session.session && state.session.session.user;
659657
return {
660658
accountMenuOpen: accountMenuOpen(state),

src/containers/sb-file-uploader.jsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {defineMessages, injectIntl, intlShape} from 'react-intl';
77
import analytics from '../lib/analytics';
88
import log from '../lib/log';
99
import {setProjectTitle} from '../reducers/project-title';
10-
import {onLoadedProject, onProjectUploadStarted} from '../reducers/project-state';
10+
import {LoadingStates, onLoadedProject, onProjectUploadStarted} from '../reducers/project-state';
1111

1212
import {
1313
openLoadingProject,
@@ -61,15 +61,15 @@ class SBFileUploader extends React.Component {
6161
action: 'Import Project File',
6262
nonInteraction: true
6363
});
64-
this.props.onLoadingFinished();
64+
this.props.onLoadingFinished(this.props.loadingState);
6565
// Reset the file input after project is loaded
6666
// This is necessary in case the user wants to reload a project
6767
thisFileInput.value = null;
6868
})
6969
.catch(error => {
7070
log.warn(error);
7171
alert(this.props.intl.formatMessage(messages.loadError)); // eslint-disable-line no-alert
72-
this.props.onLoadingFinished();
72+
this.props.onLoadingFinished(this.props.loadingState);
7373
// Reset the file input after project is loaded
7474
// This is necessary in case the user wants to reload a project
7575
thisFileInput.value = null;
@@ -82,10 +82,7 @@ class SBFileUploader extends React.Component {
8282
const matches = thisFileInput.files[0].name.match(/^(.*)\.sb3$/);
8383
if (matches) {
8484
const truncatedProjectTitle = matches[1].substring(0, 100);
85-
this.props.onSetReduxProjectTitle(truncatedProjectTitle);
86-
if (this.props.onUpdateProjectTitle) {
87-
this.props.onUpdateProjectTitle(truncatedProjectTitle);
88-
}
85+
this.props.onSetProjectTitle(truncatedProjectTitle);
8986
}
9087
}
9188
}
@@ -116,24 +113,25 @@ class SBFileUploader extends React.Component {
116113
SBFileUploader.propTypes = {
117114
children: PropTypes.func,
118115
intl: intlShape.isRequired,
116+
loadingState: PropTypes.oneOf(LoadingStates),
119117
onLoadingFinished: PropTypes.func,
120118
onLoadingStarted: PropTypes.func,
121-
onSetReduxProjectTitle: PropTypes.func,
122-
onUpdateProjectTitle: PropTypes.func,
119+
onSetProjectTitle: PropTypes.func,
123120
vm: PropTypes.shape({
124121
loadProject: PropTypes.func
125122
})
126123
};
127124
const mapStateToProps = state => ({
125+
loadingState: state.scratchGui.projectState.loadingState,
128126
vm: state.scratchGui.vm
129127
});
130128

131129
const mapDispatchToProps = dispatch => ({
132-
onLoadingFinished: () => {
133-
dispatch(onLoadedProject());
130+
onLoadingFinished: loadingState => {
131+
dispatch(onLoadedProject(loadingState));
134132
dispatch(closeLoadingProject());
135133
},
136-
onSetReduxProjectTitle: title => dispatch(setProjectTitle(title)),
134+
onSetProjectTitle: title => dispatch(setProjectTitle(title)),
137135
onLoadingStarted: () => {
138136
dispatch(openLoadingProject());
139137
dispatch(onProjectUploadStarted());

src/lib/hash-parser-hoc.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ const HashParserHOC = function (WrappedComponent) {
7373
setProjectId: PropTypes.func
7474
};
7575
const mapStateToProps = state => {
76-
const loadingState = state.scratchGui.projectId.loadingState;
76+
const loadingState = state.scratchGui.projectState.loadingState;
7777
return {
7878
isFetchingWithoutId: getIsFetchingWithoutId(loadingState),
79-
reduxProjectId: state.scratchGui.projectId.projectId
79+
reduxProjectId: state.scratchGui.projectState.projectId
8080
};
8181
};
8282
const mapDispatchToProps = dispatch => ({

src/lib/project-fetcher-hoc.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ const ProjectFetcherHOC = function (WrappedComponent) {
117117
};
118118

119119
const mapStateToProps = state => ({
120-
isFetchingWithId: getIsFetchingWithId(state.scratchGui.projectId.loadingState),
121-
loadingState: state.scratchGui.projectId.loadingState,
122-
reduxProjectId: state.scratchGui.projectId.projectId
120+
isFetchingWithId: getIsFetchingWithId(state.scratchGui.projectState.loadingState),
121+
loadingState: state.scratchGui.projectState.loadingState,
122+
reduxProjectId: state.scratchGui.projectState.projectId
123123
});
124124
const mapDispatchToProps = dispatch => ({
125125
onFetchedProjectData: (projectData, loadingState) =>

src/lib/project-saver-hoc.jsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import {
2121
* <ProjectSaverHOC>
2222
* <WrappedComponent />
2323
* </ProjectSaverHOC>
24-
*
25-
* storeProject(projectId): undefined value will cause POST/create; defined id will cause PUT/update
2624
*/
2725
const ProjectSaverHOC = function (WrappedComponent) {
2826
class ProjectSaverComponent extends React.Component {
@@ -49,6 +47,11 @@ const ProjectSaverHOC = function (WrappedComponent) {
4947
});
5048
}
5149
}
50+
/**
51+
* storeProject:
52+
* @param {number|string|undefined} projectId defined value causes PUT/update; undefined causes POST/create
53+
* @return {Promise} resolves with json object containing project's existing or new id
54+
*/
5255
storeProject (projectId) {
5356
return this.props.vm.saveProjectSb3()
5457
.then(content => {
@@ -62,7 +65,7 @@ const ProjectSaverHOC = function (WrappedComponent) {
6265
assetType,
6366
dataFormat,
6467
body,
65-
projectId // undefined value will cause POST/create; defined id will cause PUT/update
68+
projectId
6669
);
6770
});
6871
}
@@ -97,12 +100,12 @@ const ProjectSaverHOC = function (WrappedComponent) {
97100
vm: PropTypes.instanceOf(VM).isRequired
98101
};
99102
const mapStateToProps = state => {
100-
const loadingState = state.scratchGui.projectId.loadingState;
103+
const loadingState = state.scratchGui.projectState.loadingState;
101104
return {
102105
isCreating: getIsCreating(loadingState),
103106
isUpdating: getIsUpdating(loadingState),
104107
loadingState: loadingState,
105-
reduxProjectId: state.scratchGui.projectId.projectId,
108+
reduxProjectId: state.scratchGui.projectState.projectId,
106109
vm: state.scratchGui.vm
107110
};
108111
};

src/lib/vm-manager-hoc.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ const vmManagerHOC = function (WrappedComponent) {
8383

8484
VMManager.propTypes = {
8585
isLoadingWithId: PropTypes.bool,
86+
loadingState: PropTypes.oneOf(LoadingStates),
8687
onLoadedProject: PropTypes.func,
8788
projectData: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
8889
projectId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
89-
loadingState: PropTypes.oneOf(LoadingStates),
9090
vm: PropTypes.instanceOf(VM).isRequired
9191
};
9292

9393
const mapStateToProps = state => {
94-
const loadingState = state.scratchGui.projectId.loadingState;
94+
const loadingState = state.scratchGui.projectState.loadingState;
9595
return {
9696
isLoadingWithId: getIsLoadingWithId(loadingState),
97-
projectData: state.scratchGui.projectId.projectData,
98-
projectId: state.scratchGui.projectId.projectId,
97+
projectData: state.scratchGui.projectState.projectData,
98+
projectId: state.scratchGui.projectState.projectId,
9999
loadingState: loadingState
100100
};
101101
};

src/reducers/gui.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import modalReducer, {modalsInitialState} from './modals';
1313
import modeReducer, {modeInitialState} from './mode';
1414
import monitorReducer, {monitorsInitialState} from './monitors';
1515
import monitorLayoutReducer, {monitorLayoutInitialState} from './monitor-layout';
16-
import projectIdReducer, {projectIdInitialState} from './project-state';
16+
import projectStateReducer, {projectStateInitialState} from './project-state';
1717
import projectTitleReducer, {projectTitleInitialState} from './project-title';
1818
import restoreDeletionReducer, {restoreDeletionInitialState} from './restore-deletion';
1919
import stageSizeReducer, {stageSizeInitialState} from './stage-size';
@@ -43,7 +43,7 @@ const guiInitialState = {
4343
modals: modalsInitialState,
4444
monitors: monitorsInitialState,
4545
monitorLayout: monitorLayoutInitialState,
46-
projectId: projectIdInitialState,
46+
projectState: projectStateInitialState,
4747
projectTitle: projectTitleInitialState,
4848
restoreDeletion: restoreDeletionInitialState,
4949
targets: targetsInitialState,
@@ -110,7 +110,7 @@ const guiReducer = combineReducers({
110110
modals: modalReducer,
111111
monitors: monitorReducer,
112112
monitorLayout: monitorLayoutReducer,
113-
projectId: projectIdReducer,
113+
projectState: projectStateReducer,
114114
projectTitle: projectTitleReducer,
115115
restoreDeletion: restoreDeletionReducer,
116116
targets: targetReducer,

src/reducers/project-state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ const saveRequested = () => ({
323323

324324
export {
325325
reducer as default,
326-
initialState as projectIdInitialState,
326+
initialState as projectStateInitialState,
327327
LoadingState,
328328
LoadingStates,
329329
defaultProjectId,

0 commit comments

Comments
 (0)