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

Improve amp plugin compat #140

Merged
merged 13 commits into from
Jan 29, 2020
Binary file added assets/images/fallback-poster.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 6 additions & 15 deletions assets/src/edit-story/components/library/mediaLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { useConfig } from '../../app/config';
import UploadButton from '../uploadButton';
import useLibrary from './useLibrary';

Expand Down Expand Up @@ -124,17 +125,6 @@ const ButtonCSS = css`
border-radius: 3px;
`;

const SUPPORTED_IMAGE_TYPES = [
'image/png',
'image/jpeg',
'image/jpg',
'image/gif',
];

const SUPPORTED_VIDEO_TYPES = [
'video/mp4',
];

const FILTERS = [
{ filter: '', name: __( 'All', 'web-stories' ) },
{ filter: 'image', name: __( 'Images', 'web-stories' ) },
Expand All @@ -148,6 +138,7 @@ function MediaLibrary( { onInsert } ) {
state: { media, isMediaLoading, isMediaLoaded, mediaType, searchTerm },
actions: { loadMedia, setIsMediaLoading, setIsMediaLoaded, setMediaType, setSearchTerm },
} = useLibrary();
const { allowedMimeTypes: { image: allowedImageMimeTypes, video: allowedVideoMimeTypes } } = useConfig();

useEffect( loadMedia );

Expand Down Expand Up @@ -212,7 +203,7 @@ function MediaLibrary( { onInsert } ) {
const { src, mimeType, oWidth, oHeight } = attachment;
const origRatio = oWidth / oHeight;
const height = width / origRatio;
if ( SUPPORTED_IMAGE_TYPES.includes( mimeType ) ) {
if ( allowedImageMimeTypes.includes( mimeType ) ) {
return onInsert( 'image', {
src,
width,
Expand All @@ -224,7 +215,7 @@ function MediaLibrary( { onInsert } ) {
origWidth: oWidth,
origHeight: oHeight,
} );
} else if ( SUPPORTED_VIDEO_TYPES.includes( mimeType ) ) {
} else if ( allowedVideoMimeTypes.includes( mimeType ) ) {
return onInsert( 'video', {
src,
width,
Expand Down Expand Up @@ -252,7 +243,7 @@ function MediaLibrary( { onInsert } ) {
const { src, oWidth, oHeight, mimeType } = mediaEl;
const origRatio = oWidth / oHeight;
const height = width / origRatio;
if ( SUPPORTED_IMAGE_TYPES.includes( mimeType ) ) {
if ( allowedImageMimeTypes.includes( mimeType ) ) {
return ( <Image
key={ src }
src={ src }
Expand All @@ -261,7 +252,7 @@ function MediaLibrary( { onInsert } ) {
loading={ 'lazy' }
onClick={ () => insertMediaElement( mediaEl, width ) }
/> );
} else if ( SUPPORTED_VIDEO_TYPES.includes( mimeType ) ) {
} else if ( allowedVideoMimeTypes.includes( mimeType ) ) {
/* eslint-disable react/jsx-closing-tag-location */
return ( <Video
key={ src }
Expand Down
2 changes: 1 addition & 1 deletion includes/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Media {
*
* @var string
*/
const POSTER_POST_META_KEY = 'amp_is_poster';
const POSTER_POST_META_KEY = '_web_stories_is_poster';
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved

/**
* Init.
Expand Down
Loading