Skip to content

Commit

Permalink
Merge pull request #501 from wordpress-mobile/issue/372-post-title-wr…
Browse files Browse the repository at this point in the history
…iting-flow

Uses the global store for the post title and adds undo/redo support.
  • Loading branch information
diegoreymendez authored Jan 28, 2019
2 parents 8f45ed7 + 167d0ef commit 23aaed1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const AppProvider = ( { initialTitle, initialData, initialHtmlModeEnabled }: Pro
<AppContainer
initialHtml={ initialData }
initialHtmlModeEnabled={ initialHtmlModeEnabled }
title={ initialTitle } />
initialTitle={ initialTitle } />
);
};

Expand Down
35 changes: 20 additions & 15 deletions src/app/AppContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ type PropsType = {
showHtml: boolean,
editedPostContent: string,
title: string,
initialTitle: string,
initialHtml: string,
editTitle: string => mixed,
resetBlocks: Array<BlockType> => mixed,
setupEditor: ( mixed, ?mixed ) => mixed,
toggleBlockMode: ?string => mixed,
getBlocks: () => Array<BlockType>,
post: ?mixed,
};

type StateType = {
title: string,
};

class AppContainer extends React.Component<PropsType, StateType> {
class AppContainer extends React.Component<PropsType> {
lastHtml: ?string;
lastTitle: ?string;

Expand All @@ -37,19 +35,18 @@ class AppContainer extends React.Component<PropsType, StateType> {

const post = props.post || {
id: 1,
title: {
raw: props.initialTitle,
},
content: {
raw: props.initialHtml,
},
type: 'draft',
};

this.state = {
title: props.title,
};

props.setupEditor( post );
this.lastHtml = serialize( parse( props.initialHtml ) );
this.lastTitle = props.title;
this.lastTitle = props.initialTitle;

if ( props.initialHtmlModeEnabled && ! props.showHtml ) {
// enable html mode if the initial mode the parent wants it but we're not already in it
Expand All @@ -63,11 +60,13 @@ class AppContainer extends React.Component<PropsType, StateType> {
}

const html = serialize( this.props.getBlocks() );
const hasChanges = this.state.title !== this.lastTitle || this.lastHtml !== html;
const title = this.props.title;

RNReactNativeGutenbergBridge.provideToNative_Html( html, this.state.title, hasChanges );
const hasChanges = title !== this.lastTitle || html !== this.lastHtml;

this.lastTitle = this.state.title;
RNReactNativeGutenbergBridge.provideToNative_Html( html, title, hasChanges );

this.lastTitle = title;
this.lastHtml = html;
};

Expand All @@ -76,7 +75,7 @@ class AppContainer extends React.Component<PropsType, StateType> {
};

setTitleAction = ( title: string ) => {
this.setState( { title: title } );
this.props.editTitle( title );
};

updateHtmlAction = ( html: string = '' ) => {
Expand All @@ -92,7 +91,7 @@ class AppContainer extends React.Component<PropsType, StateType> {
toggleHtmlModeAction={ this.toggleHtmlModeAction }
setTitleAction={ this.setTitleAction }
updateHtmlAction={ this.updateHtmlAction }
title={ this.state.title }
title={ this.props.title }
/>
);
}
Expand All @@ -104,22 +103,28 @@ export default compose( [
getBlocks,
getBlockMode,
getEditedPostContent,
getEditedPostAttribute,
} = select( 'core/editor' );

return {
getBlocks,
showHtml: getBlockMode( rootClientId ) === 'html',
editedPostContent: getEditedPostContent(),
title: getEditedPostAttribute( 'title' ),
};
} ),
withDispatch( ( dispatch ) => {
const {
editPost,
resetBlocks,
setupEditor,
toggleBlockMode,
} = dispatch( 'core/editor' );

return {
editTitle( title ) {
editPost( { title: title } );
},
resetBlocks,
setupEditor,
toggleBlockMode,
Expand Down

0 comments on commit 23aaed1

Please sign in to comment.