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

Story block: Add more media options to choose from in the editor #19628

Merged
merged 6 commits into from
May 6, 2021
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: other

Comment: Story block: Add more media options to choose from in the editor
17 changes: 13 additions & 4 deletions projects/plugins/jetpack/extensions/blocks/story/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import './editor.scss';

const ALLOWED_MEDIA_TYPES = [ 'image', 'video' ];

export const pickRelevantMediaFiles = ( media, sizeSlug = 'large' ) => {
export const pickRelevantMediaFiles = media => {
const mediaProps = pick( media, [
'alt',
'title',
Expand All @@ -37,8 +37,8 @@ export const pickRelevantMediaFiles = ( media, sizeSlug = 'large' ) => {
'height',
] );
mediaProps.url =
get( media, [ 'sizes', sizeSlug, 'url' ] ) ||
get( media, [ 'media_details', 'sizes', sizeSlug, 'source_url' ] ) ||
get( media, [ 'sizes', 'large', 'url' ] ) ||
get( media, [ 'media_details', 'sizes', 'large', 'source_url' ] ) ||
get( media, [ 'media_details', 'videopress', 'original' ] ) ||
get( media, [ 'media_details', 'original', 'url' ] ) ||
media.url;
Expand All @@ -63,7 +63,16 @@ export default withNotices( function StoryEdit( {
const lockName = 'storyBlockLock';

const onSelectMedia = newMediaFiles => {
const allMedia = newMediaFiles.map( file => pickRelevantMediaFiles( file ) );
const allMedia = newMediaFiles
.map( newMedia => {
// MediaPlaceholder passes only the media ids as value to MediaUpload, so we're only getting those back
if ( ! isNaN( newMedia ) ) {
const existingMedia = mediaFiles.find( mediaFile => mediaFile.id === newMedia );
return existingMedia || { id: newMedia };
}
return newMedia;
} )
.map( pickRelevantMediaFiles );
const uploadedMedias = allMedia.filter( media => ! isBlobURL( media.url ) );
// prevent saving blob urls in mediaFiles block attribute
if ( allMedia.length !== uploadedMedias.length ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if ( isCurrentUserConnected() && 'function' === typeof useBlockEditContext ) {
'core/media-text',
'jetpack/image-compare',
'jetpack/slideshow',
'jetpack/story',
'jetpack/tiled-gallery',
];

Expand Down