Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Podcast player: Render podcast header markup by server-side #15221

Merged
merged 9 commits into from
Apr 1, 2020

Conversation

retrofox
Copy link
Contributor

This PR renders the podcast header on the server-side.

Changes proposed in this Pull Request:

It gets the podcast data from the Podcast RSS and renders the block HTML on the server-side, following the same structure which is applied by the client.
It adds a simple template system in order to isolate the process, suggested by @getdave here.

Testing instructions:

In the front-end disable javascript. For this:

a) Open Chrome DevTools.
b) Press Control+Shift+P or Command+Shift+P (Mac) to open the Command Menu.
c) Start typing javascript, select Disable JavaScript, and then press Enter to run the command. JavaScript is now disabled.
image

Once it's disabled, do a hard-refresh. You should be able to still see the podcast header. Same HTML structure. Styles should be applied properly.

image

image

Proposed changelog entry for your changes:

  • Render Podcast header markup in the server-side

@jetpackbot
Copy link
Collaborator

jetpackbot commented Mar 31, 2020

Warnings
⚠️

pre-commit hook was skipped for one or more commits

This is an automated check which relies on PULL_REQUEST_TEMPLATE. We encourage you to follow that template as it helps Jetpack maintainers do their job. If you think 'Testing instructions' or 'Proposed changelog entry' are not needed for your PR - please explain why you think so. Thanks for cooperation 🤖

Generated by 🚫 dangerJS against 0c4b7a0

@obenland
Copy link
Member

obenland commented Mar 31, 2020

I'm not sure moving the functions into a new file is what @getdave had in mind in #15203 (review)
I'm equally unsure how we can templify them better, given the amount of conditionals we have here.

As it stands now, I'd consider it inferior to #15203.

Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

Update: @retrofox to save you the time I pushed changes I was detailing below. This way you can throw them away without having wasted any time if you don't like them. Personally I feel that extracting all HTML rendering into dedicated "templates" rather than building HTML in functions (🤢 ) will make this all easier to maintain. But I appreciate I may be in a minority...


Wow thanks for the refactor @retrofox.

I'm not sure moving the functions into a new file is what @getdave had in mind in #15203 (review)

I think this is almost what I had in mind. We should aim to have a single "component" per template file. So you shouldn't really have any functions within the files within /templates. Thanks to the way render works you can now treat the individual files in /templates sort of like React components so there should be no need to include functions within the templates themselves.

I'm equally unsure how we can templify them better, given the amount of conditionals we have here.

I don't understand why the conditionals make any difference. Perhaps I'm missing something critical?

As it stands now, I'd consider it inferior to #15203.

I trust your judgement. However, would it be ok for you to explain why you consider it inferior? I assume because you don't like the output buffered approach (granted it's not the "WordPress way"!)?

@retrofox
Copy link
Contributor Author

retrofox commented Apr 1, 2020

I'm not sure moving the functions into a new file is what @getdave had in mind in #15203 (review)

Personally I prefer this approach but also am not 100% sure about the simplicity that it could bring, though. However, the fact that to be able to isolate the templates is a winning point.

I'm equally unsure how we can templify them better, given the amount of conditionals we have here.

This is something needed with or without templates. @getdave pushed a nice commit which improves the usage of the templates.

@retrofox retrofox added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Apr 1, 2020
@retrofox retrofox requested a review from a team April 1, 2020 11:40
Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

Overall this is good, but I'm not sure about having to manual disable all these PHPCS rules all the time.

For now this is ok, but in the longer term I wonder whether we can be cleverer about this?

If you want to ship "as is" with the disable rules I'm cool with that, but we should consider having follow up Issues for the alternative approach I suggest in this review.

Comment on lines +10 to +11
// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
// phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
Copy link
Contributor

@getdave getdave Apr 1, 2020

Choose a reason for hiding this comment

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

I wish there was a better way to do this?

It looks like we can set certain variables to be ignored from this UNdefinedVariable check.

https://github.com/sirbrillig/phpcs-variable-analysis#customization

I proposed we

  • update the var from $data to $templateProps
  • add a rule to the .phpcs.xml.dist under the validUndefinedVariableNames property to ignore the var $templateProps.
  • update the code in the render so that it doesn't perform an extract() and simply passes the $templateProps array.
  • the individual templates can then extract the data from $templateProps (or not) as required without having to worry about disabling phpcs warnings.

@jeherve what do you think about this? Having to litter each template with these disable rules feels really horrible.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that sounds like a good plan!

@retrofox
Copy link
Contributor Author

retrofox commented Apr 1, 2020

If you want to ship "as is" with the disable rules I'm cool with that

@getdave yes, I think it's shippable. Let's create a new card for this in our dashboard.

Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

Let's ship what we have and followup as you say. Thanks for this 👍

@retrofox retrofox merged commit 4dec592 into feature/podcast-player Apr 1, 2020
@retrofox retrofox deleted the update/podcast-header-ss-rendering branch April 1, 2020 14:16
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Needs Review This PR is ready for review. labels Apr 1, 2020
@retrofox retrofox changed the title Update/podcast header ss rendering Podcast player: podcast header markup by server-side Apr 2, 2020
@retrofox retrofox changed the title Podcast player: podcast header markup by server-side Podcast player: Render podcast header markup by server-side Apr 2, 2020
brbrr pushed a commit that referenced this pull request Apr 2, 2020
* podcast-player: add template render function

* podcast-player: add header template

* podcast-player: render podcast title

* [not verified] Fix to use dedicated templates

* podcast-player: fix sniffer errors. esc values. rename vars

* podcast-player: add disabling sniffer rule doc

* Update extensions/blocks/podcast-player/podcast-player.php

Co-Authored-By: Jeremy Herve <[email protected]>

* podcast-player: rename render data param name

* podcast-player: improve doc

Co-authored-by: Dave Smith <[email protected]>
Co-authored-by: Jeremy Herve <[email protected]>
obenland added a commit that referenced this pull request Apr 3, 2020
* Force refetch of feed when identical URL is submitted #15213 (#15219)

* [not verified] Force refetch of feed when identical URL is submitted

* [not verified] Outsource context through ticket link

Co-authored-by: Dave Smith <[email protected]>

* Podcast Player: Rename "episode" to "track" for consistency (#15211)

* [not verified] Rename 'episode' to 'track'

* [not verified] Prefix header class names to avoid accidental overrides

* [not verified] Replace render ternaries with &&

* [not verified] Increase image selector specificity

* Simplify podcast title selector
+ add target & rel attributes if is a link

* [not verified] A few more class name changes before scoping

* Rename "cover" class name to "current-track-info"

* Add class to the cover img element

* Make sure &&s don't render any extras when falsy

* [not verified] use audio element from me.js (#15215)

* Podcast Player: Scope podcast player styles for consistency (#15201)

* [not verified] Namespace styles with parent block class

* [not verified] Fix colors inconsistency with master
...with a bonus fix for inactive link colors! \o/

* Podcast Player - make feed fetch call cancellable and cancel on Block removal. (#15228)

* Make fetch call cancellable and cancel on unmount.

* Use optional chaining to reduce complexity

Seems to have been added to Calypso build here

https://github.com/Automattic/wp-calypso/blob/c3608b5c2b656cad1209f52b0e2229838c2592ea/packages/calypso-build/CHANGELOG.md#510

…so should be safe to used as it will be polyfilled.

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining

* Fix to also exit early on happy .then() path if promise has been cancelled

Kudos to #15228 (comment)

* Add interaction overlay (#15226)

* Update/podcast header ss rendering (#15221)

* podcast-player: add template render function

* podcast-player: add header template

* podcast-player: render podcast title

* [not verified] Fix to use dedicated templates

* podcast-player: fix sniffer errors. esc values. rename vars

* podcast-player: add disabling sniffer rule doc

* Update extensions/blocks/podcast-player/podcast-player.php

Co-Authored-By: Jeremy Herve <[email protected]>

* podcast-player: rename render data param name

* podcast-player: improve doc

Co-authored-by: Dave Smith <[email protected]>
Co-authored-by: Jeremy Herve <[email protected]>

* Podcast Player: format active track in SS (#15230)

* podcast-player: add playlist-track template

* podcast-player: set actve track in SS

* podcast-player: format the actve track in SS

* podcast-player: fix adding `is-active` css Class

* podcast-player: define track vars

* podcast-player: don't create var needlessly

* podcast-player: simplify applying classes. Porps to @obenland

* podcast-player: update aria according on #15207

* Fix invalid HTML for header cover images

Co-authored-by: Jerry Jones <[email protected]>

* Podcast Player Accessibility and Interactions (#15207)

* Uses aria-current to indicate current track
* Announcement if track has error.
* Announces loadings state and new title and description
* Announces paused state
* Adds headings and description to playlist
* Adds visually hidden episode title for link context
* Adds aria-labelledby and aria-describedby to playlist to make it be announced as a group with context

* Podcast Player: Set colors to podcast title and description, in server-side. (#15243)

* [not verified] [not verified] podcast-player: apply primary color to title

* podcast-player: apply color to the podcast title

* podcast-player: appluy color to description

* podcast-player: remove extra styles

* podcast-player: fix CSS silly mistake :-/

* Cleaned up repeated color css rules for .jetpack-podcast-player__podcast-title and apply the color even if it's not a link

* podcast-player: simplify applying color to desc

* podcast-plater: remove __container CSS class

Co-authored-by: Jerry Jones <[email protected]>

* Add a couple of common keywords

Props @joelwills.

* Podcast Player: truncate podcast description if too long (#15253)

* Podcast Player: change error notice text when user is trying to embed a Spotify hosted podcast (#15254)

* Podcast Player: change error notice text when user is trying to embed a Spotify hosted podcast

* Add linting exemption

* Podcast Player: Document template variables (#15250)

* Update/podcast colors client side (#15249)

* podcast-player: pass colors to children components

* [not verified] podcast-player: set color in podcast title

* [not verified] podcast-player: set podcast title color

* Podcast Player: Add loading and default states (#15234)

* default state style

* add player placeholder

* fix loading bar width

* colocate default styles

* add explanations for 'magic' values

* Remove unnecessary units (and selector)

* use proper escaping for context

* add is_array check for

* use empty check instead of isset

* fix text bug in IE11

* simplify formatting of the error message

* edit: set use callback dependencies properly

* reset vertical padding for player section element

* Add opening quote

Props @marekhrabe

Co-authored-by: Dave Smith <[email protected]>
Co-authored-by: Bart Kalisz <[email protected]>
Co-authored-by: Marek Hrabe <[email protected]>
Co-authored-by: Damián Suárez <[email protected]>
Co-authored-by: Jeremy Herve <[email protected]>
Co-authored-by: Jerry Jones <[email protected]>
Co-authored-by: Michael P. Pfeiffer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants