Skip to content

Commit

Permalink
Set post link text if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
mmtr committed Sep 28, 2020
1 parent a79d32c commit 514d09f
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions extensions/blocks/simple-payments/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ class SimplePaymentsEdit extends Component {
this.saveProduct();
}

if ( postLinkUrl && postLinkUrl !== attributes.postLinkUrl ) {
setAttributes( { postLinkUrl } );
}

if ( ! attributes.postLinkText ) {
setAttributes( { postLinkText: __( 'Visit the site to purchase.', 'jetpack' ) } );
const shouldUpdatePostLinkUrl =
postLinkUrl && postLinkUrl !== this.props.attributes.postLinkUrl;
const shouldUpdatePostLinkText = ! this.props.attributes.postLinkText;
if ( shouldUpdatePostLinkUrl || shouldUpdatePostLinkText ) {
setAttributes( {
...( shouldUpdatePostLinkUrl && { postLinkUrl } ),
...( shouldUpdatePostLinkText && {
postLinkText: __( 'Visit the site to purchase.', 'jetpack' ),
} ),
} );
}
}

Expand All @@ -88,12 +92,16 @@ class SimplePaymentsEdit extends Component {
this.validateAttributes();
}

if ( postLinkUrl && postLinkUrl !== this.props.attributes.postLinkUrl ) {
setAttributes( { postLinkUrl } );
}

if ( ! this.props.attributes.postLinkText ) {
setAttributes( { postLinkText: __( 'Visit the site to purchase.', 'jetpack' ) } );
const shouldUpdatePostLinkUrl =
postLinkUrl && postLinkUrl !== this.props.attributes.postLinkUrl;
const shouldUpdatePostLinkText = ! this.props.attributes.postLinkText;
if ( shouldUpdatePostLinkUrl || shouldUpdatePostLinkText ) {
setAttributes( {
...( shouldUpdatePostLinkUrl && { postLinkUrl } ),
...( shouldUpdatePostLinkText && {
postLinkText: __( 'Visit the site to purchase.', 'jetpack' ),
} ),
} );
}
}

Expand Down

0 comments on commit 514d09f

Please sign in to comment.