Conversation
initial commit
starting playlist over
….may need core mod >_< storing ids in comment as ids attribute. moving to render callback....may need core mod >_<
….may need core mod >_< storing ids in comment as ids attribute. moving to render callback....may need core mod >_<
…mmits from airport terminals ✈
This simply moves the playlist block in the list of blocks imported and registered in core-blocks/index.js.
This commit generally accomplishes a few thing: - Removes any unused variables and functions - Ensuring all used functions and variables are declared - Simplifies some variable declarations - Fixing spacing to conform to WP style
This fixes up code style issues, adds correct docblocks, and removes unneccessary script rendering which isn't necessary during server rendering.
This wraps the shortcode output in a `figure` element with a class of `wp-block-playlist` applied so we can style the block accordingly.
This adds an editor.scss file to the playlist block that removes margins from `.wp-playlist-block` elements, to avoid margins being added as a default style by browsers.
This adds an align attribute to the playlist block and adds the proper alignment class to the markup on the front end to support alignments. This also deletes the style.scss file, which now seems unnecessary.
Playlist block updates @joemcgill fixed a ton of formatting and bugs. :D
| } | ||
|
|
||
| /** | ||
| * The function is used after the editor has enqueued playlist dependencies. |
There was a problem hiding this comment.
Nitpicks:
- Proper JSDoc alignment should have space before each
*of the body, after the tab - The newline between the JSDoc block and the function declaration may prevent it from being parsed correctly as associated. I suggest removing it.
|
|
||
| category: 'common', | ||
|
|
||
| attributes: { |
There was a problem hiding this comment.
It is a duplication, yes. You shouldn't need to define attributes here. I'll need to take a closer look to understand where things aren't working correctly.
| onSelectMedia( media ) { | ||
| const { setAttributes } = this.props; | ||
| //check if there are returned media items and set attributes when there are | ||
| if ( media && media[ 0 ].url ) { |
There was a problem hiding this comment.
I don't believe it will ever be unless there is an error maybe. We also have a similar check in the Audio block. I was matching that for consistency on the chance there was an instance I was unaware of: https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/audio/edit.js#L88
| onSelectMedia( media ) { | ||
| const { setAttributes } = this.props; | ||
| //check if there are returned media items and set attributes when there are | ||
| if ( media && media[ 0 ].url ) { |
There was a problem hiding this comment.
Why do we test for a url property which we have no intention of using? Do we care about the property, or just that media.length > 0 ?
There was a problem hiding this comment.
we shouldnt. I've removed the condition
| getMimeBaseType( type ) { | ||
| const { noticeOperations } = this.props; | ||
| if ( ! type ) { | ||
| noticeOperations.createErrorNotice( 'MIME Type could not be determined' ); |
There was a problem hiding this comment.
Nitpick: Why is "Type" capitalized?
There was a problem hiding this comment.
Noting that this message will be shown multiple times if multiple files cannot have their mime types determined.
There was a problem hiding this comment.
I've fixed the capitalization. Will think through the multiple messages bit. Can create an issue for it also after merge if we want to save that for future work.
| uploadFromFiles( event ) { | ||
| const { noticeOperations } = this.props; | ||
| if ( ! event.target.files ) { | ||
| noticeOperations.createErrorNotice( 'Files list provided is empty' ); |
There was a problem hiding this comment.
I sense that these should be localized?
| this.onUploadFiles( event.target.files ); | ||
| } | ||
|
|
||
| getMimeBaseType( type ) { |
There was a problem hiding this comment.
Minor: I don't expect a function prefixed with "get", particularly one like this which could theoretically be made generic (mime type has meaning outside the playlist block) to have a side-effect such as causing a notice to be created.
|
|
||
| category: 'common', | ||
|
|
||
| attributes: { |
There was a problem hiding this comment.
I tested locally and I see no obvious issues when removing attributes from this JavaScript file. Can you elaborate on what you're seeing?
|
|
||
| // Allowed type specified by consumer | ||
| const isAllowedType = ( fileType ) => { | ||
| return ( allowedType === '*' ) || startsWith( fileType, `${ allowedType }/` ); |
There was a problem hiding this comment.
I'm not really sure I understand.
- What failures were you seeing without these changes? You're not specifying
*so I don't see why it would have any impact to leave it. - Regardless of whether a
*is sensible, it exists and is already in use by the Files block. If we want to remove it, we need to remove any references to it. Speaking personally, I don't really like*as the wildcard. It seems like if someone wants any file to be uploaded, they should just omit theallowedTypeproperty altogether. But then again, this change has nothing to do with a Playlist block implementation and seems like it should be a separate effort.
| if ( ! isEqual( prevProps, this.props ) ) { | ||
| this.fetch( this.props ); | ||
| } | ||
| if ( this.state.response !== prevState.response ) { |
There was a problem hiding this comment.
It's a bit awkward to call a prop in response to a state change in componentDidUpdate, since a component manages its own state and begs the question why isn't the prop called at the time we're calling setState ? Our current implementation of ServerSideRender#fetch doesn't make this very easy to refactor, though...
There was a problem hiding this comment.
Is this a merge blocker? If not can we bring it to an issue after? I think there would have to be an alteration of ServerSideRender to accomplish this. I fear it may introduce more bugs
| */ | ||
|
|
||
| initializePlaylist() { | ||
| window.wp.playlist.initialize(); |
There was a problem hiding this comment.
@youknowriad, this block depends on both WordPress global wp.playlist and ServerSideRender component which is very backend tied. We need to do something about it. There should be reusable blocks which work everywhere and blocks which are reusable but WordPress specific. If we would draw this distinction we wouldn't have to worry about Code and Freeform anymore.
There was a problem hiding this comment.
yes, a first step would be to move it ouside of the packages like html or freeform. Later on, we'd need to rewrite wp.playlist as a Gutenberg package and then move the block to the packages as well.
lib/client-assets.php
Outdated
| 'post' => $post->ID, | ||
| ) ); | ||
| wp_enqueue_editor(); | ||
| wp_playlist_scripts( 'audio' ); |
There was a problem hiding this comment.
Shouldn't wp.playlist to be listed as a dependency of wp-block-library? It's referenced it in the code so I would assume that it needs to be.
|
Did you check how much more data users will have to load in their browser to be able to use this block? In particular, how much weigh all the files enqueued with those two lines: wp_playlist_scripts( 'audio' );
wp_playlist_scripts( 'video' ); |
|
@gziolo there was some previous discussion about this in an earlier review. It adds about 110-120kb : #7126 (comment) |
|
The additional weight is significant, particularly for a block which won't always be commonly used by a large subset of users. I wonder if it's something where we should employ the technique as we did for the HTML block and CodeMirror: gutenberg/components/code-editor/index.js Lines 28 to 58 in eac95b5 Also related: #8017 |
|
Raising other options to explore / consider:
|
|
@aduth After digging into this a bit today, I remember the thought process in adding the playlist enqueues to client-assets. If you remove the script calls from that file and create a playlist block, the block responds that it has encountered an error and cannot load. Saving/publishing the post and refreshing the editor magically allows it to render with it's dependencies. Something is not triggering in ServerSideRender at the right time to enqueue the dependencies. Still digging through this, but I think the best path forward is the lazy load solution proposed earlier with a state that says that it has dependencies before render. |
|
Related to #805 |
|
@melchoyce @mapk @jasmussen @karmatosed @youknowriad - what's the plan regarding this block? It isn't listed as the block planned for phase 2. |
Definitely not on our list of priorities right now. I'm going to close this because it hasn't been touched since September 2018. But I don't want to discourage contributors from working on something they're passionate about. If anyone feels like refactoring this and opening it back up, go ahead. 😄 |
This is a clean PR to add the playlist block to Gutenberg. There were merge conflicts that resulted in me needing to create a new branch based on the newest version of Gutenberg. Previous conversation can be found here: #7126
There is one bug currently with notices where the mismatched type error shows 4 of the same notice. Working through that and we should be good for another review.
CC: @karmatosed @noisysocks