From f050d65352cffb62cf1ef2b2824168df43c02a82 Mon Sep 17 00:00:00 2001 From: Siobhan Date: Wed, 19 Apr 2023 10:38:19 +0100 Subject: [PATCH] refactor: Remove native functionality in web file --- .../hooks/use-sync-media/index.ts | 30 ++----------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/projects/packages/videopress/src/client/block-editor/hooks/use-sync-media/index.ts b/projects/packages/videopress/src/client/block-editor/hooks/use-sync-media/index.ts index 8d9822f09a6ce..ebc304b4a9e0b 100644 --- a/projects/packages/videopress/src/client/block-editor/hooks/use-sync-media/index.ts +++ b/projects/packages/videopress/src/client/block-editor/hooks/use-sync-media/index.ts @@ -5,9 +5,8 @@ import { usePrevious } from '@wordpress/compose'; import { store as coreStore } from '@wordpress/core-data'; import { useSelect, useDispatch } from '@wordpress/data'; import { store as editorStore } from '@wordpress/editor'; -import { useEffect, useState, useCallback, Platform } from '@wordpress/element'; +import { useEffect, useState, useCallback } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; -import { subscribePostSaveEvent } from '@wordpress/react-native-bridge'; import debugFactory from 'debug'; /** * Internal dependencies @@ -31,8 +30,6 @@ import { useVideoPosterData } from '../use-video-poster-data'; import type { UseSyncMedia, ArrangeTracksAttributesProps } from './types'; import type { UploadTrackDataProps } from '../../../lib/video-tracks/types'; -const isNative = Platform.isNative; - const debug = debugFactory( 'videopress:video:use-sync-media' ); /* @@ -167,22 +164,6 @@ export function useSyncMedia( const isSaving = useSelect( select => select( editorStore ).isSavingPost(), [] ); const wasSaving = usePrevious( isSaving ); - // In native, it's not currently possible to access a post's saved state from the editor store. - // We therefore need to listen to a native event emitter to know when a post has just been saved. - const [ postHasBeenJustSavedNative, setPostHasBeenJustSavedNative ] = useState( false ); - - useEffect( () => { - if ( ! isNative ) { - return; - } - - const subscription = subscribePostSaveEvent( () => setPostHasBeenJustSavedNative( true ) ); - - return () => { - subscription?.remove(); - }; - }, [] ); - const invalidateResolution = useDispatch( coreStore ).invalidateResolution; const [ initialState, setState ] = useState< VideoDataProps >( {} ); @@ -290,9 +271,7 @@ export function useSyncMedia( const updateMediaHandler = useMediaDataUpdate( id ); - const postHasBeenJustSaved = isNative - ? postHasBeenJustSavedNative - : !! ( wasSaving && ! isSaving ); + const postHasBeenJustSaved = !! ( wasSaving && ! isSaving ); /* * Video frame poster: Block attributes => Frame poster generation @@ -317,8 +296,6 @@ export function useSyncMedia( debug( '%o Post has been just saved. Syncing...', attributes?.guid ); - isNative && setPostHasBeenJustSavedNative( false ); - if ( ! attributes?.id ) { debug( '%o No media ID found. Impossible to sync. Bail early', attributes?.guid ); return; @@ -380,8 +357,7 @@ export function useSyncMedia( isOverwriteChapterAllowed && attributes?.guid && dataToUpdate?.description?.length && - validateChapters( chapters ) && - ! isNative + validateChapters( chapters ) ) { debug( 'Autogenerated chapter detected. Processing...' ); const track: UploadTrackDataProps = {