From c7d00c64a4c74236a4aab528b3987811ab928deb Mon Sep 17 00:00:00 2001 From: etoledom Date: Wed, 20 Nov 2019 09:48:48 +0100 Subject: [PATCH] [RNMobile] Implement getMedia on Image block. (#17979) * Implement getMedia on Image block to get media object * Revert making public default headers. Not needed anymore --- packages/api-fetch/src/index.native.js | 10 ------- .../block-library/src/image/edit.native.js | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 13 deletions(-) delete mode 100644 packages/api-fetch/src/index.native.js diff --git a/packages/api-fetch/src/index.native.js b/packages/api-fetch/src/index.native.js deleted file mode 100644 index 802ac8f7c42aea..00000000000000 --- a/packages/api-fetch/src/index.native.js +++ /dev/null @@ -1,10 +0,0 @@ - -function apiFetch( options ) { - // eslint-disable-next-line no-console - console.warn( 'apiFetch called with options', options ); - - // return a promise that never resolves - return new Promise( () => {} ); -} - -export default apiFetch; diff --git a/packages/block-library/src/image/edit.native.js b/packages/block-library/src/image/edit.native.js index edcfff4ff2a075..bb69712adb5d6e 100644 --- a/packages/block-library/src/image/edit.native.js +++ b/packages/block-library/src/image/edit.native.js @@ -10,7 +10,7 @@ import { requestImageUploadCancelDialog, requestImageFullscreenPreview, } from 'react-native-gutenberg-bridge'; -import { isEmpty, map } from 'lodash'; +import { isEmpty, map, get } from 'lodash'; /** * WordPress dependencies @@ -39,7 +39,8 @@ import { import { __, sprintf } from '@wordpress/i18n'; import { isURL } from '@wordpress/url'; import { doAction, hasAction } from '@wordpress/hooks'; -import { withPreferredColorScheme } from '@wordpress/compose'; +import { compose, withPreferredColorScheme } from '@wordpress/compose'; +import { withSelect } from '@wordpress/data'; /** * Internal dependencies @@ -209,7 +210,17 @@ export class ImageEdit extends React.Component { } onSetSizeSlug( sizeSlug ) { + const { image } = this.props; + + const url = get( image, [ 'media_details', 'sizes', sizeSlug, 'source_url' ] ); + if ( ! url ) { + return null; + } + this.props.setAttributes( { + url, + width: undefined, + height: undefined, sizeSlug, } ); } @@ -430,4 +441,14 @@ export class ImageEdit extends React.Component { } } -export default withPreferredColorScheme( ImageEdit ); +export default compose( [ + withSelect( ( select, props ) => { + const { getMedia } = select( 'core' ); + const { attributes: { id }, isSelected } = props; + + return { + image: id && isSelected ? getMedia( id ) : null, + }; + } ), + withPreferredColorScheme, +] )( ImageEdit );