From 12483fad3c7602600bbd431ed4cb79a0d3c13943 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Mon, 21 Sep 2020 17:15:34 -0300 Subject: [PATCH 01/15] added mobile StoryUpdateProgress component and bridge code to send/receive save progress --- .../src/components/index.native.js | 1 + .../story-update-progress/README.md | 105 +++++++ .../story-update-progress/index.native.js | 263 ++++++++++++++++++ .../story-update-progress/styles.native.scss | 9 + .../GutenbergBridgeJS2Parent.java | 11 +- .../RNReactNativeGutenbergBridgeModule.java | 5 + .../WPAndroidGlue/DeferredEventEmitter.java | 29 +- .../WPAndroidGlue/WPAndroidGlueCode.java | 29 ++ packages/react-native-bridge/index.js | 13 +- test/native/setup.js | 1 + 10 files changed, 460 insertions(+), 6 deletions(-) create mode 100644 packages/block-editor/src/components/story-update-progress/README.md create mode 100644 packages/block-editor/src/components/story-update-progress/index.native.js create mode 100644 packages/block-editor/src/components/story-update-progress/styles.native.scss diff --git a/packages/block-editor/src/components/index.native.js b/packages/block-editor/src/components/index.native.js index 8f8eab7b29a77f..c3b153921e4157 100644 --- a/packages/block-editor/src/components/index.native.js +++ b/packages/block-editor/src/components/index.native.js @@ -28,6 +28,7 @@ export { MEDIA_TYPE_VIDEO, } from './media-upload'; export { default as MediaUploadProgress } from './media-upload-progress'; +export { default as StoryUpdateProgress } from './story-update-progress'; export { default as URLInput } from './url-input'; export { default as BlockInvalidWarning } from './block-list/block-invalid-warning'; export { default as BlockCaption } from './block-caption'; diff --git a/packages/block-editor/src/components/story-update-progress/README.md b/packages/block-editor/src/components/story-update-progress/README.md new file mode 100644 index 00000000000000..9447ac4d065c68 --- /dev/null +++ b/packages/block-editor/src/components/story-update-progress/README.md @@ -0,0 +1,105 @@ +MediaUploadProgress +=================== + +`MediaUploadProgress` shows a progress bar while a media file associated with a block is being uploaded. + +## Usage + +Usage example + +```jsx +import { ImageBackground, Text, View } from 'react-native'; +import { + MediaUploadProgress, +} from '@wordpress/block-editor'; + +function MediaProgress( { url, id } ) { + return ( + { + return ( + + { isUploadFailed && + + { retryMessage } + + } + + ); + } } + /> + ); +} +``` + +## Props + +### mediaId + +A media ID that identifies the current upload. + +- Type: `Number` +- Required: Yes +- Platform: Mobile + +### renderContent + +Content to be rendered along with the progress bar, usually the thumbnail of the media being uploaded. + +- Type: `React components` +- Required: Yes +- Platform: Mobile + +It passes an object containing the following properties: + +`{ isUploadInProgress, isUploadFailed, retryMessage }` + +### onUpdateMediaProgress + +Callback called when the progress of the upload is updated. + +- Type: `Function` +- Required: No +- Platform: Mobile + +The argument of the callback is an object containing the following properties: + +`{ mediaId, mediaUrl, progress, state }` + +### onFinishMediaUploadWithSuccess + +Callback called when the media file has been uploaded successfully. + +- Type: `Function` +- Required: No +- Platform: Mobile + +The argument of the callback is an object containing the following properties: + +`{ mediaId, mediaServerId, mediaUrl, progress, state }` + +### onFinishMediaUploadWithFailure + +Callback called when the media file couldn't be uploaded. + +- Type: `Function` +- Required: No +- Platform: Mobile + +The argument of the callback is an object containing the following properties: + +`{ mediaId, progress, state }` + + +### onMediaUploadStateReset + +Callback called when the media upload is reset + +- Type: `Function` +- Required: No +- Platform: Mobile + diff --git a/packages/block-editor/src/components/story-update-progress/index.native.js b/packages/block-editor/src/components/story-update-progress/index.native.js new file mode 100644 index 00000000000000..40df909434f65c --- /dev/null +++ b/packages/block-editor/src/components/story-update-progress/index.native.js @@ -0,0 +1,263 @@ +/** + * External dependencies + */ +import React from 'react'; +import { View } from 'react-native'; + +/** + * WordPress dependencies + */ +import { Spinner } from '@wordpress/components'; +import { __ } from '@wordpress/i18n'; +import { + subscribeMediaUpload, + subscribeMediaSave, +} from '@wordpress/react-native-bridge'; + +/** + * Internal dependencies + */ +import styles from './styles.scss'; + +export const STORY_SAVE_STATE_SAVING = 1; +export const STORY_SAVE_STATE_SUCCEEDED = 2; +export const STORY_SAVE_STATE_FAILED = 3; +export const STORY_SAVE_STATE_RESET = 4; + +export const STORY_UPLOAD_STATE_UPLOADING = 5; +export const STORY_UPLOAD_STATE_SUCCEEDED = 6; +export const STORY_UPLOAD_STATE_FAILED = 7; +export const STORY_UPLOAD_STATE_RESET = 8; + +export class StoryUpdateProgress extends React.Component { + constructor( props ) { + super( props ); + + this.state = { + progress: 0, + isSaveInProgress: false, + isSaveFailed: false, + isUploadInProgress: false, + isUploadFailed: false, + }; + + this.mediaUpload = this.mediaUpload.bind( this ); + this.mediaSave = this.mediaSave.bind( this ); + } + + componentDidMount() { + this.addMediaUploadListener(); + this.addMediaSaveListener(); + } + + componentWillUnmount() { + this.removeMediaUploadListener(); + this.removeMediaSaveListener(); + } + + mediaIdContainedInMediaFiles( mediaId, mediaFiles ) { + // TODO check here + if ( mediaId !== undefined && mediaFiles !== undefined ) { + return true; + } + return false; + } + + mediaUpload( payload ) { + const { mediaFiles } = this.props; + + if ( + this.mediaIdContainedInMediaFiles( payload.mediaId, mediaFiles ) === + false + ) { + return; + } + // if ( payload.mediaId !== mediaId ) { + // return; + // } + + switch ( payload.state ) { + case STORY_UPLOAD_STATE_UPLOADING: + this.updateMediaProgress( payload ); + break; + case STORY_UPLOAD_STATE_SUCCEEDED: + this.finishMediaUploadWithSuccess( payload ); + break; + case STORY_UPLOAD_STATE_FAILED: + this.finishMediaUploadWithFailure( payload ); + break; + case STORY_UPLOAD_STATE_RESET: + this.mediaUploadStateReset( payload ); + break; + } + } + + mediaSave( payload ) { + const { mediaFiles } = this.props; + + if ( + this.mediaIdContainedInMediaFiles( payload.mediaId, mediaFiles ) === + false + ) { + return; + } + // if ( payload.mediaId !== mediaId ) { + // return; + // } + + switch ( payload.state ) { + case STORY_SAVE_STATE_SAVING: + this.updateMediaSaveProgress( payload ); + break; + case STORY_SAVE_STATE_SUCCEEDED: + this.finishMediaSaveWithSuccess( payload ); + break; + case STORY_SAVE_STATE_FAILED: + this.finishMediaSaveWithFailure( payload ); + break; + case STORY_SAVE_STATE_RESET: + this.mediaUploadStateReset( payload ); + break; + } + } + + // ---- Story (media) save actions + updateMediaSaveProgress( payload ) { + this.setState( { + progress: payload.progress, + isUploadInProgress: false, + isUploadFailed: false, + isSaveInProgress: true, + isSaveFailed: false, + } ); + if ( this.props.onUpdateMediaSaveProgress ) { + this.props.onUpdateMediaSaveProgress( payload ); + } + } + + finishMediaSaveWithSuccess( payload ) { + this.setState( { isSaveInProgress: false } ); + if ( this.props.onFinishMediaSaveWithSuccess ) { + this.props.onFinishMediaSaveWithSuccess( payload ); + } + } + + finishMediaSaveWithFailure( payload ) { + this.setState( { isSaveInProgress: false, isSaveFailed: true } ); + if ( this.props.onFinishMediaUploadWithFailure ) { + this.props.onFinishMediaUploadWithFailure( payload ); + } + } + + mediaSaveStateReset( payload ) { + this.setState( { isUploadInProgress: false, isUploadFailed: false } ); + if ( this.props.onMediaSaveStateReset ) { + this.props.onMediaSaveStateReset( payload ); + } + } + + // ---- Story upload actions + updateMediaProgress( payload ) { + this.setState( { + progress: payload.progress, + isUploadInProgress: true, + isUploadFailed: false, + isSaveInProgress: false, + isSaveFailed: false, + } ); + if ( this.props.onUpdateMediaProgress ) { + this.props.onUpdateMediaProgress( payload ); + } + } + + finishMediaUploadWithSuccess( payload ) { + this.setState( { isUploadInProgress: false, isSaveInProgress: false } ); + if ( this.props.onFinishMediaUploadWithSuccess ) { + this.props.onFinishMediaUploadWithSuccess( payload ); + } + } + + finishMediaUploadWithFailure( payload ) { + this.setState( { isUploadInProgress: false, isUploadFailed: true } ); + if ( this.props.onFinishMediaUploadWithFailure ) { + this.props.onFinishMediaUploadWithFailure( payload ); + } + } + + mediaUploadStateReset( payload ) { + this.setState( { isUploadInProgress: false, isUploadFailed: false } ); + if ( this.props.onMediaUploadStateReset ) { + this.props.onMediaUploadStateReset( payload ); + } + } + + addMediaUploadListener() { + //if we already have a subscription not worth doing it again + if ( this.subscriptionParentMediaUpload ) { + return; + } + this.subscriptionParentMediaUpload = subscribeMediaUpload( + ( payload ) => { + this.mediaUpload( payload ); + } + ); + } + + removeMediaUploadListener() { + if ( this.subscriptionParentMediaUpload ) { + this.subscriptionParentMediaUpload.remove(); + } + } + + addMediaSaveListener() { + //if we already have a subscription not worth doing it again + if ( this.subscriptionParentMediaSave ) { + return; + } + this.subscriptionParentMediaSave = subscribeMediaSave( ( payload ) => { + this.mediaSave( payload ); + } ); + } + + removeMediaSaveListener() { + if ( this.subscriptionParentMediaSave ) { + this.subscriptionParentMediaSave.remove(); + } + } + + render() { + const { renderContent = () => null } = this.props; + const { + isUploadInProgress, + isUploadFailed, + isSaveInProgress, + isSaveFailed, + } = this.state; + const showSpinner = + this.state.isUploadInProgress || this.state.isSaveInProgress; + const progress = this.state.progress * 100; + // eslint-disable-next-line @wordpress/i18n-no-collapsible-whitespace + const retryMessage = __( + 'Failed to insert media.\nPlease tap for options.' + ); + + return ( + + { showSpinner && ( + + + + ) } + { renderContent( { + isUploadInProgress, + isUploadFailed, + isSaveInProgress, + isSaveFailed, + retryMessage, + } ) } + + ); + } +} + +export default StoryUpdateProgress; diff --git a/packages/block-editor/src/components/story-update-progress/styles.native.scss b/packages/block-editor/src/components/story-update-progress/styles.native.scss new file mode 100644 index 00000000000000..2178be1968b1c5 --- /dev/null +++ b/packages/block-editor/src/components/story-update-progress/styles.native.scss @@ -0,0 +1,9 @@ +.mediaUploadProgress { + flex: 1; + z-index: 1; +} + +.progressBar { + background-color: $gray-lighten-30; + z-index: 1; +} diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java index 8652806dd3ea8e..5b95b1a70574c9 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java @@ -34,6 +34,13 @@ interface MediaUploadEventEmitter { void onMediaFileUploadFailed(int mediaId); } + interface StorySaveEventEmitter { + void onSaveMediaFileClear(int mediaId); + void onMediaFileSaveProgress(int mediaId, float progress); + void onMediaFileSaveSucceeded(int mediaId, String mediaUrl, int serverId); + void onMediaFileSaveFailed(int mediaId); + } + interface ReplaceUnsupportedBlockCallback { void replaceUnsupportedBlock(String content, String blockId); } @@ -126,6 +133,8 @@ public static GutenbergUserEvent getEnum(String eventName) { void mediaUploadSync(MediaSelectedCallback mediaSelectedCallback); + void storySaveSync(MediaSelectedCallback mediaSelectedCallback); + void requestImageFailedRetryDialog(int mediaId); void requestImageUploadCancelDialog(int mediaId); @@ -158,7 +167,7 @@ void gutenbergDidRequestUnsupportedBlockFallback(ReplaceUnsupportedBlockCallback void requestStarterPageTemplatesTooltipShown(StarterPageTemplatesTooltipShownCallback starterPageTemplatesTooltipShownCallback); - void requestStoryCreatorLoad(ReplaceStoryEditedBlockCallback replaceUnsupportedBlockCallback, + void requestStoryCreatorLoad(ReplaceStoryEditedBlockCallback replaceStoryEditedBlockCallback, ReadableArray mediaFiles, String blockId ); diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java index 7b96ecfb603c7f..927212d4df8e48 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java @@ -195,6 +195,11 @@ public void mediaUploadSync() { mGutenbergBridgeJS2Parent.mediaUploadSync(getNewMediaSelectedCallback(false,null)); } + @ReactMethod + public void storySaveSync() { + mGutenbergBridgeJS2Parent.storySaveSync(getNewMediaSelectedCallback(true,null)); + } + @ReactMethod public void requestImageFailedRetryDialog(final int mediaId) { mGutenbergBridgeJS2Parent.requestImageFailedRetryDialog(mediaId); diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java index e67e76a67b098b..31fb629f7d19a1 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java @@ -9,6 +9,7 @@ import com.facebook.react.bridge.WritableNativeMap; import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.MediaUploadEventEmitter; +import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.StorySaveEventEmitter; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; @@ -16,7 +17,7 @@ import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID; import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_URL; -public class DeferredEventEmitter implements MediaUploadEventEmitter { +public class DeferredEventEmitter implements MediaUploadEventEmitter, StorySaveEventEmitter { public interface JSEventEmitter { void emitToJS(String eventName, @Nullable WritableMap data); } @@ -26,6 +27,11 @@ public interface JSEventEmitter { private static final int MEDIA_UPLOAD_STATE_FAILED = 3; private static final int MEDIA_UPLOAD_STATE_RESET = 4; + private static final int STORY_SAVE_STATE_SAVING = 5; + private static final int STORY_SAVE_STATE_SUCCEEDED = 6; + private static final int STORY_SAVE_STATE_FAILED = 7; + private static final int STORY_SAVE_STATE_RESET = 8; + private static final String EVENT_NAME_MEDIA_UPLOAD = "mediaUpload"; private static final String MAP_KEY_MEDIA_FILE_UPLOAD_STATE = "state"; @@ -124,6 +130,27 @@ public void onMediaFileUploadFailed(int mediaId) { setMediaFileUploadDataInJS(MEDIA_UPLOAD_STATE_FAILED, mediaId, null, 0); } + // Story save events emitter + @Override + public void onSaveMediaFileClear(int mediaId) { + setMediaFileUploadDataInJS(STORY_SAVE_STATE_RESET, mediaId, null, 0); + } + + @Override + public void onMediaFileSaveProgress(int mediaId, float progress) { + setMediaFileUploadDataInJS(STORY_SAVE_STATE_SAVING, mediaId, null, progress); + } + + @Override + public void onMediaFileSaveSucceeded(int mediaId, String mediaUrl, int mediaServerId) { + setMediaFileUploadDataInJS(STORY_SAVE_STATE_SUCCEEDED, mediaId, mediaUrl, 1, mediaServerId); + } + + @Override + public void onMediaFileSaveFailed(int mediaId) { + setMediaFileUploadDataInJS(STORY_SAVE_STATE_FAILED, mediaId, null, 0); + } + public void updateCapabilities(GutenbergProps gutenbergProps) { queueActionToJS(MAP_KEY_UPDATE_CAPABILITIES, Arguments.makeNativeMap(gutenbergProps.getUpdatedCapabilitiesProps())); } diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java index 825e2cfbbb0944..2b69c8c0d509cc 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java @@ -84,6 +84,7 @@ public class WPAndroidGlueCode { private OnMediaLibraryButtonListener mOnMediaLibraryButtonListener; private OnReattachQueryListener mOnReattachQueryListener; + private OnStorySavingReattachQueryListener mOnStorySavingReattachQueryListener; private OnEditorMountListener mOnEditorMountListener; private OnEditorAutosaveListener mOnEditorAutosaveListener; private OnImageFullscreenPreviewListener mOnImageFullscreenPreviewListener; @@ -160,6 +161,10 @@ public interface OnReattachQueryListener { void onQueryCurrentProgressForUploadingMedia(); } + public interface OnStorySavingReattachQueryListener { + void onQueryCurrentProgressForStoryMediaSaving(); + } + public interface OnEditorMountListener { void onEditorDidMount(ArrayList unsupportedBlockNames); } @@ -271,6 +276,12 @@ public void mediaUploadSync(MediaSelectedCallback mediaSelectedCallback) { mOnReattachQueryListener.onQueryCurrentProgressForUploadingMedia(); } + @Override + public void storySaveSync(MediaSelectedCallback mediaSelectedCallback) { + mMediaSelectedCallback = mediaSelectedCallback; + mOnStorySavingReattachQueryListener.onQueryCurrentProgressForStoryMediaSaving(); + } + @Override public void requestImageFailedRetryDialog(int mediaId) { mOnMediaLibraryButtonListener.onRetryUploadForMediaClicked(mediaId); @@ -469,6 +480,7 @@ public void onCreateView(Context initContext, public void attachToContainer(ViewGroup viewGroup, OnMediaLibraryButtonListener onMediaLibraryButtonListener, OnReattachQueryListener onReattachQueryListener, + OnStorySavingReattachQueryListener onStorySavingReattachQueryListener, OnEditorMountListener onEditorMountListener, OnEditorAutosaveListener onEditorAutosaveListener, OnAuthHeaderRequestedListener onAuthHeaderRequestedListener, @@ -486,6 +498,7 @@ public void attachToContainer(ViewGroup viewGroup, mOnMediaLibraryButtonListener = onMediaLibraryButtonListener; mOnReattachQueryListener = onReattachQueryListener; + mOnStorySavingReattachQueryListener = onStorySavingReattachQueryListener; mOnEditorMountListener = onEditorMountListener; mOnEditorAutosaveListener = onEditorAutosaveListener; mRequestExecutor = fetchExecutor; @@ -855,6 +868,22 @@ public void clearMediaFileURL(final int mediaId) { mDeferredEventEmitter.onUploadMediaFileClear(mediaId); } + public void clearFileSaveStatus(final int mediaId) { + mDeferredEventEmitter.onSaveMediaFileClear(mediaId); + } + + public void mediaFileSaveProgress(final int mediaId, final float progress) { + mDeferredEventEmitter.onMediaFileSaveProgress(mediaId, progress); + } + + public void mediaFileSaveFailed(final int mediaId) { + mDeferredEventEmitter.onMediaFileSaveFailed(mediaId); + } + + public void mediaFileSaveSucceeded(final int mediaId, final String mediaUrl, final int serverMediaId) { + mDeferredEventEmitter.onMediaFileSaveSucceeded(mediaId, mediaUrl, serverMediaId); + } + public void replaceUnsupportedBlock(String content, String blockId) { if (mReplaceUnsupportedBlockCallback != null) { mReplaceUnsupportedBlockCallback.replaceUnsupportedBlock(content, blockId); diff --git a/packages/react-native-bridge/index.js b/packages/react-native-bridge/index.js index e8acb2ee616aab..822f66594957aa 100644 --- a/packages/react-native-bridge/index.js +++ b/packages/react-native-bridge/index.js @@ -67,6 +67,10 @@ export function subscribeMediaUpload( callback ) { return gutenbergBridgeEvents.addListener( 'mediaUpload', callback ); } +export function subscribeMediaSave( callback ) { + return gutenbergBridgeEvents.addListener( 'mediaSave', callback ); +} + export function subscribeMediaAppend( callback ) { return gutenbergBridgeEvents.addListener( 'mediaAppend', callback ); } @@ -158,6 +162,10 @@ export function mediaUploadSync() { return RNReactNativeGutenbergBridge.mediaUploadSync(); } +export function storySaveSync() { + return RNReactNativeGutenbergBridge.storySaveSync(); +} + export function requestImageFailedRetryDialog( mediaId ) { return RNReactNativeGutenbergBridge.requestImageFailedRetryDialog( mediaId @@ -227,10 +235,7 @@ export function setStarterPageTemplatesTooltipShown( tooltipShown ) { ); } -export function requestStoryCreatorLoad( - mediaFiles, - blockClientId -) { +export function requestStoryCreatorLoad( mediaFiles, blockClientId ) { return RNReactNativeGutenbergBridge.requestStoryCreatorLoad( mediaFiles, blockClientId diff --git a/test/native/setup.js b/test/native/setup.js index 0f8e157825233b..9e589e0d4e5759 100644 --- a/test/native/setup.js +++ b/test/native/setup.js @@ -29,6 +29,7 @@ jest.mock( '@wordpress/react-native-bridge', () => { editorDidMount: jest.fn(), editorDidAutosave: jest.fn(), subscribeMediaUpload: jest.fn(), + subscribeMediaSave: jest.fn(), getOtherMediaOptions: jest.fn(), requestMediaPicker: jest.fn(), requestUnsupportedBlockFallback: jest.fn(), From 2c170553742578c8ab8f3d94a4a1748bf60ae0af Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Wed, 23 Sep 2020 21:44:01 -0300 Subject: [PATCH 02/15] updated WPAndroid bridge DeferredEventEmitter to handle Story save events separately --- .../WPAndroidGlue/DeferredEventEmitter.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java index 31fb629f7d19a1..7b1bd2c54e95ec 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java @@ -33,6 +33,7 @@ public interface JSEventEmitter { private static final int STORY_SAVE_STATE_RESET = 8; private static final String EVENT_NAME_MEDIA_UPLOAD = "mediaUpload"; + private static final String EVENT_NAME_MEDIA_SAVE = "mediaSave"; private static final String MAP_KEY_MEDIA_FILE_UPLOAD_STATE = "state"; private static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_PROGRESS = "progress"; @@ -106,8 +107,29 @@ private void setMediaFileUploadDataInJS(int state, int mediaId, String mediaUrl, } } + private void setStorySaveDataInJS(int state, int mediaId, String mediaUrl, float progress) { + setStorySaveDataInJS(state, mediaId, mediaUrl, progress, MEDIA_SERVER_ID_UNKNOWN); + } + + private void setStorySaveDataInJS(int state, int mediaId, String mediaUrl, float progress, int mediaServerId) { + WritableMap writableMap = new WritableNativeMap(); + writableMap.putInt(MAP_KEY_MEDIA_FILE_UPLOAD_STATE, state); + writableMap.putInt(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID, mediaId); + writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_URL, mediaUrl); + writableMap.putDouble(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_PROGRESS, progress); + if (mediaServerId != MEDIA_SERVER_ID_UNKNOWN) { + writableMap.putInt(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_SERVER_ID, mediaServerId); + } + if (isCriticalMessage(state)) { + queueActionToJS(EVENT_NAME_MEDIA_SAVE, writableMap); + } else { + emitOrDrop(EVENT_NAME_MEDIA_SAVE, writableMap); + } + } + private boolean isCriticalMessage(int state) { - return state == MEDIA_UPLOAD_STATE_SUCCEEDED || state == MEDIA_UPLOAD_STATE_FAILED; + return state == MEDIA_UPLOAD_STATE_SUCCEEDED || state == MEDIA_UPLOAD_STATE_FAILED + || state == STORY_SAVE_STATE_SUCCEEDED || state == STORY_SAVE_STATE_FAILED; } @Override @@ -133,22 +155,22 @@ public void onMediaFileUploadFailed(int mediaId) { // Story save events emitter @Override public void onSaveMediaFileClear(int mediaId) { - setMediaFileUploadDataInJS(STORY_SAVE_STATE_RESET, mediaId, null, 0); + setStorySaveDataInJS(STORY_SAVE_STATE_RESET, mediaId, null, 0); } @Override public void onMediaFileSaveProgress(int mediaId, float progress) { - setMediaFileUploadDataInJS(STORY_SAVE_STATE_SAVING, mediaId, null, progress); + setStorySaveDataInJS(STORY_SAVE_STATE_SAVING, mediaId, null, progress); } @Override public void onMediaFileSaveSucceeded(int mediaId, String mediaUrl, int mediaServerId) { - setMediaFileUploadDataInJS(STORY_SAVE_STATE_SUCCEEDED, mediaId, mediaUrl, 1, mediaServerId); + setStorySaveDataInJS(STORY_SAVE_STATE_SUCCEEDED, mediaId, mediaUrl, 1, mediaServerId); } @Override public void onMediaFileSaveFailed(int mediaId) { - setMediaFileUploadDataInJS(STORY_SAVE_STATE_FAILED, mediaId, null, 0); + setStorySaveDataInJS(STORY_SAVE_STATE_FAILED, mediaId, null, 0); } public void updateCapabilities(GutenbergProps gutenbergProps) { From 78455a8ef8ad3a33da1137fedfc1474e546b40db Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Thu, 24 Sep 2020 08:10:15 -0300 Subject: [PATCH 03/15] changed all Save event interface methods to use String ids instead of int, and removed serverMediaId params as these don't apply while saving locally --- .../GutenbergBridgeJS2Parent.java | 10 ++++----- .../WPAndroidGlue/DeferredEventEmitter.java | 21 +++++++------------ .../WPAndroidGlue/WPAndroidGlueCode.java | 10 ++++----- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java index 5b95b1a70574c9..cd88b7d8358688 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java @@ -35,10 +35,10 @@ interface MediaUploadEventEmitter { } interface StorySaveEventEmitter { - void onSaveMediaFileClear(int mediaId); - void onMediaFileSaveProgress(int mediaId, float progress); - void onMediaFileSaveSucceeded(int mediaId, String mediaUrl, int serverId); - void onMediaFileSaveFailed(int mediaId); + void onSaveMediaFileClear(String mediaId); + void onMediaFileSaveProgress(String mediaId, float progress); + void onMediaFileSaveSucceeded(String mediaId, String mediaUrl); + void onMediaFileSaveFailed(String mediaId); } interface ReplaceUnsupportedBlockCallback { @@ -162,7 +162,7 @@ void gutenbergDidRequestUnsupportedBlockFallback(ReplaceUnsupportedBlockCallback String blockTitle); void onAddMention(Consumer onSuccess); - + void setStarterPageTemplatesTooltipShown(boolean tooltipShown); void requestStarterPageTemplatesTooltipShown(StarterPageTemplatesTooltipShownCallback starterPageTemplatesTooltipShownCallback); diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java index 7b1bd2c54e95ec..9f3dada6a044be 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java @@ -107,19 +107,12 @@ private void setMediaFileUploadDataInJS(int state, int mediaId, String mediaUrl, } } - private void setStorySaveDataInJS(int state, int mediaId, String mediaUrl, float progress) { - setStorySaveDataInJS(state, mediaId, mediaUrl, progress, MEDIA_SERVER_ID_UNKNOWN); - } - - private void setStorySaveDataInJS(int state, int mediaId, String mediaUrl, float progress, int mediaServerId) { + private void setStorySaveDataInJS(int state, String mediaId, String mediaUrl, float progress) { WritableMap writableMap = new WritableNativeMap(); writableMap.putInt(MAP_KEY_MEDIA_FILE_UPLOAD_STATE, state); - writableMap.putInt(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID, mediaId); + writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID, mediaId); writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_URL, mediaUrl); writableMap.putDouble(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_PROGRESS, progress); - if (mediaServerId != MEDIA_SERVER_ID_UNKNOWN) { - writableMap.putInt(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_SERVER_ID, mediaServerId); - } if (isCriticalMessage(state)) { queueActionToJS(EVENT_NAME_MEDIA_SAVE, writableMap); } else { @@ -154,22 +147,22 @@ public void onMediaFileUploadFailed(int mediaId) { // Story save events emitter @Override - public void onSaveMediaFileClear(int mediaId) { + public void onSaveMediaFileClear(String mediaId) { setStorySaveDataInJS(STORY_SAVE_STATE_RESET, mediaId, null, 0); } @Override - public void onMediaFileSaveProgress(int mediaId, float progress) { + public void onMediaFileSaveProgress(String mediaId, float progress) { setStorySaveDataInJS(STORY_SAVE_STATE_SAVING, mediaId, null, progress); } @Override - public void onMediaFileSaveSucceeded(int mediaId, String mediaUrl, int mediaServerId) { - setStorySaveDataInJS(STORY_SAVE_STATE_SUCCEEDED, mediaId, mediaUrl, 1, mediaServerId); + public void onMediaFileSaveSucceeded(String mediaId, String mediaUrl) { + setStorySaveDataInJS(STORY_SAVE_STATE_SUCCEEDED, mediaId, mediaUrl, 1); } @Override - public void onMediaFileSaveFailed(int mediaId) { + public void onMediaFileSaveFailed(String mediaId) { setStorySaveDataInJS(STORY_SAVE_STATE_FAILED, mediaId, null, 0); } diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java index 2b69c8c0d509cc..796d15d7bcca6a 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java @@ -868,20 +868,20 @@ public void clearMediaFileURL(final int mediaId) { mDeferredEventEmitter.onUploadMediaFileClear(mediaId); } - public void clearFileSaveStatus(final int mediaId) { + public void clearFileSaveStatus(final String mediaId) { mDeferredEventEmitter.onSaveMediaFileClear(mediaId); } - public void mediaFileSaveProgress(final int mediaId, final float progress) { + public void mediaFileSaveProgress(final String mediaId, final float progress) { mDeferredEventEmitter.onMediaFileSaveProgress(mediaId, progress); } - public void mediaFileSaveFailed(final int mediaId) { + public void mediaFileSaveFailed(final String mediaId) { mDeferredEventEmitter.onMediaFileSaveFailed(mediaId); } - public void mediaFileSaveSucceeded(final int mediaId, final String mediaUrl, final int serverMediaId) { - mDeferredEventEmitter.onMediaFileSaveSucceeded(mediaId, mediaUrl, serverMediaId); + public void mediaFileSaveSucceeded(final String mediaId, final String mediaUrl) { + mDeferredEventEmitter.onMediaFileSaveSucceeded(mediaId, mediaUrl); } public void replaceUnsupportedBlock(String content, String blockId) { From da1a900b9923a114ce332b8e6d775ff163c715ed Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Fri, 25 Sep 2020 10:41:18 -0300 Subject: [PATCH 04/15] redefined upload/save state constants --- .../story-update-progress/README.md | 8 +++---- .../story-update-progress/index.native.js | 24 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/block-editor/src/components/story-update-progress/README.md b/packages/block-editor/src/components/story-update-progress/README.md index 9447ac4d065c68..c24a95a78b72ac 100644 --- a/packages/block-editor/src/components/story-update-progress/README.md +++ b/packages/block-editor/src/components/story-update-progress/README.md @@ -1,7 +1,7 @@ -MediaUploadProgress +StoryUpdateProgress =================== -`MediaUploadProgress` shows a progress bar while a media file associated with a block is being uploaded. +`StoryUpdateProgress` shows a progress bar while the media files associated with a Story block are being saved ## Usage @@ -10,12 +10,12 @@ Usage example ```jsx import { ImageBackground, Text, View } from 'react-native'; import { - MediaUploadProgress, + StoryUpdateProgress, } from '@wordpress/block-editor'; function MediaProgress( { url, id } ) { return ( - { return ( diff --git a/packages/block-editor/src/components/story-update-progress/index.native.js b/packages/block-editor/src/components/story-update-progress/index.native.js index 40df909434f65c..0edd278bc10b70 100644 --- a/packages/block-editor/src/components/story-update-progress/index.native.js +++ b/packages/block-editor/src/components/story-update-progress/index.native.js @@ -19,15 +19,15 @@ import { */ import styles from './styles.scss'; -export const STORY_SAVE_STATE_SAVING = 1; -export const STORY_SAVE_STATE_SUCCEEDED = 2; -export const STORY_SAVE_STATE_FAILED = 3; -export const STORY_SAVE_STATE_RESET = 4; +export const STORY_UPLOAD_STATE_UPLOADING = 1; +export const STORY_UPLOAD_STATE_SUCCEEDED = 2; +export const STORY_UPLOAD_STATE_FAILED = 3; +export const STORY_UPLOAD_STATE_RESET = 4; -export const STORY_UPLOAD_STATE_UPLOADING = 5; -export const STORY_UPLOAD_STATE_SUCCEEDED = 6; -export const STORY_UPLOAD_STATE_FAILED = 7; -export const STORY_UPLOAD_STATE_RESET = 8; +export const STORY_SAVE_STATE_SAVING = 5; +export const STORY_SAVE_STATE_SUCCEEDED = 6; +export const STORY_SAVE_STATE_FAILED = 7; +export const STORY_SAVE_STATE_RESET = 8; export class StoryUpdateProgress extends React.Component { constructor( props ) { @@ -78,7 +78,7 @@ export class StoryUpdateProgress extends React.Component { switch ( payload.state ) { case STORY_UPLOAD_STATE_UPLOADING: - this.updateMediaProgress( payload ); + this.updateMediaUploadProgress( payload ); break; case STORY_UPLOAD_STATE_SUCCEEDED: this.finishMediaUploadWithSuccess( payload ); @@ -157,7 +157,7 @@ export class StoryUpdateProgress extends React.Component { } // ---- Story upload actions - updateMediaProgress( payload ) { + updateMediaUploadProgress( payload ) { this.setState( { progress: payload.progress, isUploadInProgress: true, @@ -165,8 +165,8 @@ export class StoryUpdateProgress extends React.Component { isSaveInProgress: false, isSaveFailed: false, } ); - if ( this.props.onUpdateMediaProgress ) { - this.props.onUpdateMediaProgress( payload ); + if ( this.props.onUpdateMediaUploadProgress ) { + this.props.onUpdateMediaUploadProgress( payload ); } } From 9613c56002d0d5ff1d38fbc48f4315ce2cd67d10 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Fri, 25 Sep 2020 17:12:41 -0300 Subject: [PATCH 05/15] added onStorySaveResult handling to bridge, and renamed STORY_SAVE_STATE_* events to MEDIA_SAVE_STATE_* where appropriate --- .../story-update-progress/index.native.js | 37 +++++++++++++----- .../GutenbergBridgeJS2Parent.java | 1 + .../RNReactNativeGutenbergBridgeModule.java | 1 + .../WPAndroidGlue/DeferredEventEmitter.java | 38 ++++++++++++++----- .../WPAndroidGlue/WPAndroidGlueCode.java | 4 ++ 5 files changed, 62 insertions(+), 19 deletions(-) diff --git a/packages/block-editor/src/components/story-update-progress/index.native.js b/packages/block-editor/src/components/story-update-progress/index.native.js index 0edd278bc10b70..e437ca5afd22b5 100644 --- a/packages/block-editor/src/components/story-update-progress/index.native.js +++ b/packages/block-editor/src/components/story-update-progress/index.native.js @@ -24,10 +24,11 @@ export const STORY_UPLOAD_STATE_SUCCEEDED = 2; export const STORY_UPLOAD_STATE_FAILED = 3; export const STORY_UPLOAD_STATE_RESET = 4; -export const STORY_SAVE_STATE_SAVING = 5; -export const STORY_SAVE_STATE_SUCCEEDED = 6; -export const STORY_SAVE_STATE_FAILED = 7; -export const STORY_SAVE_STATE_RESET = 8; +export const MEDIA_SAVE_STATE_SAVING = 5; +export const MEDIA_SAVE_STATE_SUCCEEDED = 6; +export const MEDIA_SAVE_STATE_FAILED = 7; +export const MEDIA_SAVE_STATE_RESET = 8; +export const STORY_SAVE_STATE_RESULT = 9; export class StoryUpdateProgress extends React.Component { constructor( props ) { @@ -106,17 +107,20 @@ export class StoryUpdateProgress extends React.Component { // } switch ( payload.state ) { - case STORY_SAVE_STATE_SAVING: + case MEDIA_SAVE_STATE_SAVING: this.updateMediaSaveProgress( payload ); break; - case STORY_SAVE_STATE_SUCCEEDED: + case MEDIA_SAVE_STATE_SUCCEEDED: this.finishMediaSaveWithSuccess( payload ); break; - case STORY_SAVE_STATE_FAILED: + case MEDIA_SAVE_STATE_FAILED: this.finishMediaSaveWithFailure( payload ); break; - case STORY_SAVE_STATE_RESET: - this.mediaUploadStateReset( payload ); + case MEDIA_SAVE_STATE_RESET: + this.mediaSaveStateReset( payload ); + break; + case STORY_SAVE_STATE_RESULT: + this.storySaveResult( payload ); break; } } @@ -155,6 +159,19 @@ export class StoryUpdateProgress extends React.Component { this.props.onMediaSaveStateReset( payload ); } } + + storySaveResult( payload ) { + this.setState( { + progress: payload.progress, + isUploadInProgress: false, + isUploadFailed: false, + isSaveInProgress: false, + isSaveFailed: (! payload.success), + } ); + if ( this.props.onStorySaveResult ) { + this.props.onStorySaveResult( payload ); + } + } // ---- Story upload actions updateMediaUploadProgress( payload ) { @@ -238,7 +255,7 @@ export class StoryUpdateProgress extends React.Component { const progress = this.state.progress * 100; // eslint-disable-next-line @wordpress/i18n-no-collapsible-whitespace const retryMessage = __( - 'Failed to insert media.\nPlease tap for options.' + 'Failed to save Story.\nPlease tap for options.' ); return ( diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java index cd88b7d8358688..e5798c5be49354 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java @@ -39,6 +39,7 @@ interface StorySaveEventEmitter { void onMediaFileSaveProgress(String mediaId, float progress); void onMediaFileSaveSucceeded(String mediaId, String mediaUrl); void onMediaFileSaveFailed(String mediaId); + void onStorySaveResult(String storyFirstMediaId, boolean success); } interface ReplaceUnsupportedBlockCallback { diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java index 927212d4df8e48..e223c649e38479 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java @@ -54,6 +54,7 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu public static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_TYPE = "mediaType"; private static final String MAP_KEY_THEME_UPDATE_COLORS = "colors"; private static final String MAP_KEY_THEME_UPDATE_GRADIENTS = "gradients"; + public static final String MAP_KEY_STORY_SAVE_RESULT = "storySaveResult"; private static final String MAP_KEY_IS_PREFERRED_COLOR_SCHEME_DARK = "isPreferredColorSchemeDark"; diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java index 9f3dada6a044be..ac0d5e982c903b 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java @@ -16,6 +16,7 @@ import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID; import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_URL; +import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_STORY_SAVE_RESULT; public class DeferredEventEmitter implements MediaUploadEventEmitter, StorySaveEventEmitter { public interface JSEventEmitter { @@ -27,10 +28,11 @@ public interface JSEventEmitter { private static final int MEDIA_UPLOAD_STATE_FAILED = 3; private static final int MEDIA_UPLOAD_STATE_RESET = 4; - private static final int STORY_SAVE_STATE_SAVING = 5; - private static final int STORY_SAVE_STATE_SUCCEEDED = 6; - private static final int STORY_SAVE_STATE_FAILED = 7; - private static final int STORY_SAVE_STATE_RESET = 8; + private static final int MEDIA_SAVE_STATE_SAVING = 5; + private static final int MEDIA_SAVE_STATE_SUCCEEDED = 6; + private static final int MEDIA_SAVE_STATE_FAILED = 7; + private static final int MEDIA_SAVE_STATE_RESET = 8; + private static final int STORY_SAVE_STATE_RESULT = 9; private static final String EVENT_NAME_MEDIA_UPLOAD = "mediaUpload"; private static final String EVENT_NAME_MEDIA_SAVE = "mediaSave"; @@ -120,9 +122,22 @@ private void setStorySaveDataInJS(int state, String mediaId, String mediaUrl, fl } } + private void setStorySaveDataInJS(int state, String mediaId, boolean success, float progress) { + WritableMap writableMap = new WritableNativeMap(); + writableMap.putInt(MAP_KEY_MEDIA_FILE_UPLOAD_STATE, state); + writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID, mediaId); + writableMap.putBoolean(MAP_KEY_STORY_SAVE_RESULT, success); + writableMap.putDouble(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_PROGRESS, progress); + if (isCriticalMessage(state)) { + queueActionToJS(EVENT_NAME_MEDIA_SAVE, writableMap); + } else { + emitOrDrop(EVENT_NAME_MEDIA_SAVE, writableMap); + } + } + private boolean isCriticalMessage(int state) { return state == MEDIA_UPLOAD_STATE_SUCCEEDED || state == MEDIA_UPLOAD_STATE_FAILED - || state == STORY_SAVE_STATE_SUCCEEDED || state == STORY_SAVE_STATE_FAILED; + || state == MEDIA_SAVE_STATE_SUCCEEDED || state == MEDIA_SAVE_STATE_FAILED; } @Override @@ -148,22 +163,27 @@ public void onMediaFileUploadFailed(int mediaId) { // Story save events emitter @Override public void onSaveMediaFileClear(String mediaId) { - setStorySaveDataInJS(STORY_SAVE_STATE_RESET, mediaId, null, 0); + setStorySaveDataInJS(MEDIA_SAVE_STATE_RESET, mediaId, null, 0); } @Override public void onMediaFileSaveProgress(String mediaId, float progress) { - setStorySaveDataInJS(STORY_SAVE_STATE_SAVING, mediaId, null, progress); + setStorySaveDataInJS(MEDIA_SAVE_STATE_SAVING, mediaId, null, progress); } @Override public void onMediaFileSaveSucceeded(String mediaId, String mediaUrl) { - setStorySaveDataInJS(STORY_SAVE_STATE_SUCCEEDED, mediaId, mediaUrl, 1); + setStorySaveDataInJS(MEDIA_SAVE_STATE_SUCCEEDED, mediaId, mediaUrl, 1); } @Override public void onMediaFileSaveFailed(String mediaId) { - setStorySaveDataInJS(STORY_SAVE_STATE_FAILED, mediaId, null, 0); + setStorySaveDataInJS(MEDIA_SAVE_STATE_FAILED, mediaId, null, 0); + } + + @Override + public void onStorySaveResult(String storyFirstMediaId, boolean success) { + setStorySaveDataInJS(STORY_SAVE_STATE_RESULT, storyFirstMediaId, success, success ? 1 : 0); } public void updateCapabilities(GutenbergProps gutenbergProps) { diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java index 796d15d7bcca6a..a85b125798a4d3 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java @@ -884,6 +884,10 @@ public void mediaFileSaveSucceeded(final String mediaId, final String mediaUrl) mDeferredEventEmitter.onMediaFileSaveSucceeded(mediaId, mediaUrl); } + public void storySaveResult(final String storyFirstMediaId, final boolean success) { + mDeferredEventEmitter.onStorySaveResult(storyFirstMediaId, success); + } + public void replaceUnsupportedBlock(String content, String blockId) { if (mReplaceUnsupportedBlockCallback != null) { mReplaceUnsupportedBlockCallback.replaceUnsupportedBlock(content, blockId); From b305a9d8471aaff95b36911974d788bf1dfc69a8 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Mon, 28 Sep 2020 15:47:43 -0300 Subject: [PATCH 06/15] checking for matches of mediaId in mediaFiles while saving to send save progress updates --- .../components/story-update-progress/index.native.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/block-editor/src/components/story-update-progress/index.native.js b/packages/block-editor/src/components/story-update-progress/index.native.js index e437ca5afd22b5..a3cdaeb40e05f8 100644 --- a/packages/block-editor/src/components/story-update-progress/index.native.js +++ b/packages/block-editor/src/components/story-update-progress/index.native.js @@ -57,9 +57,12 @@ export class StoryUpdateProgress extends React.Component { } mediaIdContainedInMediaFiles( mediaId, mediaFiles ) { - // TODO check here if ( mediaId !== undefined && mediaFiles !== undefined ) { - return true; + for ( let i = 0; i < this.props.mediaFiles.length; i++ ) { + if ( mediaFiles[ i ].id === mediaId ) { + return true; + } + } } return false; } @@ -159,14 +162,14 @@ export class StoryUpdateProgress extends React.Component { this.props.onMediaSaveStateReset( payload ); } } - + storySaveResult( payload ) { this.setState( { progress: payload.progress, isUploadInProgress: false, isUploadFailed: false, isSaveInProgress: false, - isSaveFailed: (! payload.success), + isSaveFailed: ! payload.success, } ); if ( this.props.onStorySaveResult ) { this.props.onStorySaveResult( payload ); From 407b2d118c29c5ebf053aa0a8b1bf19ae5f2b0fe Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Mon, 28 Sep 2020 19:49:45 -0300 Subject: [PATCH 07/15] added mediaModelCreated() method to the bridge, so a new ID can be assigned to a mediaFile in a Story block --- .../story-update-progress/index.native.js | 18 +++++++++++++++++- .../GutenbergBridgeJS2Parent.java | 1 + .../RNReactNativeGutenbergBridgeModule.java | 1 + .../WPAndroidGlue/DeferredEventEmitter.java | 18 +++++++++++++++++- .../WPAndroidGlue/WPAndroidGlueCode.java | 4 ++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/components/story-update-progress/index.native.js b/packages/block-editor/src/components/story-update-progress/index.native.js index a3cdaeb40e05f8..088f9ace64f0dd 100644 --- a/packages/block-editor/src/components/story-update-progress/index.native.js +++ b/packages/block-editor/src/components/story-update-progress/index.native.js @@ -29,6 +29,7 @@ export const MEDIA_SAVE_STATE_SUCCEEDED = 6; export const MEDIA_SAVE_STATE_FAILED = 7; export const MEDIA_SAVE_STATE_RESET = 8; export const STORY_SAVE_STATE_RESULT = 9; +export const MEDIA_SAVE_MEDIAMODEL_CREATED = 10; export class StoryUpdateProgress extends React.Component { constructor( props ) { @@ -125,7 +126,10 @@ export class StoryUpdateProgress extends React.Component { case STORY_SAVE_STATE_RESULT: this.storySaveResult( payload ); break; - } + case MEDIA_SAVE_MEDIAMODEL_CREATED: + this.mediaModelCreated( payload ); + break; + } } // ---- Story (media) save actions @@ -176,6 +180,18 @@ export class StoryUpdateProgress extends React.Component { } } + mediaModelCreated( payload ) { + this.setState( { + isUploadInProgress: false, + isUploadFailed: false, + isSaveInProgress: false, + isSaveFailed: false, + } ); + if ( this.props.onMediaModelCreated ) { + this.props.onMediaModelCreated( payload ); + } + } + // ---- Story upload actions updateMediaUploadProgress( payload ) { this.setState( { diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java index e5798c5be49354..142c9617842e27 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java @@ -40,6 +40,7 @@ interface StorySaveEventEmitter { void onMediaFileSaveSucceeded(String mediaId, String mediaUrl); void onMediaFileSaveFailed(String mediaId); void onStorySaveResult(String storyFirstMediaId, boolean success); + void onMediaModelCreatedForFile(final String oldId, final String newId, final String oldUrl); } interface ReplaceUnsupportedBlockCallback { diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java index e223c649e38479..0367698007f9cf 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java @@ -49,6 +49,7 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu private static final String MAP_KEY_UPDATE_HTML = "html"; private static final String MAP_KEY_UPDATE_TITLE = "title"; + public static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_NEW_ID = "newId"; public static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID = "mediaId"; public static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_URL = "mediaUrl"; public static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_TYPE = "mediaType"; diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java index ac0d5e982c903b..54548042e8a0e7 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java @@ -15,6 +15,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID; +import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_NEW_ID; import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_URL; import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_STORY_SAVE_RESULT; @@ -33,6 +34,7 @@ public interface JSEventEmitter { private static final int MEDIA_SAVE_STATE_FAILED = 7; private static final int MEDIA_SAVE_STATE_RESET = 8; private static final int STORY_SAVE_STATE_RESULT = 9; + private static final int MEDIA_SAVE_MEDIAMODEL_CREATED = 10; private static final String EVENT_NAME_MEDIA_UPLOAD = "mediaUpload"; private static final String EVENT_NAME_MEDIA_SAVE = "mediaSave"; @@ -137,7 +139,8 @@ private void setStorySaveDataInJS(int state, String mediaId, boolean success, fl private boolean isCriticalMessage(int state) { return state == MEDIA_UPLOAD_STATE_SUCCEEDED || state == MEDIA_UPLOAD_STATE_FAILED - || state == MEDIA_SAVE_STATE_SUCCEEDED || state == MEDIA_SAVE_STATE_FAILED; + || state == MEDIA_SAVE_STATE_SUCCEEDED || state == MEDIA_SAVE_STATE_FAILED + || state == MEDIA_SAVE_MEDIAMODEL_CREATED; } @Override @@ -186,6 +189,19 @@ public void onStorySaveResult(String storyFirstMediaId, boolean success) { setStorySaveDataInJS(STORY_SAVE_STATE_RESULT, storyFirstMediaId, success, success ? 1 : 0); } + @Override public void onMediaModelCreatedForFile(String oldId, String newId, String oldUrl) { + WritableMap writableMap = new WritableNativeMap(); + writableMap.putInt(MAP_KEY_MEDIA_FILE_UPLOAD_STATE, MEDIA_SAVE_MEDIAMODEL_CREATED); + writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID, oldId); + writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_NEW_ID, newId); + writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_URL, oldUrl); + if (isCriticalMessage(MEDIA_SAVE_MEDIAMODEL_CREATED)) { + queueActionToJS(EVENT_NAME_MEDIA_SAVE, writableMap); + } else { + emitOrDrop(EVENT_NAME_MEDIA_SAVE, writableMap); + } + } + public void updateCapabilities(GutenbergProps gutenbergProps) { queueActionToJS(MAP_KEY_UPDATE_CAPABILITIES, Arguments.makeNativeMap(gutenbergProps.getUpdatedCapabilitiesProps())); } diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java index a85b125798a4d3..681cf404d7e039 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java @@ -888,6 +888,10 @@ public void storySaveResult(final String storyFirstMediaId, final boolean succes mDeferredEventEmitter.onStorySaveResult(storyFirstMediaId, success); } + public void mediaModelCreatedForFile(final String oldId, final String newId, final String oldUrl) { + mDeferredEventEmitter.onMediaModelCreatedForFile(oldId, newId, oldUrl); + } + public void replaceUnsupportedBlock(String content, String blockId) { if (mReplaceUnsupportedBlockCallback != null) { mReplaceUnsupportedBlockCallback.replaceUnsupportedBlock(content, blockId); From 269cc917dd552f34464ee704aec214f34172c55e Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Mon, 28 Sep 2020 21:18:07 -0300 Subject: [PATCH 08/15] mediaId should always be a string in mediaFiles so, converting to avoid strict comparison to fail --- .../src/components/story-update-progress/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/story-update-progress/index.native.js b/packages/block-editor/src/components/story-update-progress/index.native.js index 088f9ace64f0dd..3da50f3fe4d6d3 100644 --- a/packages/block-editor/src/components/story-update-progress/index.native.js +++ b/packages/block-editor/src/components/story-update-progress/index.native.js @@ -60,7 +60,7 @@ export class StoryUpdateProgress extends React.Component { mediaIdContainedInMediaFiles( mediaId, mediaFiles ) { if ( mediaId !== undefined && mediaFiles !== undefined ) { for ( let i = 0; i < this.props.mediaFiles.length; i++ ) { - if ( mediaFiles[ i ].id === mediaId ) { + if ( mediaFiles[ i ].id === mediaId.toString() ) { return true; } } From 5ce5e5c9c71affac73eb55e2e4f51e41a7e97a12 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Tue, 29 Sep 2020 12:17:28 -0300 Subject: [PATCH 09/15] removed commented code --- .../src/components/story-update-progress/index.native.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/block-editor/src/components/story-update-progress/index.native.js b/packages/block-editor/src/components/story-update-progress/index.native.js index 3da50f3fe4d6d3..143605bbeb88cd 100644 --- a/packages/block-editor/src/components/story-update-progress/index.native.js +++ b/packages/block-editor/src/components/story-update-progress/index.native.js @@ -77,9 +77,6 @@ export class StoryUpdateProgress extends React.Component { ) { return; } - // if ( payload.mediaId !== mediaId ) { - // return; - // } switch ( payload.state ) { case STORY_UPLOAD_STATE_UPLOADING: @@ -106,9 +103,6 @@ export class StoryUpdateProgress extends React.Component { ) { return; } - // if ( payload.mediaId !== mediaId ) { - // return; - // } switch ( payload.state ) { case MEDIA_SAVE_STATE_SAVING: From e83c8c8ce4574c0481f642a2ae21d53e159b5b34 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Wed, 30 Sep 2020 16:20:54 -0300 Subject: [PATCH 10/15] updated documentation --- .../components/story-update-progress/README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/block-editor/src/components/story-update-progress/README.md b/packages/block-editor/src/components/story-update-progress/README.md index c24a95a78b72ac..2ebfb12cfbf1c6 100644 --- a/packages/block-editor/src/components/story-update-progress/README.md +++ b/packages/block-editor/src/components/story-update-progress/README.md @@ -1,7 +1,7 @@ StoryUpdateProgress =================== -`StoryUpdateProgress` shows a progress bar while the media files associated with a Story block are being saved +`StoryUpdateProgress` shows a progress bar while the media files associated with a Story block are being saved and uploaded ## Usage @@ -13,17 +13,17 @@ import { StoryUpdateProgress, } from '@wordpress/block-editor'; -function MediaProgress( { url, id } ) { +function StoryProgress( { url, id } ) { return ( { + renderContent={ ( { isSaveFailed, retryMessage } ) => { return ( - { isUploadFailed && + { isSaveFailed && { retryMessage } @@ -38,11 +38,11 @@ function MediaProgress( { url, id } ) { ## Props -### mediaId +### mediaFiles -A media ID that identifies the current upload. +A collection of media ID that identifies the current story upload. -- Type: `Number` +- Type: `Array` - Required: Yes - Platform: Mobile @@ -56,7 +56,7 @@ Content to be rendered along with the progress bar, usually the thumbnail of the It passes an object containing the following properties: -`{ isUploadInProgress, isUploadFailed, retryMessage }` +`{ isUploadInProgress, isUploadFailed, isSaveInProgress, isSaveFailed, retryMessage }` ### onUpdateMediaProgress From 42288a565b6b9efb85c4a0e180bcb2b601fe9d6d Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Thu, 1 Oct 2020 00:33:41 -0300 Subject: [PATCH 11/15] added missing implementation of method storySaveSync() in demo app --- .../app/src/main/java/com/gutenberg/MainApplication.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainApplication.java b/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainApplication.java index eebb2007820433..83db0ff4421255 100644 --- a/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainApplication.java +++ b/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainApplication.java @@ -84,6 +84,10 @@ public void requestMediaPickFromMediaLibrary(MediaSelectedCallback mediaSelected public void mediaUploadSync(MediaSelectedCallback mediaSelectedCallback) { } + @Override + public void storySaveSync(MediaSelectedCallback mediaSelectedCallback) { + } + @Override public void requestImageFailedRetryDialog(int mediaId) { } From 5d385b58421e77c652fe4b2d5bc1414e1805cd32 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Thu, 1 Oct 2020 18:53:17 -0300 Subject: [PATCH 12/15] fixed prettier warning --- .../src/components/story-update-progress/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/story-update-progress/index.native.js b/packages/block-editor/src/components/story-update-progress/index.native.js index 143605bbeb88cd..0c370429c507e9 100644 --- a/packages/block-editor/src/components/story-update-progress/index.native.js +++ b/packages/block-editor/src/components/story-update-progress/index.native.js @@ -123,7 +123,7 @@ export class StoryUpdateProgress extends React.Component { case MEDIA_SAVE_MEDIAMODEL_CREATED: this.mediaModelCreated( payload ); break; - } + } } // ---- Story (media) save actions From 876ef24d53cd7a3ba63a62f970c8c8afe40adeb4 Mon Sep 17 00:00:00 2001 From: mzorz Date: Wed, 14 Oct 2020 11:32:06 -0300 Subject: [PATCH 13/15] Update packages/block-editor/src/components/story-update-progress/README.md Co-authored-by: Joel Dean --- .../src/components/story-update-progress/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/block-editor/src/components/story-update-progress/README.md b/packages/block-editor/src/components/story-update-progress/README.md index 2ebfb12cfbf1c6..652fa01b39857b 100644 --- a/packages/block-editor/src/components/story-update-progress/README.md +++ b/packages/block-editor/src/components/story-update-progress/README.md @@ -40,7 +40,7 @@ function StoryProgress( { url, id } ) { ### mediaFiles -A collection of media ID that identifies the current story upload. +A collection of media IDs that identify the current story upload. - Type: `Array` - Required: Yes @@ -102,4 +102,3 @@ Callback called when the media upload is reset - Type: `Function` - Required: No - Platform: Mobile - From 5b74fa09617c8c7dd1d0987aa8e40b34ce084768 Mon Sep 17 00:00:00 2001 From: mzorz Date: Wed, 14 Oct 2020 11:32:15 -0300 Subject: [PATCH 14/15] Update packages/block-editor/src/components/story-update-progress/README.md Co-authored-by: Joel Dean --- .../block-editor/src/components/story-update-progress/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/story-update-progress/README.md b/packages/block-editor/src/components/story-update-progress/README.md index 652fa01b39857b..75b87b0f4485ad 100644 --- a/packages/block-editor/src/components/story-update-progress/README.md +++ b/packages/block-editor/src/components/story-update-progress/README.md @@ -97,7 +97,7 @@ The argument of the callback is an object containing the following properties: ### onMediaUploadStateReset -Callback called when the media upload is reset +Callback called when the media upload is reset. - Type: `Function` - Required: No From e2889308a4f279c48f4f2fe451b9c0696e31147d Mon Sep 17 00:00:00 2001 From: mzorz Date: Wed, 14 Oct 2020 11:54:57 -0300 Subject: [PATCH 15/15] Mobile Stories block (part3: refactor / rename) (#26005) * renames for generic media files collection block and BlockMediaUpdateProgres * referencing the right props method in finishMediaSaveWithFailure * mistaken renames of parameters in bridge methods * renamed more abstract/generic method names requestMediaFilesEditorLoad * removed extra whtie space * renamed argument type --- .../README.md | 10 ++-- .../index.native.js | 42 +++++++------- .../styles.native.scss | 0 .../src/components/index.native.js | 2 +- .../GutenbergBridgeJS2Parent.java | 12 ++-- .../RNReactNativeGutenbergBridgeModule.java | 10 ++-- .../WPAndroidGlue/DeferredEventEmitter.java | 50 ++++++++-------- .../WPAndroidGlue/WPAndroidGlueCode.java | 58 +++++++++---------- packages/react-native-bridge/index.js | 8 +-- .../ios/RNReactNativeGutenbergBridge.m | 2 +- .../ios/RNReactNativeGutenbergBridge.swift | 4 +- .../java/com/gutenberg/MainApplication.java | 10 ++-- 12 files changed, 104 insertions(+), 104 deletions(-) rename packages/block-editor/src/components/{story-update-progress => block-media-update-progress}/README.md (87%) rename packages/block-editor/src/components/{story-update-progress => block-media-update-progress}/index.native.js (87%) rename packages/block-editor/src/components/{story-update-progress => block-media-update-progress}/styles.native.scss (100%) diff --git a/packages/block-editor/src/components/story-update-progress/README.md b/packages/block-editor/src/components/block-media-update-progress/README.md similarity index 87% rename from packages/block-editor/src/components/story-update-progress/README.md rename to packages/block-editor/src/components/block-media-update-progress/README.md index 75b87b0f4485ad..2f9844bc7a22be 100644 --- a/packages/block-editor/src/components/story-update-progress/README.md +++ b/packages/block-editor/src/components/block-media-update-progress/README.md @@ -1,7 +1,7 @@ -StoryUpdateProgress +BlockMediaUpdateProgress =================== -`StoryUpdateProgress` shows a progress bar while the media files associated with a Story block are being saved and uploaded +`BlockMediaUpdateProgress` shows a progress bar while the media files associated with a media-containing block are being saved first and uploaded later ## Usage @@ -10,12 +10,12 @@ Usage example ```jsx import { ImageBackground, Text, View } from 'react-native'; import { - StoryUpdateProgress, + BlockMediaUpdateProgress, } from '@wordpress/block-editor'; -function StoryProgress( { url, id } ) { +function BlockUpdatingProgress( { url, id } ) { return ( - { return ( diff --git a/packages/block-editor/src/components/story-update-progress/index.native.js b/packages/block-editor/src/components/block-media-update-progress/index.native.js similarity index 87% rename from packages/block-editor/src/components/story-update-progress/index.native.js rename to packages/block-editor/src/components/block-media-update-progress/index.native.js index 0c370429c507e9..0ff813f88c4721 100644 --- a/packages/block-editor/src/components/story-update-progress/index.native.js +++ b/packages/block-editor/src/components/block-media-update-progress/index.native.js @@ -19,19 +19,19 @@ import { */ import styles from './styles.scss'; -export const STORY_UPLOAD_STATE_UPLOADING = 1; -export const STORY_UPLOAD_STATE_SUCCEEDED = 2; -export const STORY_UPLOAD_STATE_FAILED = 3; -export const STORY_UPLOAD_STATE_RESET = 4; +export const MEDIA_UPLOAD_STATE_UPLOADING = 1; +export const MEDIA_UPLOAD_STATE_SUCCEEDED = 2; +export const MEDIA_UPLOAD_STATE_FAILED = 3; +export const MEDIA_UPLOAD_STATE_RESET = 4; export const MEDIA_SAVE_STATE_SAVING = 5; export const MEDIA_SAVE_STATE_SUCCEEDED = 6; export const MEDIA_SAVE_STATE_FAILED = 7; export const MEDIA_SAVE_STATE_RESET = 8; -export const STORY_SAVE_STATE_RESULT = 9; +export const MEDIA_SAVE_FINAL_STATE_RESULT = 9; export const MEDIA_SAVE_MEDIAMODEL_CREATED = 10; -export class StoryUpdateProgress extends React.Component { +export class BlockMediaUpdateProgress extends React.Component { constructor( props ) { super( props ); @@ -79,16 +79,16 @@ export class StoryUpdateProgress extends React.Component { } switch ( payload.state ) { - case STORY_UPLOAD_STATE_UPLOADING: + case MEDIA_UPLOAD_STATE_UPLOADING: this.updateMediaUploadProgress( payload ); break; - case STORY_UPLOAD_STATE_SUCCEEDED: + case MEDIA_UPLOAD_STATE_SUCCEEDED: this.finishMediaUploadWithSuccess( payload ); break; - case STORY_UPLOAD_STATE_FAILED: + case MEDIA_UPLOAD_STATE_FAILED: this.finishMediaUploadWithFailure( payload ); break; - case STORY_UPLOAD_STATE_RESET: + case MEDIA_UPLOAD_STATE_RESET: this.mediaUploadStateReset( payload ); break; } @@ -117,8 +117,8 @@ export class StoryUpdateProgress extends React.Component { case MEDIA_SAVE_STATE_RESET: this.mediaSaveStateReset( payload ); break; - case STORY_SAVE_STATE_RESULT: - this.storySaveResult( payload ); + case MEDIA_SAVE_FINAL_STATE_RESULT: + this.finalSaveResult( payload ); break; case MEDIA_SAVE_MEDIAMODEL_CREATED: this.mediaModelCreated( payload ); @@ -126,7 +126,7 @@ export class StoryUpdateProgress extends React.Component { } } - // ---- Story (media) save actions + // ---- Block media save actions updateMediaSaveProgress( payload ) { this.setState( { progress: payload.progress, @@ -149,8 +149,8 @@ export class StoryUpdateProgress extends React.Component { finishMediaSaveWithFailure( payload ) { this.setState( { isSaveInProgress: false, isSaveFailed: true } ); - if ( this.props.onFinishMediaUploadWithFailure ) { - this.props.onFinishMediaUploadWithFailure( payload ); + if ( this.props.onFinishMediaSaveWithFailure ) { + this.props.onFinishMediaSaveWithFailure( payload ); } } @@ -161,7 +161,7 @@ export class StoryUpdateProgress extends React.Component { } } - storySaveResult( payload ) { + finalSaveResult( payload ) { this.setState( { progress: payload.progress, isUploadInProgress: false, @@ -169,8 +169,8 @@ export class StoryUpdateProgress extends React.Component { isSaveInProgress: false, isSaveFailed: ! payload.success, } ); - if ( this.props.onStorySaveResult ) { - this.props.onStorySaveResult( payload ); + if ( this.props.onFinalSaveResult ) { + this.props.onFinalSaveResult( payload ); } } @@ -186,7 +186,7 @@ export class StoryUpdateProgress extends React.Component { } } - // ---- Story upload actions + // ---- Block media upload actions updateMediaUploadProgress( payload ) { this.setState( { progress: payload.progress, @@ -268,7 +268,7 @@ export class StoryUpdateProgress extends React.Component { const progress = this.state.progress * 100; // eslint-disable-next-line @wordpress/i18n-no-collapsible-whitespace const retryMessage = __( - 'Failed to save Story.\nPlease tap for options.' + 'Failed to save files.\nPlease tap for options.' ); return ( @@ -290,4 +290,4 @@ export class StoryUpdateProgress extends React.Component { } } -export default StoryUpdateProgress; +export default BlockMediaUpdateProgress; diff --git a/packages/block-editor/src/components/story-update-progress/styles.native.scss b/packages/block-editor/src/components/block-media-update-progress/styles.native.scss similarity index 100% rename from packages/block-editor/src/components/story-update-progress/styles.native.scss rename to packages/block-editor/src/components/block-media-update-progress/styles.native.scss diff --git a/packages/block-editor/src/components/index.native.js b/packages/block-editor/src/components/index.native.js index 8f8ab518934b4c..2245d16a1511ba 100644 --- a/packages/block-editor/src/components/index.native.js +++ b/packages/block-editor/src/components/index.native.js @@ -28,7 +28,7 @@ export { MEDIA_TYPE_VIDEO, } from './media-upload'; export { default as MediaUploadProgress } from './media-upload-progress'; -export { default as StoryUpdateProgress } from './story-update-progress'; +export { default as BlockMediaUpdateProgress } from './block-media-update-progress'; export { default as URLInput } from './url-input'; export { default as BlockInvalidWarning } from './block-list/block-invalid-warning'; export { default as BlockCaption } from './block-caption'; diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java index df5d2d3c8fd162..89cb3ccf3b5adc 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/GutenbergBridgeJS2Parent.java @@ -34,12 +34,12 @@ interface MediaUploadEventEmitter { void onMediaFileUploadFailed(int mediaId); } - interface StorySaveEventEmitter { + interface MediaSaveEventEmitter { void onSaveMediaFileClear(String mediaId); void onMediaFileSaveProgress(String mediaId, float progress); void onMediaFileSaveSucceeded(String mediaId, String mediaUrl); void onMediaFileSaveFailed(String mediaId); - void onStorySaveResult(String storyFirstMediaId, boolean success); + void onMediaCollectionSaveResult(String firstMediaIdInCollection, boolean success); void onMediaModelCreatedForFile(final String oldId, final String newId, final String oldUrl); } @@ -47,8 +47,8 @@ interface ReplaceUnsupportedBlockCallback { void replaceUnsupportedBlock(String content, String blockId); } - interface ReplaceStoryEditedBlockCallback { - void replaceStoryBlock(String mediaFiles, String blockId); + interface ReplaceMediaFilesEditedBlockCallback { + void replaceMediaFilesEditedBlock(String mediaFiles, String blockId); } interface StarterPageTemplatesTooltipShownCallback { @@ -135,7 +135,7 @@ public static GutenbergUserEvent getEnum(String eventName) { void mediaUploadSync(MediaSelectedCallback mediaSelectedCallback); - void storySaveSync(MediaSelectedCallback mediaSelectedCallback); + void mediaSaveSync(MediaSelectedCallback mediaSelectedCallback); void requestImageFailedRetryDialog(int mediaId); @@ -171,7 +171,7 @@ void gutenbergDidRequestUnsupportedBlockFallback(ReplaceUnsupportedBlockCallback void requestStarterPageTemplatesTooltipShown(StarterPageTemplatesTooltipShownCallback starterPageTemplatesTooltipShownCallback); - void requestStoryCreatorLoad(ReplaceStoryEditedBlockCallback replaceStoryEditedBlockCallback, + void requestMediaFilesEditorLoad(ReplaceMediaFilesEditedBlockCallback replaceMediaFilesEditedBlockCallback, ReadableArray mediaFiles, String blockId ); diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java index e589842a33a3a6..e64c9d357c2be2 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java @@ -55,7 +55,7 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu public static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_TYPE = "mediaType"; private static final String MAP_KEY_THEME_UPDATE_COLORS = "colors"; private static final String MAP_KEY_THEME_UPDATE_GRADIENTS = "gradients"; - public static final String MAP_KEY_STORY_SAVE_RESULT = "storySaveResult"; + public static final String MAP_KEY_MEDIA_FINAL_SAVE_RESULT = "mediaFinalSaveResult"; private static final String MAP_KEY_IS_PREFERRED_COLOR_SCHEME_DARK = "isPreferredColorSchemeDark"; @@ -198,8 +198,8 @@ public void mediaUploadSync() { } @ReactMethod - public void storySaveSync() { - mGutenbergBridgeJS2Parent.storySaveSync(getNewMediaSelectedCallback(true,null)); + public void mediaSaveSync() { + mGutenbergBridgeJS2Parent.mediaSaveSync(getNewMediaSelectedCallback(true,null)); } @ReactMethod @@ -228,8 +228,8 @@ public void requestMediaEditor(String mediaUrl, final Callback onUploadMediaSele } @ReactMethod - public void requestStoryCreatorLoad(ReadableArray mediaFiles, String blockId) { - mGutenbergBridgeJS2Parent.requestStoryCreatorLoad((savedMediaFiles, savedBlockId) -> + public void requestMediaFilesEditorLoad(ReadableArray mediaFiles, String blockId) { + mGutenbergBridgeJS2Parent.requestMediaFilesEditorLoad((savedMediaFiles, savedBlockId) -> replaceBlock(savedMediaFiles, savedBlockId), mediaFiles, blockId); } diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java index 54548042e8a0e7..98b473322a32f4 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/DeferredEventEmitter.java @@ -9,7 +9,7 @@ import com.facebook.react.bridge.WritableNativeMap; import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.MediaUploadEventEmitter; -import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.StorySaveEventEmitter; +import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.MediaSaveEventEmitter; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; @@ -17,9 +17,9 @@ import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID; import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_NEW_ID; import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_URL; -import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_STORY_SAVE_RESULT; +import static org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgeModule.MAP_KEY_MEDIA_FINAL_SAVE_RESULT; -public class DeferredEventEmitter implements MediaUploadEventEmitter, StorySaveEventEmitter { +public class DeferredEventEmitter implements MediaUploadEventEmitter, MediaSaveEventEmitter { public interface JSEventEmitter { void emitToJS(String eventName, @Nullable WritableMap data); } @@ -33,15 +33,15 @@ public interface JSEventEmitter { private static final int MEDIA_SAVE_STATE_SUCCEEDED = 6; private static final int MEDIA_SAVE_STATE_FAILED = 7; private static final int MEDIA_SAVE_STATE_RESET = 8; - private static final int STORY_SAVE_STATE_RESULT = 9; + private static final int MEDIA_SAVE_FINAL_STATE_RESULT = 9; private static final int MEDIA_SAVE_MEDIAMODEL_CREATED = 10; private static final String EVENT_NAME_MEDIA_UPLOAD = "mediaUpload"; private static final String EVENT_NAME_MEDIA_SAVE = "mediaSave"; - private static final String MAP_KEY_MEDIA_FILE_UPLOAD_STATE = "state"; - private static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_PROGRESS = "progress"; - private static final String MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_SERVER_ID = "mediaServerId"; + private static final String MAP_KEY_MEDIA_FILE_STATE = "state"; + private static final String MAP_KEY_MEDIA_FILE_MEDIA_ACTION_PROGRESS = "progress"; + private static final String MAP_KEY_MEDIA_FILE_MEDIA_SERVER_ID = "mediaServerId"; private static final String MAP_KEY_UPDATE_CAPABILITIES = "updateCapabilities"; @@ -97,12 +97,12 @@ private void setMediaFileUploadDataInJS(int state, int mediaId, String mediaUrl, private void setMediaFileUploadDataInJS(int state, int mediaId, String mediaUrl, float progress, int mediaServerId) { WritableMap writableMap = new WritableNativeMap(); - writableMap.putInt(MAP_KEY_MEDIA_FILE_UPLOAD_STATE, state); + writableMap.putInt(MAP_KEY_MEDIA_FILE_STATE, state); writableMap.putInt(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID, mediaId); writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_URL, mediaUrl); - writableMap.putDouble(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_PROGRESS, progress); + writableMap.putDouble(MAP_KEY_MEDIA_FILE_MEDIA_ACTION_PROGRESS, progress); if (mediaServerId != MEDIA_SERVER_ID_UNKNOWN) { - writableMap.putInt(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_SERVER_ID, mediaServerId); + writableMap.putInt(MAP_KEY_MEDIA_FILE_MEDIA_SERVER_ID, mediaServerId); } if (isCriticalMessage(state)) { queueActionToJS(EVENT_NAME_MEDIA_UPLOAD, writableMap); @@ -111,12 +111,12 @@ private void setMediaFileUploadDataInJS(int state, int mediaId, String mediaUrl, } } - private void setStorySaveDataInJS(int state, String mediaId, String mediaUrl, float progress) { + private void setMediaSaveResultDataInJS(int state, String mediaId, String mediaUrl, float progress) { WritableMap writableMap = new WritableNativeMap(); - writableMap.putInt(MAP_KEY_MEDIA_FILE_UPLOAD_STATE, state); + writableMap.putInt(MAP_KEY_MEDIA_FILE_STATE, state); writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID, mediaId); writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_URL, mediaUrl); - writableMap.putDouble(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_PROGRESS, progress); + writableMap.putDouble(MAP_KEY_MEDIA_FILE_MEDIA_ACTION_PROGRESS, progress); if (isCriticalMessage(state)) { queueActionToJS(EVENT_NAME_MEDIA_SAVE, writableMap); } else { @@ -124,12 +124,12 @@ private void setStorySaveDataInJS(int state, String mediaId, String mediaUrl, fl } } - private void setStorySaveDataInJS(int state, String mediaId, boolean success, float progress) { + private void setMediaSaveResultDataInJS(int state, String mediaId, boolean success, float progress) { WritableMap writableMap = new WritableNativeMap(); - writableMap.putInt(MAP_KEY_MEDIA_FILE_UPLOAD_STATE, state); + writableMap.putInt(MAP_KEY_MEDIA_FILE_STATE, state); writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID, mediaId); - writableMap.putBoolean(MAP_KEY_STORY_SAVE_RESULT, success); - writableMap.putDouble(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_PROGRESS, progress); + writableMap.putBoolean(MAP_KEY_MEDIA_FINAL_SAVE_RESULT, success); + writableMap.putDouble(MAP_KEY_MEDIA_FILE_MEDIA_ACTION_PROGRESS, progress); if (isCriticalMessage(state)) { queueActionToJS(EVENT_NAME_MEDIA_SAVE, writableMap); } else { @@ -163,35 +163,35 @@ public void onMediaFileUploadFailed(int mediaId) { setMediaFileUploadDataInJS(MEDIA_UPLOAD_STATE_FAILED, mediaId, null, 0); } - // Story save events emitter + // Media file save events emitter @Override public void onSaveMediaFileClear(String mediaId) { - setStorySaveDataInJS(MEDIA_SAVE_STATE_RESET, mediaId, null, 0); + setMediaSaveResultDataInJS(MEDIA_SAVE_STATE_RESET, mediaId, null, 0); } @Override public void onMediaFileSaveProgress(String mediaId, float progress) { - setStorySaveDataInJS(MEDIA_SAVE_STATE_SAVING, mediaId, null, progress); + setMediaSaveResultDataInJS(MEDIA_SAVE_STATE_SAVING, mediaId, null, progress); } @Override public void onMediaFileSaveSucceeded(String mediaId, String mediaUrl) { - setStorySaveDataInJS(MEDIA_SAVE_STATE_SUCCEEDED, mediaId, mediaUrl, 1); + setMediaSaveResultDataInJS(MEDIA_SAVE_STATE_SUCCEEDED, mediaId, mediaUrl, 1); } @Override public void onMediaFileSaveFailed(String mediaId) { - setStorySaveDataInJS(MEDIA_SAVE_STATE_FAILED, mediaId, null, 0); + setMediaSaveResultDataInJS(MEDIA_SAVE_STATE_FAILED, mediaId, null, 0); } @Override - public void onStorySaveResult(String storyFirstMediaId, boolean success) { - setStorySaveDataInJS(STORY_SAVE_STATE_RESULT, storyFirstMediaId, success, success ? 1 : 0); + public void onMediaCollectionSaveResult(String firstMediaIdInCollection, boolean success) { + setMediaSaveResultDataInJS(MEDIA_SAVE_FINAL_STATE_RESULT, firstMediaIdInCollection, success, success ? 1 : 0); } @Override public void onMediaModelCreatedForFile(String oldId, String newId, String oldUrl) { WritableMap writableMap = new WritableNativeMap(); - writableMap.putInt(MAP_KEY_MEDIA_FILE_UPLOAD_STATE, MEDIA_SAVE_MEDIAMODEL_CREATED); + writableMap.putInt(MAP_KEY_MEDIA_FILE_STATE, MEDIA_SAVE_MEDIAMODEL_CREATED); writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_ID, oldId); writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_NEW_ID, newId); writableMap.putString(MAP_KEY_MEDIA_FILE_UPLOAD_MEDIA_URL, oldUrl); diff --git a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java index 980c653aa6e31f..9c61321afd67fc 100644 --- a/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java +++ b/packages/react-native-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java @@ -49,7 +49,7 @@ import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent; import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.GutenbergUserEvent; import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.MediaSelectedCallback; -import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.ReplaceStoryEditedBlockCallback; +import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.ReplaceMediaFilesEditedBlockCallback; import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.ReplaceUnsupportedBlockCallback; import org.wordpress.mobile.ReactNativeGutenbergBridge.RNMedia; import org.wordpress.mobile.ReactNativeGutenbergBridge.RNReactNativeGutenbergBridgePackage; @@ -83,8 +83,8 @@ public class WPAndroidGlueCode { private boolean mAppendsMultipleSelectedToSiblingBlocks = false; private OnMediaLibraryButtonListener mOnMediaLibraryButtonListener; - private OnReattachQueryListener mOnReattachQueryListener; - private OnStorySavingReattachQueryListener mOnStorySavingReattachQueryListener; + private OnReattachMediaUploadQueryListener mOnReattachMediaUploadQueryListener; + private OnReattachMediaSavingQueryListener mOnReattachMediaSavingQueryListener; private OnEditorMountListener mOnEditorMountListener; private OnEditorAutosaveListener mOnEditorAutosaveListener; private OnImageFullscreenPreviewListener mOnImageFullscreenPreviewListener; @@ -94,8 +94,8 @@ public class WPAndroidGlueCode { private OnGutenbergDidSendButtonPressedActionListener mOnGutenbergDidSendButtonPressedActionListener; private ReplaceUnsupportedBlockCallback mReplaceUnsupportedBlockCallback; private OnStarterPageTemplatesTooltipShownEventListener mOnStarterPageTemplatesTooltipShownListener; - private OnStoryCreatorLoadRequestListener mOnStoryCreatorLoadRequestListener; - private ReplaceStoryEditedBlockCallback mReplaceStoryEditedBlockCallback; + private OnMediaFilesEditorLoadRequestListener mOnMediaFilesEditorLoadRequestListener; + private ReplaceMediaFilesEditedBlockCallback mReplaceMediaFilesEditedBlockCallback; private boolean mIsEditorMounted; private String mContentHtml = ""; @@ -150,20 +150,20 @@ public interface OnMediaLibraryButtonListener { void onOtherMediaButtonClicked(String mediaSource, boolean allowMultipleSelection); } - public interface OnStoryCreatorLoadRequestListener { - void onRequestStoryCreatorLoad(ArrayList mediaFiles, String blockId); + public interface OnMediaFilesEditorLoadRequestListener { + void onRequestMediaFilesEditorLoad(ArrayList mediaFiles, String blockId); } public interface OnImageFullscreenPreviewListener { void onImageFullscreenPreviewClicked(String mediaUrl); } - public interface OnReattachQueryListener { + public interface OnReattachMediaUploadQueryListener { void onQueryCurrentProgressForUploadingMedia(); } - public interface OnStorySavingReattachQueryListener { - void onQueryCurrentProgressForStoryMediaSaving(); + public interface OnReattachMediaSavingQueryListener { + void onQueryCurrentProgressForSavingMedia(); } public interface OnEditorMountListener { @@ -278,13 +278,13 @@ public void requestMediaImport(String url, MediaSelectedCallback mediaSelectedCa @Override public void mediaUploadSync(MediaSelectedCallback mediaSelectedCallback) { mMediaSelectedCallback = mediaSelectedCallback; - mOnReattachQueryListener.onQueryCurrentProgressForUploadingMedia(); + mOnReattachMediaUploadQueryListener.onQueryCurrentProgressForUploadingMedia(); } @Override - public void storySaveSync(MediaSelectedCallback mediaSelectedCallback) { + public void mediaSaveSync(MediaSelectedCallback mediaSelectedCallback) { mMediaSelectedCallback = mediaSelectedCallback; - mOnStorySavingReattachQueryListener.onQueryCurrentProgressForStoryMediaSaving(); + mOnReattachMediaSavingQueryListener.onQueryCurrentProgressForSavingMedia(); } @Override @@ -418,13 +418,13 @@ public void requestStarterPageTemplatesTooltipShown(StarterPageTemplatesTooltipS } @Override - public void requestStoryCreatorLoad( - ReplaceStoryEditedBlockCallback replaceStoryEditedBlockCallback, + public void requestMediaFilesEditorLoad( + ReplaceMediaFilesEditedBlockCallback replaceMediaFilesEditedBlockCallback, ReadableArray mediaFiles, String blockId ) { - mReplaceStoryEditedBlockCallback = replaceStoryEditedBlockCallback; - mOnStoryCreatorLoadRequestListener.onRequestStoryCreatorLoad(mediaFiles.toArrayList(), blockId); + mReplaceMediaFilesEditedBlockCallback = replaceMediaFilesEditedBlockCallback; + mOnMediaFilesEditorLoadRequestListener.onRequestMediaFilesEditorLoad(mediaFiles.toArrayList(), blockId); } }, mIsDarkMode); @@ -489,8 +489,8 @@ public void onCreateView(Context initContext, public void attachToContainer(ViewGroup viewGroup, OnMediaLibraryButtonListener onMediaLibraryButtonListener, - OnReattachQueryListener onReattachQueryListener, - OnStorySavingReattachQueryListener onStorySavingReattachQueryListener, + OnReattachMediaUploadQueryListener onReattachMediaUploadQueryListener, + OnReattachMediaSavingQueryListener onReattachMediaSavingQueryListener, OnEditorMountListener onEditorMountListener, OnEditorAutosaveListener onEditorAutosaveListener, OnAuthHeaderRequestedListener onAuthHeaderRequestedListener, @@ -502,14 +502,14 @@ public void attachToContainer(ViewGroup viewGroup, OnGutenbergDidSendButtonPressedActionListener onGutenbergDidSendButtonPressedActionListener, AddMentionUtil addMentionUtil, OnStarterPageTemplatesTooltipShownEventListener onStarterPageTemplatesTooltipListener, - OnStoryCreatorLoadRequestListener onStoryCreatorLoadRequestListener, + OnMediaFilesEditorLoadRequestListener onMediaFilesEditorLoadRequestListener, boolean isDarkMode) { MutableContextWrapper contextWrapper = (MutableContextWrapper) mReactRootView.getContext(); contextWrapper.setBaseContext(viewGroup.getContext()); mOnMediaLibraryButtonListener = onMediaLibraryButtonListener; - mOnReattachQueryListener = onReattachQueryListener; - mOnStorySavingReattachQueryListener = onStorySavingReattachQueryListener; + mOnReattachMediaUploadQueryListener = onReattachMediaUploadQueryListener; + mOnReattachMediaSavingQueryListener = onReattachMediaSavingQueryListener; mOnEditorMountListener = onEditorMountListener; mOnEditorAutosaveListener = onEditorAutosaveListener; mRequestExecutor = fetchExecutor; @@ -520,7 +520,7 @@ public void attachToContainer(ViewGroup viewGroup, mOnGutenbergDidSendButtonPressedActionListener = onGutenbergDidSendButtonPressedActionListener; mAddMentionUtil = addMentionUtil; mOnStarterPageTemplatesTooltipShownListener = onStarterPageTemplatesTooltipListener; - mOnStoryCreatorLoadRequestListener = onStoryCreatorLoadRequestListener; + mOnMediaFilesEditorLoadRequestListener = onMediaFilesEditorLoadRequestListener; sAddCookiesInterceptor.setOnAuthHeaderRequestedListener(onAuthHeaderRequestedListener); @@ -896,8 +896,8 @@ public void mediaFileSaveSucceeded(final String mediaId, final String mediaUrl) mDeferredEventEmitter.onMediaFileSaveSucceeded(mediaId, mediaUrl); } - public void storySaveResult(final String storyFirstMediaId, final boolean success) { - mDeferredEventEmitter.onStorySaveResult(storyFirstMediaId, success); + public void mediaCollectionFinalSaveResult(final String blockFirstMediaId, final boolean success) { + mDeferredEventEmitter.onMediaCollectionSaveResult(blockFirstMediaId, success); } public void mediaModelCreatedForFile(final String oldId, final String newId, final String oldUrl) { @@ -911,10 +911,10 @@ public void replaceUnsupportedBlock(String content, String blockId) { } } - public void replaceStoryEditedBlock(String mediaFiles, String blockId) { - if (mReplaceStoryEditedBlockCallback != null) { - mReplaceStoryEditedBlockCallback.replaceStoryBlock(mediaFiles, blockId); - mReplaceStoryEditedBlockCallback = null; + public void replaceMediaFilesEditedBlock(String mediaFiles, String blockId) { + if (mReplaceMediaFilesEditedBlockCallback != null) { + mReplaceMediaFilesEditedBlockCallback.replaceMediaFilesEditedBlock(mediaFiles, blockId); + mReplaceMediaFilesEditedBlockCallback = null; } } diff --git a/packages/react-native-bridge/index.js b/packages/react-native-bridge/index.js index b594debfc0e93a..c411f06dfd4716 100644 --- a/packages/react-native-bridge/index.js +++ b/packages/react-native-bridge/index.js @@ -179,8 +179,8 @@ export function mediaUploadSync() { return RNReactNativeGutenbergBridge.mediaUploadSync(); } -export function storySaveSync() { - return RNReactNativeGutenbergBridge.storySaveSync(); +export function mediaSaveSync() { + return RNReactNativeGutenbergBridge.mediaSaveSync(); } export function requestImageFailedRetryDialog( mediaId ) { @@ -252,8 +252,8 @@ export function setStarterPageTemplatesTooltipShown( tooltipShown ) { ); } -export function requestStoryCreatorLoad( mediaFiles, blockClientId ) { - return RNReactNativeGutenbergBridge.requestStoryCreatorLoad( +export function requestMediaFilesEditorLoad( mediaFiles, blockClientId ) { + return RNReactNativeGutenbergBridge.requestMediaFilesEditorLoad( mediaFiles, blockClientId ); diff --git a/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.m b/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.m index 618c1c73937f8b..46b813cfc660de 100644 --- a/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.m +++ b/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.m @@ -23,7 +23,7 @@ @interface RCT_EXTERN_MODULE(RNReactNativeGutenbergBridge, NSObject) RCT_EXTERN_METHOD(addMention:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)rejecter) RCT_EXTERN_METHOD(requestStarterPageTemplatesTooltipShown:(RCTResponseSenderBlock)callback) RCT_EXTERN_METHOD(setStarterPageTemplatesTooltipShown:(BOOL)tooltipShown) -RCT_EXTERN_METHOD(requestStoryCreatorLoad:(NSArray *)mediaFiles blockId:(NSString *)blockId) +RCT_EXTERN_METHOD(requestMediaFilesEditorLoad:(NSArray *)mediaFiles blockId:(NSString *)blockId) RCT_EXTERN_METHOD(actionButtonPressed:(NSString *)buttonType) @end diff --git a/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift b/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift index f2c81ecc085abb..c7dbfa38e6632e 100644 --- a/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift +++ b/packages/react-native-bridge/ios/RNReactNativeGutenbergBridge.swift @@ -289,11 +289,11 @@ public class RNReactNativeGutenbergBridge: RCTEventEmitter { } @objc - func requestStoryCreatorLoad(_ mediaFilesArray: [AnyObject], blockId: String) { + func requestMediaFilesEditorLoad(_ mediaFilesArray: [AnyObject], blockId: String) { // TODO actually implement the delegate call on iOS let mediaFiles = mediaFilesArray.compactMap { $0 as? String } // DispatchQueue.main.async { - // self.delegate?.gutenbergDidRequestStoryCreatorLoad(mediaFiles: mediaFiles, blockId: blockId) + // self.delegate?.gutenbergDidRequestMediaFilesEditorLoad(mediaFiles: mediaFiles, blockId: blockId) // } } diff --git a/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainApplication.java b/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainApplication.java index 2193936128fba7..a32138a0dba2e8 100644 --- a/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainApplication.java +++ b/packages/react-native-editor/android/app/src/main/java/com/gutenberg/MainApplication.java @@ -85,7 +85,7 @@ public void mediaUploadSync(MediaSelectedCallback mediaSelectedCallback) { } @Override - public void storySaveSync(MediaSelectedCallback mediaSelectedCallback) { + public void mediaSaveSync(MediaSelectedCallback mediaSelectedCallback) { } @Override @@ -177,14 +177,14 @@ public void onAddMention(Consumer onSuccess) { } @Override - public void requestStoryCreatorLoad( - ReplaceStoryEditedBlockCallback replaceStoryEditedBlockCallback, + public void requestMediaFilesEditorLoad( + ReplaceMediaFilesEditedBlockCallback replaceMediaFilesEditedBlockCallback, ReadableArray mediaFiles, String blockId ) { // mReplaceStoryEditedBlockCallback = replaceStoryEditedBlockCallback; - // mOnStoryCreatorLoadRequestListener.onRequestStoryCreatorLoad(content, blockId); - Toast.makeText(MainApplication.this, "requestStoryCreatorLoad called", Toast.LENGTH_SHORT).show(); + // mOnMediaFilesEditorLoadRequestListener.onRequestMediaFilesEditorLoad(content, blockId); + Toast.makeText(MainApplication.this, "requestMediaFilesEditorLoad called", Toast.LENGTH_SHORT).show(); } @Override