-
Notifications
You must be signed in to change notification settings - Fork 6
[Gutenberg] Add "Featured Destinations" homepage block #34
Conversation
@DavidCramer Started adding the featured block within this commit: 9f745ae What's missing:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<div class='form-field form-required location-cover-image-wrap'> | ||
<label for='location-cover-image'><?php esc_html_e( 'Activity Cover Image' ); ?></label> | ||
<input type='hidden' id='location-cover-image-value' class='small-text' name='location-cover-image-value' value='' /> | ||
<input type='button' id='location-cover-image' class='button location-cover-image-upload-button' value='<?php esc_html_e( 'Upload' ); ?>' /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, the new "Select" text looks good.
|
||
} ); | ||
|
||
component.removeButton.on( 'click', function( event ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have time, could you display this component.removeButton
only if there's no selected image? But I'd call this a "nice to have."
It could be confusing to have a "Remove" button if there's no image to remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making this change, @miina. This works well.
/** | ||
* Init. | ||
*/ | ||
component.init = function init() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the selected image is persisting even after saving a new "Location"
- Go to
/wp-admin/edit-tags.php?taxonomy=location
- Fill in all of the fields, and select an image
- Click "Add New Location"
- Expected: the selected image doesn't display anymore, as the rest of the fields are empty
- Actual: the selected image still displays:
But the workflow looks fine when editing a location:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this.
blocks/featured/index.js
Outdated
featuredLocations: '/wp/v2/locations?per_page=6&meta_value=1&meta_key=amp_travel_featured' | ||
}; | ||
} )( ( { featuredLocations } ) => { // eslint-disable-line | ||
const hasLocations = Array.isArray( featuredLocations.data ) && 6 === featuredLocations.data.length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about making this
featuredLocations.data.length >= 6
instead of:
6 === featuredLocations.data.length
It might be easy for someone to change AMP_Travel_Blocks::$featured_locations_count
, without noticing that this line requires it to be exactly 6
.
*/ | ||
public function add_location_meta_fields() { | ||
?> | ||
<div class='form-field form-required location-cover-image-wrap'> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this method please use double quotes for the attributes, like:
<div class="form-field form-required location-cover-image-wrap">
And likewise for edit_location_meta_fields()
<td> | ||
<?php wp_nonce_field( basename( __FILE__ ), 'travel_location_meta_nonce' ); ?> | ||
|
||
<input type='hidden' id='location-cover-image-value' class='small-text' name='location-cover-image-value' value='<?php esc_attr( $cover_img_id ); ?>' /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<?php esc_attr( $cover_img_id ); ?>
This could probably use an echo
at the beginning:
<?php echo esc_attr( $cover_img_id ); ?>
includes/class-amp-travel-blocks.php
Outdated
$location_img_srcset = wp_get_attachment_image_srcset( $location_img_id, 'full' ); | ||
|
||
$output .= '<a href="' . esc_url( get_term_link( $location['term_id'] ) ) . '" class="travel-featured-tile flex flex-auto relative travel-featured-color-' . | ||
esc_html( $location_params[ $i ]['color'] ) . '"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
esc_html( $location_params[ $i ]['color']
Could this use esc_attr()
instead, as this is for an attribute (class)
includes/class-amp-travel-blocks.php
Outdated
esc_html( $location_params[ $i ]['color'] ) . '"> | ||
<amp-img class="travel-object-cover flex-auto" layout="responsive" width="' . | ||
esc_html( $location_params[ $i ]['width'] ) . '" height="' . | ||
esc_html( $location_params[ $i ]['height'] ) . '" srcset="' . esc_html( $location_img_srcset ) . '" src="' . esc_url( $location_img_src[0] ) . '""></amp-img> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this line and the line above use esc_attr()
for all of the attributes? But maybe there was an issue in using esc_attr()
with the srcset
.
blocks/featured/index.js
Outdated
icon="admin-post" | ||
label={ __( 'Locations' ) } | ||
> | ||
{ __( 'Not enough featured locations found, add at least six to use the block.' ) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be easier to use if the message mentioned "Location" terms, maybe like:
Not enough featured locations found. Please add at least six "Locations" terms, select an image, and check "Featured destination."
includes/class-amp-travel-blocks.php
Outdated
* | ||
* @var int | ||
*/ | ||
public static $featured_locations_count = 6; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class is instantiated, so would there be a need to make this static? If not, could you please remove static
, and change this to something like:
const FEATURED_LOCATIONS_COUNT = 6;
Then, references to it could change from self::$featured_locations_count
to self::FEATURED_LOCATIONS_COUNT
This is outside the diff of this PR, but could you please do the same thing to $popular_posts_count
below?
Editor Styling This is probably outside the scope of this PR. But we might revisit the styling of this block in the editor. The images appear much taller than on the front-end. |
@kienstra Thanks for all the found issues! These should be addressed now, also improved the Gutenberg styling a little bit. |
Approved, Other Than Merge Conflicts Hi @miina, Could you please resolve these merge conflicts? I caused them by merging in #16. I tried to resolve them on my own, but it looks like editor-blocks.js will need to be rebuilt. And this command didn't seem to rebuild it properly:
I probably missed something 😄 Thanks! |
@kienstra, Merged develop & resolved conflicts, sorry for not noticing the conflicts before. |
Before, there was an error in Gutenberg, as renderStaticFeaturedBlock() wasn't defined. This PR removed that function. So change save() to return null, as this looks to be a dynamic block. AMP_Travel_Blocks::render_block_travel_featured() renders the output on the front-end. Also, compile js/editor-blocks.js, using: npm run build.
Merging, Request For Sanity Check Hi @miina, Could you please sanity-check this commit? I changed the |
Hey @kienstra, the commit you did looks good, thanks for that! |
Based on #12 and #31.Aims to do the following:
location
term.