Skip to content

Commit

Permalink
refactor: Remove native functionality in web file
Browse files Browse the repository at this point in the history
  • Loading branch information
Siobhan committed Apr 19, 2023
1 parent 7ec2f68 commit f050d65
Showing 1 changed file with 3 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' );

/*
Expand Down Expand Up @@ -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 >( {} );
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit f050d65

Please sign in to comment.