@@ -3,7 +3,10 @@ import React from 'react';
33import { connect } from 'react-redux' ;
44import { defineMessages , injectIntl , intlShape } from 'react-intl' ;
55
6- import { getIsShowingWithoutId } from '../reducers/project-state' ;
6+ import {
7+ getIsAnyCreatingNewState ,
8+ getIsShowingWithoutId
9+ } from '../reducers/project-state' ;
710import { setProjectTitle } from '../reducers/project-title' ;
811
912const messages = defineMessages ( {
@@ -27,6 +30,12 @@ const TitledHOC = function (WrappedComponent) {
2730 if ( this . props . projectTitle !== prevProps . projectTitle ) {
2831 this . handleReceivedProjectTitle ( this . props . projectTitle ) ;
2932 }
33+ // if project is a new default project, and has loaded,
34+ if ( this . props . isShowingWithoutId && prevProps . isAnyCreatingNewState ) {
35+ // reset title to default
36+ const defaultProjectTitle = this . handleReceivedProjectTitle ( ) ;
37+ this . props . onUpdateProjectTitle ( defaultProjectTitle ) ;
38+ }
3039 // if the projectTitle hasn't changed, but the reduxProjectTitle
3140 // HAS changed, we need to report that change to the projectTitle's owner
3241 if ( this . props . reduxProjectTitle !== prevProps . reduxProjectTitle &&
@@ -40,11 +49,13 @@ const TitledHOC = function (WrappedComponent) {
4049 newTitle = this . props . intl . formatMessage ( messages . defaultProjectTitle ) ;
4150 }
4251 this . props . onChangedProjectTitle ( newTitle ) ;
52+ return newTitle ;
4353 }
4454 render ( ) {
4555 const {
4656 /* eslint-disable no-unused-vars */
4757 intl,
58+ isAnyCreatingNewState,
4859 isShowingWithoutId,
4960 onChangedProjectTitle,
5061 // for children, we replace onUpdateProjectTitle with our own
@@ -66,6 +77,7 @@ const TitledHOC = function (WrappedComponent) {
6677
6778 TitledComponent . propTypes = {
6879 intl : intlShape ,
80+ isAnyCreatingNewState : PropTypes . bool ,
6981 isShowingWithoutId : PropTypes . bool ,
7082 onChangedProjectTitle : PropTypes . func ,
7183 onUpdateProjectTitle : PropTypes . func ,
@@ -80,6 +92,7 @@ const TitledHOC = function (WrappedComponent) {
8092 const mapStateToProps = state => {
8193 const loadingState = state . scratchGui . projectState . loadingState ;
8294 return {
95+ isAnyCreatingNewState : getIsAnyCreatingNewState ( loadingState ) ,
8396 isShowingWithoutId : getIsShowingWithoutId ( loadingState ) ,
8497 reduxProjectTitle : state . scratchGui . projectTitle
8598 } ;
0 commit comments