Skip to content

Commit

Permalink
Refactor for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Aug 9, 2018
1 parent 6437c4a commit 0bcaa57
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,26 @@ class MaybeTagsPanel extends Component {
constructor( props ) {
super( props );
this.state = {
hadTags: props.hasTags,
hadTagsWhenOpeningThePanel: props.hasTags,
};
}

/*
* We only want to show the tag panel if the post didn't have
* any tags when the user hit the Publish button.
*
* We can't use the prop.hasTags because it'll change to true
* if the user adds a new tag within the pre-publish panel.
* This would force a re-render and a new prop.hasTags check,
* hiding this panel and keeping the user from adding
* more than one tag.
*/
render() {
if ( this.state.hadTags ) {
return null;
if ( ! this.state.hadTagsWhenOpeningThePanel ) {
return <TagsPanel />;
}

return <TagsPanel />;
return null;
}
}

Expand Down

1 comment on commit 0bcaa57

@tofumatt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 So much clearer! 👍

Please sign in to comment.