Skip to content

Commit

Permalink
Refactor componentDidUpdate to accomodate separate flows
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jun 11, 2018
1 parent bcdb811 commit c9829bc
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions edit-post/components/browser-url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,25 @@ export class BrowserURL extends Component {
const { historyId } = this.state;

if ( postStatus === 'trash' ) {
window.location.href = getPostTrashedURL( postId, postType );
}

if ( postId === prevProps.postId && postId === historyId ) {
this.setTrashURL( postId, postType );
return;
}

if ( postStatus !== 'auto-draft' ) {
if ( ( postId !== prevProps.postId || postId !== historyId ) && postStatus !== 'auto-draft' ) {
this.setBrowserURL( postId );
}
}

/**
* Navigates the browser to the post trashed URL to show a notice about the trashed post.
*
* @param {number} postId Post ID.
* @param {string} postType Post Type.
*/
setTrashURL( postId, postType ) {
window.location.href = getPostTrashedURL( postId, postType );
}

/**
* Replaces the browser URL with a post editor link for the given post ID.
*
Expand Down

0 comments on commit c9829bc

Please sign in to comment.