@@ -4,9 +4,13 @@ import {compose} from 'redux';
44import { connect } from 'react-redux' ;
55import ReactModal from 'react-modal' ;
66import VM from 'scratch-vm' ;
7+ import { injectIntl , intlShape } from 'react-intl' ;
78
89import ErrorBoundaryHOC from '../lib/error-boundary-hoc.jsx' ;
910import { openExtensionLibrary } from '../reducers/modals' ;
11+ import {
12+ getIsShowingProject
13+ } from '../reducers/project-state' ;
1014import { setProjectTitle } from '../reducers/project-title' ;
1115import {
1216 activateTab ,
@@ -25,18 +29,29 @@ import ProjectFetcherHOC from '../lib/project-fetcher-hoc.jsx';
2529import ProjectSaverHOC from '../lib/project-saver-hoc.jsx' ;
2630import vmListenerHOC from '../lib/vm-listener-hoc.jsx' ;
2731import vmManagerHOC from '../lib/vm-manager-hoc.jsx' ;
32+ import { defaultProjectTitleMessages } from '../reducers/project-title' ;
2833
2934import GUIComponent from '../components/gui/gui.jsx' ;
3035
3136class GUI extends React . Component {
3237 componentDidMount ( ) {
33- if ( this . props . projectTitle ) {
34- this . props . onUpdateReduxProjectTitle ( this . props . projectTitle ) ;
38+ this . setReduxTitle ( this . props . projectTitle ) ;
39+ }
40+ componentDidUpdate ( prevProps ) {
41+ if ( this . props . projectId !== prevProps . projectId && this . props . projectId !== null ) {
42+ this . props . onUpdateProjectId ( this . props . projectId ) ;
43+ }
44+ if ( this . props . projectTitle !== prevProps . projectTitle ) {
45+ this . setReduxTitle ( this . props . projectTitle ) ;
3546 }
3647 }
37- componentWillReceiveProps ( nextProps ) {
38- if ( this . props . projectTitle !== nextProps . projectTitle ) {
39- this . props . onUpdateReduxProjectTitle ( nextProps . projectTitle ) ;
48+ setReduxTitle ( newTitle ) {
49+ if ( newTitle === null || typeof newTitle === 'undefined' ) {
50+ this . props . onUpdateReduxProjectTitle (
51+ this . props . intl . formatMessage ( defaultProjectTitleMessages . defaultProjectTitle )
52+ ) ;
53+ } else {
54+ this . props . onUpdateReduxProjectTitle ( newTitle ) ;
4055 }
4156 }
4257 render ( ) {
@@ -50,8 +65,11 @@ class GUI extends React.Component {
5065 errorMessage,
5166 hideIntro,
5267 loadingError,
68+ isShowingProject,
69+ onUpdateProjectId,
5370 onUpdateReduxProjectTitle,
5471 projectHost,
72+ projectId,
5573 projectTitle,
5674 /* eslint-enable no-unused-vars */
5775 children,
@@ -78,40 +96,53 @@ GUI.propTypes = {
7896 fetchingProject : PropTypes . bool ,
7997 hideIntro : PropTypes . bool ,
8098 importInfoVisible : PropTypes . bool ,
99+ intl : intlShape ,
81100 isLoading : PropTypes . bool ,
101+ isShowingProject : PropTypes . bool ,
82102 loadingError : PropTypes . bool ,
83103 loadingStateVisible : PropTypes . bool ,
84104 onChangeProjectInfo : PropTypes . func ,
85105 onSeeCommunity : PropTypes . func ,
106+ onUpdateProjectId : PropTypes . func ,
86107 onUpdateProjectTitle : PropTypes . func ,
87108 onUpdateReduxProjectTitle : PropTypes . func ,
88109 previewInfoVisible : PropTypes . bool ,
89110 projectHost : PropTypes . string ,
111+ projectId : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ,
90112 projectTitle : PropTypes . string ,
91113 vm : PropTypes . instanceOf ( VM ) . isRequired
92114} ;
93115
94- const mapStateToProps = ( state , ownProps ) => ( {
95- activeTabIndex : state . scratchGui . editorTab . activeTabIndex ,
96- alertsVisible : state . scratchGui . alerts . visible ,
97- backdropLibraryVisible : state . scratchGui . modals . backdropLibrary ,
98- blocksTabVisible : state . scratchGui . editorTab . activeTabIndex === BLOCKS_TAB_INDEX ,
99- cardsVisible : state . scratchGui . cards . visible ,
100- costumeLibraryVisible : state . scratchGui . modals . costumeLibrary ,
101- costumesTabVisible : state . scratchGui . editorTab . activeTabIndex === COSTUMES_TAB_INDEX ,
102- importInfoVisible : state . scratchGui . modals . importInfo ,
103- isPlayerOnly : state . scratchGui . mode . isPlayerOnly ,
104- isRtl : state . locales . isRtl ,
105- loadingStateVisible : state . scratchGui . modals . loadingProject ,
106- previewInfoVisible : state . scratchGui . modals . previewInfo && ! ownProps . hideIntro ,
107- targetIsStage : (
108- state . scratchGui . targets . stage &&
109- state . scratchGui . targets . stage . id === state . scratchGui . targets . editingTarget
110- ) ,
111- soundsTabVisible : state . scratchGui . editorTab . activeTabIndex === SOUNDS_TAB_INDEX ,
112- tipsLibraryVisible : state . scratchGui . modals . tipsLibrary ,
113- vm : state . scratchGui . vm
114- } ) ;
116+ GUI . defaultProps = {
117+ onUpdateProjectId : ( ) => { }
118+ } ;
119+
120+ const mapStateToProps = ( state , ownProps ) => {
121+ const loadingState = state . scratchGui . projectState . loadingState ;
122+ return {
123+ activeTabIndex : state . scratchGui . editorTab . activeTabIndex ,
124+ alertsVisible : state . scratchGui . alerts . visible ,
125+ backdropLibraryVisible : state . scratchGui . modals . backdropLibrary ,
126+ blocksTabVisible : state . scratchGui . editorTab . activeTabIndex === BLOCKS_TAB_INDEX ,
127+ cardsVisible : state . scratchGui . cards . visible ,
128+ costumeLibraryVisible : state . scratchGui . modals . costumeLibrary ,
129+ costumesTabVisible : state . scratchGui . editorTab . activeTabIndex === COSTUMES_TAB_INDEX ,
130+ importInfoVisible : state . scratchGui . modals . importInfo ,
131+ isPlayerOnly : state . scratchGui . mode . isPlayerOnly ,
132+ isRtl : state . locales . isRtl ,
133+ isShowingProject : getIsShowingProject ( loadingState ) ,
134+ loadingStateVisible : state . scratchGui . modals . loadingProject ,
135+ previewInfoVisible : state . scratchGui . modals . previewInfo && ! ownProps . hideIntro ,
136+ projectId : state . scratchGui . projectState . projectId ,
137+ targetIsStage : (
138+ state . scratchGui . targets . stage &&
139+ state . scratchGui . targets . stage . id === state . scratchGui . targets . editingTarget
140+ ) ,
141+ soundsTabVisible : state . scratchGui . editorTab . activeTabIndex === SOUNDS_TAB_INDEX ,
142+ tipsLibraryVisible : state . scratchGui . modals . tipsLibrary ,
143+ vm : state . scratchGui . vm
144+ } ;
145+ } ;
115146
116147const mapDispatchToProps = dispatch => ( {
117148 onExtensionButtonClick : ( ) => dispatch ( openExtensionLibrary ( ) ) ,
@@ -123,10 +154,10 @@ const mapDispatchToProps = dispatch => ({
123154 onUpdateReduxProjectTitle : title => dispatch ( setProjectTitle ( title ) )
124155} ) ;
125156
126- const ConnectedGUI = connect (
157+ const ConnectedGUI = injectIntl ( connect (
127158 mapStateToProps ,
128159 mapDispatchToProps ,
129- ) ( GUI ) ;
160+ ) ( GUI ) ) ;
130161
131162// note that redux's 'compose' function is just being used as a general utility to make
132163// the hierarchy of HOC constructor calls clearer here; it has nothing to do with redux's
0 commit comments