@@ -3,7 +3,10 @@ import React from 'react';
3
3
import { connect } from 'react-redux' ;
4
4
import { defineMessages , injectIntl , intlShape } from 'react-intl' ;
5
5
6
- import { getIsShowingWithoutId } from '../reducers/project-state' ;
6
+ import {
7
+ getIsAnyCreatingNewState ,
8
+ getIsShowingWithoutId
9
+ } from '../reducers/project-state' ;
7
10
import { setProjectTitle } from '../reducers/project-title' ;
8
11
9
12
const messages = defineMessages ( {
@@ -27,6 +30,12 @@ const TitledHOC = function (WrappedComponent) {
27
30
if ( this . props . projectTitle !== prevProps . projectTitle ) {
28
31
this . handleReceivedProjectTitle ( this . props . projectTitle ) ;
29
32
}
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
+ }
30
39
// if the projectTitle hasn't changed, but the reduxProjectTitle
31
40
// HAS changed, we need to report that change to the projectTitle's owner
32
41
if ( this . props . reduxProjectTitle !== prevProps . reduxProjectTitle &&
@@ -40,11 +49,13 @@ const TitledHOC = function (WrappedComponent) {
40
49
newTitle = this . props . intl . formatMessage ( messages . defaultProjectTitle ) ;
41
50
}
42
51
this . props . onChangedProjectTitle ( newTitle ) ;
52
+ return newTitle ;
43
53
}
44
54
render ( ) {
45
55
const {
46
56
/* eslint-disable no-unused-vars */
47
57
intl,
58
+ isAnyCreatingNewState,
48
59
isShowingWithoutId,
49
60
onChangedProjectTitle,
50
61
// for children, we replace onUpdateProjectTitle with our own
@@ -66,6 +77,7 @@ const TitledHOC = function (WrappedComponent) {
66
77
67
78
TitledComponent . propTypes = {
68
79
intl : intlShape ,
80
+ isAnyCreatingNewState : PropTypes . bool ,
69
81
isShowingWithoutId : PropTypes . bool ,
70
82
onChangedProjectTitle : PropTypes . func ,
71
83
onUpdateProjectTitle : PropTypes . func ,
@@ -80,6 +92,7 @@ const TitledHOC = function (WrappedComponent) {
80
92
const mapStateToProps = state => {
81
93
const loadingState = state . scratchGui . projectState . loadingState ;
82
94
return {
95
+ isAnyCreatingNewState : getIsAnyCreatingNewState ( loadingState ) ,
83
96
isShowingWithoutId : getIsShowingWithoutId ( loadingState ) ,
84
97
reduxProjectTitle : state . scratchGui . projectTitle
85
98
} ;
0 commit comments