Skip to content

Commit

Permalink
VideoPress: fix replace video from toolbar issues (#28432)
Browse files Browse the repository at this point in the history
* propagate new vide data when replacing video

* changelog

* fix issue when picking guid from media item
  • Loading branch information
retrofox authored Jan 18, 2023
1 parent 5d8626b commit 9439f40
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

VideoPress: fix replace video by uploading a new file issue
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ const usePosterAndTitleUpdate = ( { setAttributes, videoData, onDone } ) => {

Promise.allSettled( updates ).then( () => {
setIsFinishingUpdate( false );
setAttributes( videoData );
onDone();
onDone( videoData );
} );
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,19 @@ export default function VideoPressEdit( {

// Render uploading block view
if ( isUploadingFile ) {
const handleDoneUpload = () => {
const handleDoneUpload = newVideoData => {
setIsUploadingFile( false );
if ( isReplacingFile.isReplacing ) {
const newBlockAttributes = {
...attributes,
...newVideoData,
};

// Delete attributes that are not needed.
delete newBlockAttributes.poster;

setIsReplacingFile( { isReplacing: false, prevAttrs: {} } );
replaceBlock( clientId, createBlock( 'videopress/video', { ...attributes } ) );
replaceBlock( clientId, createBlock( 'videopress/video', newBlockAttributes ) );
}
};

Expand Down Expand Up @@ -498,8 +506,12 @@ export default function VideoPressEdit( {
setFileToUpload( media );
} }
onSelectVideoFromLibrary={ media => {
const mediaGuid = media.videopress_guid?.[ 0 ] ?? media.videopress_guid;
// Depending on the endpoint, `videopress_guid` can be an array or a string.
const mediaGuid = Array.isArray( media.videopress_guid )
? media.videopress_guid[ 0 ]
: media.videopress_guid;
if ( ! mediaGuid ) {
debug( 'No media guid provided' );
return;
}

Expand Down

0 comments on commit 9439f40

Please sign in to comment.