From d3b2901b6839581fd3c51fe9078f7af4edd55c5e Mon Sep 17 00:00:00 2001 From: Justin Foell <630830+jrfoell@users.noreply.github.com> Date: Fri, 27 Nov 2020 15:39:14 -0600 Subject: [PATCH] Fixed buttons, make sure som is passed to render --- readme.txt | 1 + src/WPStrava/Blocks/Activity.php | 7 +++- src/blocks/activity/edit.js | 12 +++++- src/blocks/activity/som-override.js | 63 ++++++++++++++--------------- 4 files changed, 49 insertions(+), 34 deletions(-) diff --git a/readme.txt b/readme.txt index 79d1489..705255c 100755 --- a/readme.txt +++ b/readme.txt @@ -118,6 +118,7 @@ Fix missing translation domain on "Save Changes" in settings. https://wordpress. Refined styles for responsive tables https://wordpress.org/support/topic/responsive-strava-activity-table/ Add activity description under image (if set) https://wordpress.org/support/topic/show-activity-description/ Add preview of activity in the block editor using server-side render +Add System of Measure override in Activity Block display options = 2.4.0 = diff --git a/src/WPStrava/Blocks/Activity.php b/src/WPStrava/Blocks/Activity.php index e624e98..20d4a47 100644 --- a/src/WPStrava/Blocks/Activity.php +++ b/src/WPStrava/Blocks/Activity.php @@ -41,6 +41,10 @@ class WPStrava_Blocks_Activity implements WPStrava_Blocks_Interface { 'type' => 'boolean', 'default' => false, ), + 'som' => array( + 'type' => 'string', + 'default' => null, + ), ), ) ); @@ -68,9 +72,10 @@ class WPStrava_Blocks_Activity implements WPStrava_Blocks_Interface { if ( $matches[1] ) { // Transform from block attributes to shortcode standard. $attributes = array( + 'id' => $matches[1], 'image_only' => isset( $attributes['imageOnly'] ) ? $attributes['imageOnly'] : false, 'markers' => isset( $attributes['displayMarkers'] ) ? $attributes['displayMarkers'] : false, - 'id' => $matches[1], + 'som' => ! empty( $attributes['som'] ) ? $attributes['som'] : null, ); $renderer = new WPStrava_ActivityRenderer(); diff --git a/src/blocks/activity/edit.js b/src/blocks/activity/edit.js index 9dd241e..8cb73ec 100644 --- a/src/blocks/activity/edit.js +++ b/src/blocks/activity/edit.js @@ -18,11 +18,13 @@ class Edit extends Component { this.switchBackToURLInput = this.switchBackToURLInput.bind( this ); this.toggleImageOnly = this.toggleImageOnly.bind( this ); this.toggleDisplayMarkers = this.toggleDisplayMarkers.bind( this ); + this.overrideSOM = this.overrideSOM.bind( this ); this.state = { url: this.props.attributes.url, imageOnly: this.props.attributes.imageOnly, displayMarkers: this.props.attributes.displayMarkers, + som: this.props.attributes.som, editingURL: isEmpty( this.props.attributes.url ) ? true : false, }; } @@ -49,12 +51,18 @@ class Edit extends Component { this.props.setAttributes( { displayMarkers: checked } ); } + overrideSOM( newSOM ) { + this.setState( { som: newSOM } ); + this.props.setAttributes( { som: newSOM } ); + } + render() { const { url, editingURL, imageOnly, displayMarkers, + som } = this.state; // Newly inserted block or we've clicked the edit button. @@ -83,6 +91,7 @@ class Edit extends Component { url: url, imageOnly: imageOnly, displayMarkers: displayMarkers, + som: som, } } /> @@ -100,7 +109,8 @@ class Edit extends Component { onChange={ (checked ) => this.toggleDisplayMarkers( checked ) } /> this.props.setAttributes( { som: value } ) } + onChange={ ( value ) => this.overrideSOM( value ) } + som={ som } /> diff --git a/src/blocks/activity/som-override.js b/src/blocks/activity/som-override.js index c1f1b82..3907a58 100644 --- a/src/blocks/activity/som-override.js +++ b/src/blocks/activity/som-override.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import mapValues from 'lodash'; - /** * WordPress dependencies */ @@ -12,44 +7,48 @@ import { } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; -const SOM_PRESETS = { - 'english': __( 'English', 'wp-strava' ), - 'metric': __( 'Metric', 'wp-strava' ), -}; - export default function SOMOverride( { + som, onChange, } ) { - function updateSOM( newSOM ) { + function updateSOM( som ) { return () => { - onChange( { som: newSOM } ); + onChange( som ); }; } return ( <>
- - { mapValues( SOM_PRESETS, ( key, label ) => { - return ( - - ); - } ) } - - +

+ { __( 'System of Measure (override from settings)' ) } +

+
+ + + + + +
);