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

Video block: Gracefully auto-transform into Embed if embeddable resource provided #4990

Closed
wants to merge 3 commits into from

Conversation

mcsf
Copy link
Contributor

@mcsf mcsf commented Feb 10, 2018

Partly fixes #4922. This is an experimental take on the parent issue which eschews the display of failure information. More than anything else, it needs feedback on whether it's a feature worth having, and—if so—it needs design feedback. Moreover, adding this automated correction behavior doesn't exclude displaying failure information if we can't handle the video automatically.

Description

When adding a new Video block, if the URL provided doesn't correspond to a usable video file (or if its loading otherwise fails) and the URL corresponds to an embeddable resource, then automatically transform the block into a proper Embed block.

gutenberg-video-to-embed

How Has This Been Tested?

Try adding a Video block with the following kinds of values:

  • A valid video URL (e.g. https://upload.wikimedia.org/wikipedia/commons/9/96/Curiosity%27s_Seven_Minutes_of_Terror.ogv)
  • A valid video URL while the network is down
  • An invalid video URL (e.g. a mis-copied link like https://upload.wikimedia.org/wikipedia/commons/9/96/Curiosity%27s_Seven_Minutes_of_Terror.og)
  • A valid embeddable URL (e.g. https://youtube.com/watch?v=lNHhmz-smlE)
  • An invalid embeddable URL (e.g. https://youtube.com/watch?v=lNHhmz-sml)

Verify that the block is only converted to Embed when provided a valid embeddable URL.

Types of changes

Tentative UX enhancement

A technical aside

This pull request refactors the Video block's edit method into a functional component. For this, it extended withState in order to accommodate its use case, allowing prop-dependent state initializations. If this is a desirable addition, I can spawn a new PR for it.

Because of the refactor, the Commits view may provide diffs that are easier to review.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code has proper inline documentation.

mcsf added 3 commits February 10, 2018 18:56
Fixes #4922. If an error is detected in a video block's video element,
check whether the provided source is actually an embeddable resource. If
so, convert the failed video block to an embed one.
@mcsf mcsf added [Type] Question Questions about the design or development of the editor. [Feature] Blocks Overall functionality of blocks labels Feb 10, 2018
@youknowriad youknowriad added the Needs Design Feedback Needs general design feedback. label Feb 12, 2018
} );

console.log( 'tryEmbed; querying' );
window.fetch( apiURL, { credentials: 'include' } ).then(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we transform this to class component to avoid calling setState on unmounted components?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Either that, or we source a bound fetch like:

#4839 (comment)

@youknowriad
Copy link
Contributor

Waiting for an UX/design review to do a more in-depth code review.

@jasmussen
Copy link
Contributor

This seems like an impressive enhancement, though it's a little difficult for me to understand exactly what goes on. Perhaps you can elaborate a bit?

What seems to happen is that even if I try to embed an invalid URL, it creates an embed of sorts. It would seem more obvious to me if we showed an error here, perhaps.

I noticed an issue, btw, not sure if this is both on master and in this branch:

autosave

Steps to reproduce:

  1. Insert video block in fresh post
  2. Paste video URL, valid or invalid, doesn't matter
  3. Wait for autosave, or invoke it manually
  4. Reload the page
  5. Insert video block again

The second time you insert a video block, it's born with the URL you pasted previously.

@mcsf
Copy link
Contributor Author

mcsf commented Mar 6, 2018

Thanks for having a look at this, @jasmussen, despite my inability to get back to you. :)

The parent issue has been closed, so I'm dropping this one.

@mcsf mcsf closed this Mar 6, 2018
@mcsf mcsf deleted the update/video-block-support-embed branch March 6, 2018 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks Needs Design Feedback Needs general design feedback. [Type] Question Questions about the design or development of the editor.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add failure information to the video block
3 participants