Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update Image block failed upload visuals #56937

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
62191f5
refactor: Rename `useIsConnected` to `useNetworkConnectivity`
dcalhoun Dec 14, 2023
1af5f0e
test: Add `useNetworkConnectivity` Hook tests
dcalhoun Dec 14, 2023
25d141a
docs: Document `useNetworkConnectivity` Hook
dcalhoun Dec 14, 2023
ddc08b8
refactor: Rename `withIsConnected` to `withNetworkConnectivity`
dcalhoun Dec 14, 2023
f7bccf5
fix: Optimistically presume network connectivity
dcalhoun Dec 14, 2023
59995b3
test: Create realistic default `requestConnectionStatus` mock
dcalhoun Dec 14, 2023
30bf2a0
fix: Prevent duplicative offline status indicators
dcalhoun Dec 16, 2023
cb7e168
Add subscribeConnectionStatus to MediaUploadProgress component
derekblank Dec 11, 2023
1ce863f
Update MediaUploadProgress to use withIsConnected HOC
derekblank Dec 12, 2023
c223aa8
refactor: Fix HoC name reference
dcalhoun Dec 20, 2023
22e5851
refactor: Enable Fast Refresh for Image component
dcalhoun Dec 21, 2023
cdae407
feat: Update the image offline message
dcalhoun Dec 21, 2023
dd4e5db
refactor: Avoid unnecessary inconsistency in switch case logic
dcalhoun Dec 21, 2023
070979a
refactor: Enable Fast Refresh for Image component
dcalhoun Dec 21, 2023
533a348
feat: Revert logic intended to display progress bar when offline
dcalhoun Dec 21, 2023
4e92330
refactor: Remove sizing from offline SVG
dcalhoun Dec 21, 2023
ec9f1a0
feat: Update Image block media upload visuals
dcalhoun Dec 21, 2023
4938a1e
feat: Add paused media upload state
dcalhoun Dec 22, 2023
a5d533d
Merge branch 'trunk' into rnmobile/media-upload-progress-connection-s…
derekblank Dec 28, 2023
a66e3ae
feat: Scope the paused upload state to the Image block
dcalhoun Jan 2, 2024
4927d9f
feat: Enable paused media uploads for Media and Text block types
dcalhoun Jan 2, 2024
210b43f
perf: Avoid unnecessary state updates and callback invocations
dcalhoun Jan 2, 2024
21aa5a5
Add MEDIA_UPLOAD_STATE_PAUSED to Android DeferredEvent emitter
derekblank Jan 3, 2024
9db9142
feat: Add Android paused media upload bridge methods
dcalhoun Jan 3, 2024
8c441f8
Merge branch 'trunk' of github.com:WordPress/gutenberg into rnmobile/…
dcalhoun Jan 4, 2024
96b7c0c
docs: Add change log entry
dcalhoun Jan 4, 2024
6b6600f
feat: Add image upload failure dark mode styles
dcalhoun Jan 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ export {
MEDIA_TYPE_AUDIO,
MEDIA_TYPE_ANY,
} from './media-upload/constants';
export { default as MediaUploadProgress } from './media-upload-progress';
export {
default as MediaUploadProgress,
MEDIA_UPLOAD_STATE_UPLOADING,
MEDIA_UPLOAD_STATE_SUCCEEDED,
MEDIA_UPLOAD_STATE_FAILED,
MEDIA_UPLOAD_STATE_RESET,
} from './media-upload-progress';
} from './media-upload-progress/constants';
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';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const MEDIA_UPLOAD_STATE_IDLE = 0;
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_UPLOAD_STATE_PAUSED = 11;
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,28 @@ import { subscribeMediaUpload } from '@wordpress/react-native-bridge';
* Internal dependencies
*/
import styles from './styles.scss';

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;
import {
MEDIA_UPLOAD_STATE_IDLE,
MEDIA_UPLOAD_STATE_UPLOADING,
MEDIA_UPLOAD_STATE_SUCCEEDED,
MEDIA_UPLOAD_STATE_FAILED,
MEDIA_UPLOAD_STATE_RESET,
MEDIA_UPLOAD_STATE_PAUSED,
} from './constants';

export class MediaUploadProgress extends Component {
constructor( props ) {
super( props );

this.state = {
uploadState: MEDIA_UPLOAD_STATE_IDLE,
progress: 0,
isUploadInProgress: false,
isUploadFailed: false,
};

this.mediaUpload = this.mediaUpload.bind( this );
this.getRetryMessage = this.getRetryMessage.bind( this );
}

componentDidMount() {
Expand All @@ -45,7 +50,11 @@ export class MediaUploadProgress extends Component {
mediaUpload( payload ) {
const { mediaId } = this.props;

if ( payload.mediaId !== mediaId ) {
if (
payload.mediaId !== mediaId ||
( payload.state === this.state.uploadState &&
payload.progress === this.state.progress )
) {
return;
}

Expand All @@ -56,6 +65,9 @@ export class MediaUploadProgress extends Component {
case MEDIA_UPLOAD_STATE_SUCCEEDED:
this.finishMediaUploadWithSuccess( payload );
break;
case MEDIA_UPLOAD_STATE_PAUSED:
this.finishMediaUploadWithPause( payload );
break;
case MEDIA_UPLOAD_STATE_FAILED:
this.finishMediaUploadWithFailure( payload );
break;
Expand All @@ -68,6 +80,7 @@ export class MediaUploadProgress extends Component {
updateMediaProgress( payload ) {
this.setState( {
progress: payload.progress,
uploadState: payload.state,
isUploadInProgress: true,
isUploadFailed: false,
} );
Expand All @@ -77,21 +90,48 @@ export class MediaUploadProgress extends Component {
}

finishMediaUploadWithSuccess( payload ) {
this.setState( { isUploadInProgress: false } );
this.setState( {
uploadState: payload.state,
isUploadInProgress: false,
} );
if ( this.props.onFinishMediaUploadWithSuccess ) {
this.props.onFinishMediaUploadWithSuccess( payload );
}
}

finishMediaUploadWithPause( payload ) {
if ( ! this.props.enablePausedUploads ) {
this.finishMediaUploadWithFailure( payload );
return;
}

this.setState( {
uploadState: payload.state,
isUploadInProgress: true,
isUploadFailed: false,
} );
if ( this.props.onFinishMediaUploadWithFailure ) {
this.props.onFinishMediaUploadWithFailure( payload );
}
}

finishMediaUploadWithFailure( payload ) {
this.setState( { isUploadInProgress: false, isUploadFailed: true } );
this.setState( {
uploadState: payload.state,
isUploadInProgress: false,
isUploadFailed: true,
} );
if ( this.props.onFinishMediaUploadWithFailure ) {
this.props.onFinishMediaUploadWithFailure( payload );
}
}

mediaUploadStateReset( payload ) {
this.setState( { isUploadInProgress: false, isUploadFailed: false } );
this.setState( {
uploadState: payload.state,
isUploadInProgress: false,
isUploadFailed: false,
} );
if ( this.props.onMediaUploadStateReset ) {
this.props.onMediaUploadStateReset( payload );
}
Expand All @@ -115,15 +155,24 @@ export class MediaUploadProgress extends Component {
}
}

getRetryMessage() {
if (
this.state.uploadState === MEDIA_UPLOAD_STATE_PAUSED &&
this.props.enablePausedUploads
) {
return __( 'Waiting for connection' );
}

// eslint-disable-next-line @wordpress/i18n-no-collapsible-whitespace
return __( 'Failed to insert media.\nTap for more info.' );
}

render() {
const { renderContent = () => null } = this.props;
const { isUploadInProgress, isUploadFailed } = this.state;
const { isUploadInProgress, isUploadFailed, uploadState } = this.state;
const showSpinner = this.state.isUploadInProgress;
const progress = this.state.progress * 100;
// eslint-disable-next-line @wordpress/i18n-no-collapsible-whitespace
const retryMessage = __(
'Failed to insert media.\nTap for more info.'
);
const retryMessage = this.getRetryMessage();

const progressBarStyle = [
styles.progressBar,
Expand All @@ -149,6 +198,9 @@ export class MediaUploadProgress extends Component {
) }
</View>
{ renderContent( {
isUploadPaused:
uploadState === MEDIA_UPLOAD_STATE_PAUSED &&
this.props.enablePausedUploads,
isUploadInProgress,
isUploadFailed,
retryMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import {
/**
* Internal dependencies
*/
import { MediaUploadProgress } from '../';
import {
MediaUploadProgress,
MEDIA_UPLOAD_STATE_UPLOADING,
MEDIA_UPLOAD_STATE_SUCCEEDED,
MEDIA_UPLOAD_STATE_FAILED,
MEDIA_UPLOAD_STATE_RESET,
} from '../';
} from '../constants';

let uploadCallBack;
subscribeMediaUpload.mockImplementation( ( callback ) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ export class ImageEdit extends Component {
{ ! this.state.isCaptionSelected &&
getToolbarEditButton( openMediaOptions ) }
<MediaUploadProgress
enablePausedUploads
coverUrl={ url }
mediaId={ id }
onUpdateMediaProgress={ this.updateMediaProgress }
Expand All @@ -825,6 +826,7 @@ export class ImageEdit extends Component {
this.mediaUploadStateReset
}
renderContent={ ( {
isUploadPaused,
isUploadInProgress,
isUploadFailed,
retryMessage,
Expand All @@ -843,6 +845,7 @@ export class ImageEdit extends Component {
! isCaptionSelected
}
isUploadFailed={ isUploadFailed }
isUploadPaused={ isUploadPaused }
isUploadInProgress={
isUploadInProgress
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class MediaContainer extends Component {
mediaWidth,
shouldStack,
} = this.props;
const { isUploadFailed, retryMessage } = params;
const { isUploadFailed, isUploadPaused, retryMessage } = params;
const focalPointValues = ! focalPoint
? IMAGE_DEFAULT_FOCAL_POINT
: focalPoint;
Expand Down Expand Up @@ -203,6 +203,7 @@ class MediaContainer extends Component {
focalPoint={ imageFill && focalPointValues }
isSelected={ isMediaSelected }
isUploadFailed={ isUploadFailed }
isUploadPaused={ isUploadPaused }
isUploadInProgress={ isUploadInProgress }
onSelectMediaUploadOption={
this.onSelectMediaUploadOption
Expand Down Expand Up @@ -340,6 +341,7 @@ class MediaContainer extends Component {
{ getMediaOptions() }

<MediaUploadProgress
enablePausedUploads
coverUrl={ coverUrl }
mediaId={ mediaId }
onUpdateMediaProgress={
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export { default as LinkSettings } from './mobile/link-settings';
export { default as LinkSettingsScreen } from './mobile/link-settings/link-settings-screen';
export { default as LinkSettingsNavigation } from './mobile/link-settings/link-settings-navigation';
export { default as SegmentedControl } from './mobile/segmented-control';
export { default as Image, IMAGE_DEFAULT_FOCAL_POINT } from './mobile/image';
export { default as Image } from './mobile/image';
export { IMAGE_DEFAULT_FOCAL_POINT } from './mobile/image/constants';
export { default as ImageEditingButton } from './mobile/image/image-editing-button';
export { setClipboard, getClipboard } from './mobile/clipboard';
export { default as AudioPlayer } from './mobile/audio-player';
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/mobile/image/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const IMAGE_DEFAULT_FOCAL_POINT = { x: 0.5, y: 0.5 };
Loading
Loading