Skip to content

Commit

Permalink
Fetch token upon block mount
Browse files Browse the repository at this point in the history
  • Loading branch information
fluiddot committed Mar 28, 2023
1 parent d216490 commit 716807f
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { createBlock } from '@wordpress/blocks';
import { PanelBody } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { useState, useCallback } from '@wordpress/element';
import { useEffect, useState, useCallback, Platform } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';
/**
Expand All @@ -20,6 +20,7 @@ import { View } from 'react-native';
/**
* Internal dependencies
*/
import getMediaToken from '../../../lib/get-media-token/index.native';
import { buildVideoPressURL, getVideoPressUrl } from '../../../lib/url';
import { usePreview } from '../../hooks/use-preview';
import ColorPanel from './components/color-panel';
Expand Down Expand Up @@ -73,6 +74,16 @@ export default function VideoPressEdit( {
isReplacing: false,
prevAttrs: {},
} );
const [ , setToken ] = useState< string >();

// Fetch token upon block mount
useEffect( () => {
if ( Platform.isAndroid && guid ) {
getMediaToken( 'playback', { guid } ).then( tokenData => {
setToken( tokenData.token );
} );
}
}, [] );

const wasBlockJustInserted = useSelect(
select => select( blockEditorStore ).wasBlockJustInserted( clientId, 'inserter_menu' ),
Expand Down

0 comments on commit 716807f

Please sign in to comment.