Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

[Gutenberg] Add Popular homepage block. #32

Merged
merged 15 commits into from
Apr 12, 2018
Merged

Conversation

miina
Copy link
Contributor

@miina miina commented Apr 5, 2018

Based on #12.
Fixes #23.

Intends to:

  • Enable filtering posts by rating;
  • Pull adventure post data dynamically;
  • Frontend render for Top adventures;
  • Display the correct term;

This PR is blocked by #7.

@miina miina changed the title [WIP] [Gutenberg] Add Popular homepage block. [Gutenberg] Add Popular homepage block. Apr 11, 2018
Copy link
Contributor

@kienstra kienstra left a comment

Choose a reason for hiding this comment

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

Good Work, A Few Points

Hi @miina,
Thanks for adding this 'Popular' homepage block.

It looks like this PR uses commits from #33, so I tried to keep the scope of the review to the diff between this PR and #33.

There will probably be more merge conflicts after merging #33.

I'm trying to merge that first, as it seems like a big dependency.

Thanks!

* Adds meta boxes for adventure post type.
*/
public function add_adventure_meta_boxes() {
add_meta_box( 'amp_travel_adventure_meta', __( 'Adventure details' ), array( $this, 'adventure_meta_box_html' ), 'adventure', 'side' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add a text domain:

__( 'Adventure details', 'travel' ),

*/
public function adventure_meta_box_html() {
global $post;
$adventure_custom = get_post_custom( $post->ID );
Copy link
Contributor

Choose a reason for hiding this comment

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

How about calling get_post_custom() without an argument? It looks like that defaults to the global post ID, and it worked locally in briefly testing it.

$adventure_custom = get_post_custom( $post->ID );
$price = isset( $adventure_custom['amp_travel_price'][0] ) ? $adventure_custom['amp_travel_price'][0] : '';
?>
<label for='amp_travel_price'><?php esc_attr_e( 'Price (USD)', 'travel' ); ?></label>
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be esc_html_e() instead of esc_attr_e()?

}

if ( isset( $_POST['amp_travel_price'] ) ) {
update_post_meta( $post->ID, 'amp_travel_price', esc_attr( $_POST['amp_travel_price'] ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this use get_the_ID() instead of $post->ID? This works locally.

* Saves the custom meta.
*/
public function save_adventure_post() {
if ( ! empty( $_POST ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This might not be needed. If $_POST is empty, the function will return in the next conditional when isset( $_POST['amp_travel_price'] ) is false.


if ( ! empty( $attributes['heading'] ) ) {
$output .= '<header class="max-width-3 mx-auto px1 md-px2">
<h3 class="h1 bold line-height-2 md-hide lg-hide" aria-hidden="true">' . esc_attr( $attributes['heading'] ) . '</h3>
Copy link
Contributor

@kienstra kienstra Apr 11, 2018

Choose a reason for hiding this comment

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

Could this and the line below use esc_html( $attributes['heading'] ) instead of esc_attr()?

</div>
</div>
<div class="h2 line-height-2 mb1">
<span class="travel-results-result-text">' . esc_attr( get_the_title( $adventure->ID ) ) . '</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this please use esc_html():

esc_html( get_the_title( $adventure->ID ) )

<div class="h2 line-height-2 mb1">
<span class="travel-results-result-text">' . esc_attr( get_the_title( $adventure->ID ) ) . '</span>
<span class="travel-results-result-subtext h3">•</span>
<span class="travel-results-result-subtext h3">$&nbsp;</span><span class="black bold">' . esc_attr( $price ) . '</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this please use esc_html():

esc_html( $price )


$output .= '</div>
</div>
<span class="travel-results-result-subtext mr1">' . esc_attr( $comments->approved ) . esc_attr__( ' Reviews' ) . '</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be something like:

sprintf( esc_html__( '%d Reviews', 'travel' ), esc_html( $comments->approved ) )

With a translators comment above:

<?php /* translators: %d: The number of reviews */ ?>

</div>
<span class="travel-results-result-subtext mr1">' . esc_attr( $comments->approved ) . esc_attr__( ' Reviews' ) . '</span>
<span class="travel-results-result-subtext"><svg class="travel-icon" viewBox="0 0 77 100"><g fill="none" fillRule="evenodd"><path stroke="currentColor" strokeWidth="7.5" d="M38.794 93.248C58.264 67.825 68 49.692 68 38.848 68 22.365 54.57 9 38 9S8 22.364 8 38.85c0 10.842 9.735 28.975 29.206 54.398a1 1 0 0 0 1.588 0z"></path><circle cx="38" cy="39" r="10" fill="currentColor"></circle></g></svg>
' . esc_attr( $location ) . '</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please change this to esc_html( $location )

@miina
Copy link
Contributor Author

miina commented Apr 12, 2018

@kienstra Thanks for reviewing, made the changes + some other small changes found when testing the block.

@miina
Copy link
Contributor Author

miina commented Apr 12, 2018

Note that the heading of the block is static, looks like the texts of dynamic blocks can't be edited directly as with other blocks (at least with the Gutenberg stable version as of current moment) and making the heading editable is something to look into later.

This was the only remaining issue in the PR.
So I made this change on my own to merge it.
There were conflicts in:
assets/css/editor-blocks.css
includes/class-amp-travel-blocks.php
Retain edits from both develop and this branch:
feature/23-popular_block
Also, change order of register_block_travel_popular()
and render_block_travel_popular()
But make no change in those methods.
@kienstra
Copy link
Contributor

kienstra commented Apr 12, 2018

Approved

Hi @miina,
Thanks for your great work here. As you mentioned, the heading of this can't be edited now, as this is a dynamic block. We might revisit this later.

Also, as you mentioned, this depends on Issue #7 (PR #33).

These look to have been from PR #33.
And they might be valid.
But defer the discussion of those to that PR.
@kienstra
Copy link
Contributor

kienstra commented Apr 12, 2018

Deferring Merge Until #33 Merged

As this has commits from #33, I'm going to try to merge that PR before this.

There were conflics in:
assets/css/editor-blocks.css
includes/class-amp-travel-theme.php
In AMP_Travel_Theme, these were simply from
reorganizing that class in a recent other PR.
@kienstra
Copy link
Contributor

Merging

With #33 merged into develop, I merged develop into this branch. It's now ready to merge.

@kienstra kienstra merged commit 8f4c721 into develop Apr 12, 2018
@kienstra kienstra deleted the feature/23-popular_block branch April 12, 2018 22:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants