Skip to content

Commit 22e2c17

Browse files
committed
don’t pass onUpdateProjectTitle below titledHIC
1 parent 9c33bbb commit 22e2c17

File tree

7 files changed

+41
-77
lines changed

7 files changed

+41
-77
lines changed

src/components/gui/gui.jsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ const GUIComponent = props => {
9494
onLogOut,
9595
onOpenRegistration,
9696
onToggleLoginOpen,
97-
onUpdateProjectTitle,
9897
onActivateCostumesTab,
9998
onActivateSoundsTab,
10099
onActivateTab,
@@ -228,7 +227,6 @@ const GUIComponent = props => {
228227
onSeeCommunity={onSeeCommunity}
229228
onShare={onShare}
230229
onToggleLoginOpen={onToggleLoginOpen}
231-
onUpdateProjectTitle={onUpdateProjectTitle}
232230
/>
233231
<Box className={styles.bodyWrapper}>
234232
<Box className={styles.flexWrapper}>
@@ -406,7 +404,6 @@ GUIComponent.propTypes = {
406404
onTelemetryModalOptIn: PropTypes.func,
407405
onTelemetryModalOptOut: PropTypes.func,
408406
onToggleLoginOpen: PropTypes.func,
409-
onUpdateProjectTitle: PropTypes.func,
410407
renderLogin: PropTypes.func,
411408
showComingSoon: PropTypes.bool,
412409
soundsTabVisible: PropTypes.bool,

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ class MenuBar extends React.Component {
395395
<SBFileUploader
396396
canSave={this.props.canSave}
397397
userOwnsProject={this.props.userOwnsProject}
398-
onUpdateProjectTitle={this.props.onUpdateProjectTitle}
399398
>
400399
{(className, renderFileInput, handleLoadProject) => (
401400
<MenuItem
@@ -495,7 +494,6 @@ class MenuBar extends React.Component {
495494
>
496495
<ProjectTitleInput
497496
className={classNames(styles.titleFieldGrowable)}
498-
onUpdateProjectTitle={this.props.onUpdateProjectTitle}
499497
/>
500498
</MenuBarItemTooltip>
501499
</div>
@@ -746,7 +744,6 @@ MenuBar.propTypes = {
746744
onSeeCommunity: PropTypes.func,
747745
onShare: PropTypes.func,
748746
onToggleLoginOpen: PropTypes.func,
749-
onUpdateProjectTitle: PropTypes.func,
750747
projectTitle: PropTypes.string,
751748
renderLogin: PropTypes.func,
752749
sessionExists: PropTypes.bool,

src/components/menu-bar/project-title-input.jsx

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import classNames from 'classnames';
22
import {connect} from 'react-redux';
33
import PropTypes from 'prop-types';
4-
import bindAll from 'lodash.bindall';
54
import React from 'react';
65
import {defineMessages, intlShape, injectIntl} from 'react-intl';
6+
import {setProjectTitle} from '../../reducers/project-title';
77

88
import BufferedInputHOC from '../forms/buffered-input-hoc.jsx';
99
import Input from '../forms/input.jsx';
@@ -19,47 +19,37 @@ const messages = defineMessages({
1919
}
2020
});
2121

22-
class ProjectTitleInput extends React.Component {
23-
constructor (props) {
24-
super(props);
25-
bindAll(this, [
26-
'handleUpdateProjectTitle'
27-
]);
28-
}
29-
// call onUpdateProjectTitle if it is defined (only defined when gui
30-
// is used within scratch-www)
31-
handleUpdateProjectTitle (newTitle) {
32-
if (this.props.onUpdateProjectTitle) {
33-
this.props.onUpdateProjectTitle(newTitle);
34-
}
35-
}
36-
render () {
37-
return (
38-
<BufferedInput
39-
className={classNames(styles.titleField, this.props.className)}
40-
maxLength="100"
41-
placeholder={this.props.intl.formatMessage(messages.projectTitlePlaceholder)}
42-
tabIndex="0"
43-
type="text"
44-
value={this.props.projectTitle}
45-
onSubmit={this.handleUpdateProjectTitle}
46-
/>
47-
);
48-
}
49-
}
22+
const ProjectTitleInput = ({
23+
className,
24+
handleUpdateReduxProjectTitle,
25+
intl,
26+
projectTitle
27+
}) => (
28+
<BufferedInput
29+
className={classNames(styles.titleField, className)}
30+
maxLength="100"
31+
placeholder={intl.formatMessage(messages.projectTitlePlaceholder)}
32+
tabIndex="0"
33+
type="text"
34+
value={projectTitle}
35+
onSubmit={handleUpdateReduxProjectTitle}
36+
/>
37+
);
5038

5139
ProjectTitleInput.propTypes = {
5240
className: PropTypes.string,
41+
handleUpdateReduxProjectTitle: PropTypes.func,
5342
intl: intlShape.isRequired,
54-
onUpdateProjectTitle: PropTypes.func,
5543
projectTitle: PropTypes.string
5644
};
5745

5846
const mapStateToProps = state => ({
5947
projectTitle: state.scratchGui.projectTitle
6048
});
6149

62-
const mapDispatchToProps = () => ({});
50+
const mapDispatchToProps = dispatch => ({
51+
handleUpdateReduxProjectTitle: title => dispatch(setProjectTitle(title))
52+
});
6353

6454
export default injectIntl(connect(
6555
mapStateToProps,

src/containers/gui.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,11 @@ GUI.propTypes = {
103103
isLoading: PropTypes.bool,
104104
isScratchDesktop: PropTypes.bool,
105105
isShowingProject: PropTypes.bool,
106-
isShowingWithoutId: PropTypes.bool,
107106
loadingStateVisible: PropTypes.bool,
108107
onProjectLoaded: PropTypes.func,
109108
onSeeCommunity: PropTypes.func,
110109
onStorageInit: PropTypes.func,
111110
onUpdateProjectId: PropTypes.func,
112-
onUpdateProjectTitle: PropTypes.func,
113111
onVmInit: PropTypes.func,
114112
projectHost: PropTypes.string,
115113
projectId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),

src/containers/sb-file-uploader.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33
import React from 'react';
44
import {connect} from 'react-redux';
55
import {defineMessages, injectIntl, intlShape} from 'react-intl';
6+
import {setProjectTitle} from '../reducers/project-title';
67

78
import log from '../lib/log';
89
import sharedMessages from '../lib/shared-messages';
@@ -131,7 +132,7 @@ class SBFileUploader extends React.Component {
131132
// This is necessary in case the user wants to reload a project
132133
if (filename) {
133134
const uploadedProjectTitle = this.getProjectTitleFromFilename(filename);
134-
this.props.onUpdateProjectTitle(uploadedProjectTitle);
135+
this.props.updateReduxProjectTitle(uploadedProjectTitle);
135136
}
136137
this.resetFileInput();
137138
})
@@ -179,9 +180,9 @@ SBFileUploader.propTypes = {
179180
loadingState: PropTypes.oneOf(LoadingStates),
180181
onLoadingFinished: PropTypes.func,
181182
onLoadingStarted: PropTypes.func,
182-
onUpdateProjectTitle: PropTypes.func,
183183
projectChanged: PropTypes.bool,
184184
requestProjectUpload: PropTypes.func,
185+
updateReduxProjectTitle: PropTypes.func,
185186
userOwnsProject: PropTypes.bool,
186187
vm: PropTypes.shape({
187188
loadProject: PropTypes.func
@@ -209,7 +210,8 @@ const mapDispatchToProps = (dispatch, ownProps) => ({
209210
dispatch(closeFileMenu());
210211
},
211212
requestProjectUpload: loadingState => dispatch(requestProjectUpload(loadingState)),
212-
onLoadingStarted: () => dispatch(openLoadingProject())
213+
onLoadingStarted: () => dispatch(openLoadingProject()),
214+
updateReduxProjectTitle: title => dispatch(setProjectTitle(title))
213215
});
214216

215217
// Allow incoming props to override redux-provided props. Used to mock in tests.

src/lib/titled-hoc.jsx

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
3-
import bindAll from 'lodash.bindall';
43
import {connect} from 'react-redux';
54
import {defineMessages, injectIntl, intlShape} from 'react-intl';
65

@@ -21,23 +20,18 @@ const messages = defineMessages({
2120
*/
2221
const TitledHOC = function (WrappedComponent) {
2322
class TitledComponent extends React.Component {
24-
constructor (props) {
25-
super(props);
26-
bindAll(this, [
27-
'handleUpdateProjectTitle'
28-
]);
29-
}
3023
componentDidMount () {
31-
this.setReduxTitle(this.props.projectTitle);
24+
this.props.updateReduxProjectTitle(this.titleWithDefault(this.props.projectTitle));
3225
}
3326
componentDidUpdate (prevProps) {
3427
if (this.props.projectTitle !== prevProps.projectTitle) {
35-
this.setReduxTitle(this.props.projectTitle);
28+
this.props.updateReduxProjectTitle(this.titleWithDefault(this.props.projectTitle));
3629
}
37-
if (this.props.isShowingWithoutId && !prevProps.isShowingWithoutId) {
38-
const defaultProjectTitle = this.titleWithDefault();
39-
this.setReduxTitle(defaultProjectTitle);
40-
this.props.onUpdateProjectTitle(defaultProjectTitle);
30+
// if the projectTitle hasn't changed, but the reduxProjectTitle
31+
// HAS changed, we need to report that change to the projectTitle's owner
32+
if (this.props.reduxProjectTitle !== prevProps.reduxProjectTitle &&
33+
this.props.reduxProjectTitle !== this.props.projectTitle) {
34+
this.props.onUpdateProjectTitle(this.props.reduxProjectTitle);
4135
}
4236
}
4337
titleWithDefault (title) {
@@ -46,36 +40,23 @@ const TitledHOC = function (WrappedComponent) {
4640
}
4741
return title;
4842
}
49-
setReduxTitle (newTitle) {
50-
if (newTitle === null || typeof newTitle === 'undefined') {
51-
this.props.onUpdateReduxProjectTitle(
52-
this.props.intl.formatMessage(messages.defaultProjectTitle)
53-
);
54-
} else {
55-
this.props.onUpdateReduxProjectTitle(newTitle);
56-
}
57-
}
58-
handleUpdateProjectTitle (newTitle) {
59-
this.setReduxTitle(newTitle);
60-
this.props.onUpdateProjectTitle(newTitle);
61-
}
6243
render () {
6344
const {
6445
/* eslint-disable no-unused-vars */
6546
intl,
6647
isShowingWithoutId,
6748
// for children, we replace onUpdateProjectTitle with our own
6849
onUpdateProjectTitle,
69-
onUpdateReduxProjectTitle,
7050
// we don't pass projectTitle prop to children -- they must use
7151
// redux value
7252
projectTitle,
53+
reduxProjectTitle,
54+
updateReduxProjectTitle,
7355
/* eslint-enable no-unused-vars */
7456
...componentProps
7557
} = this.props;
7658
return (
7759
<WrappedComponent
78-
onUpdateProjectTitle={this.handleUpdateProjectTitle}
7960
{...componentProps}
8061
/>
8162
);
@@ -86,8 +67,9 @@ const TitledHOC = function (WrappedComponent) {
8667
intl: intlShape,
8768
isShowingWithoutId: PropTypes.bool,
8869
onUpdateProjectTitle: PropTypes.func,
89-
onUpdateReduxProjectTitle: PropTypes.func,
90-
projectTitle: PropTypes.string
70+
projectTitle: PropTypes.string,
71+
reduxProjectTitle: PropTypes.string,
72+
updateReduxProjectTitle: PropTypes.func
9173
};
9274

9375
TitledComponent.defaultProps = {
@@ -97,12 +79,13 @@ const TitledHOC = function (WrappedComponent) {
9779
const mapStateToProps = state => {
9880
const loadingState = state.scratchGui.projectState.loadingState;
9981
return {
100-
isShowingWithoutId: getIsShowingWithoutId(loadingState)
82+
isShowingWithoutId: getIsShowingWithoutId(loadingState),
83+
reduxProjectTitle: state.scratchGui.projectTitle
10184
};
10285
};
10386

10487
const mapDispatchToProps = dispatch => ({
105-
onUpdateReduxProjectTitle: title => dispatch(setProjectTitle(title))
88+
updateReduxProjectTitle: title => dispatch(setProjectTitle(title))
10689
});
10790

10891
return injectIntl(connect(

test/unit/containers/sb-file-uploader.test.jsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ describe('SBFileUploader Container', () => {
1111
const mockStore = configureStore();
1212
let onLoadingFinished;
1313
let onLoadingStarted;
14-
let onUpdateProjectTitle;
1514
let store;
1615

1716
// Wrap this in a function so it gets test specific states and can be reused.
@@ -20,7 +19,6 @@ describe('SBFileUploader Container', () => {
2019
<SBFileUploader
2120
onLoadingFinished={onLoadingFinished}
2221
onLoadingStarted={onLoadingStarted}
23-
onUpdateProjectTitle={onUpdateProjectTitle}
2422
>
2523
{(renderFileInput, loadProject) => (
2624
<div
@@ -40,7 +38,6 @@ describe('SBFileUploader Container', () => {
4038
vm: {}
4139
}
4240
});
43-
onUpdateProjectTitle = jest.fn();
4441
onLoadingFinished = jest.fn();
4542
onLoadingStarted = jest.fn();
4643
});

0 commit comments

Comments
 (0)