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

VideoPress: clean video attributes that are not options when replacing the video file #28249

Merged
merged 5 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

VideoPress: clean video attributes that are not options when replacing the video file
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/**
* WordPress dependencies
*/

import { store as blockEditorStore } from '@wordpress/block-editor';
import {
BlockIcon,
useBlockProps,
InspectorControls,
BlockControls,
} from '@wordpress/block-editor';
import { createBlock } from '@wordpress/blocks';
import { Spinner, Placeholder, Button, withNotices } from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect, useDispatch } from '@wordpress/data';
Expand All @@ -32,13 +33,14 @@ import TracksControl from './components/tracks-control';
import VideoPressPlayer from './components/videopress-player';
import VideoPressUploader from './components/videopress-uploader';
import { description, title } from '.';
import './editor.scss';
/**
* Types
*/
import type { VideoBlockAttributes } from './types';
import type React from 'react';

import './editor.scss';

const debug = debugFactory( 'videopress:video:edit' );

const VIDEO_PREVIEW_ATTEMPTS_LIMIT = 10;
Expand Down Expand Up @@ -334,6 +336,8 @@ export default function VideoPressEdit( {
const [ isUploadingFile, setIsUploadingFile ] = useState( ! guid );
const [ fileToUpload, setFileToUpload ] = useState( null );

const { replaceBlock } = useDispatch( blockEditorStore );

// Replace video state
const [ isReplacingFile, setIsReplacingFile ] = useState< {
isReplacing: boolean;
Expand Down Expand Up @@ -370,6 +374,10 @@ export default function VideoPressEdit( {
if ( isUploadingFile ) {
const handleDoneUpload = () => {
setIsUploadingFile( false );
if ( isReplacingFile.isReplacing ) {
setIsReplacingFile( { isReplacing: false, prevAttrs: {} } );
replaceBlock( clientId, createBlock( 'videopress/video', { ...attributes } ) );
}
};

return (
Expand Down Expand Up @@ -458,13 +466,17 @@ export default function VideoPressEdit( {
setAttributes={ setAttributes }
attributes={ attributes }
onUploadFileStart={ media => {
// Store current attributes in case we wanto to cancel the replacing.
setIsReplacingFile( {
isReplacing: true,
prevAttrs: attributes,
} );

setAttributes( { id: null, guid: null } );
setIsUploadingFile( true );

// Clean relevant attributes to show the uploader placeholder.
setAttributes( { id: null, guid: null, cacheHtml: '', videoRatio: null } );

// Pass, through local state, the new file to upload.
setFileToUpload( media );
} }
onSelectVideoFromLibrary={ media => {
Expand Down