From c9829bceafd3c22329b0a1306200896ea358edd9 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Mon, 11 Jun 2018 11:43:33 +0100 Subject: [PATCH] Refactor componentDidUpdate to accomodate separate flows --- edit-post/components/browser-url/index.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/edit-post/components/browser-url/index.js b/edit-post/components/browser-url/index.js index 00ae3213fe30d..7d50e89772540 100644 --- a/edit-post/components/browser-url/index.js +++ b/edit-post/components/browser-url/index.js @@ -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. *