diff --git a/lib/components/base-edit-user-avatar-provider.react.js b/lib/components/base-edit-user-avatar-provider.react.js index e4ad0afada..c4a3fdc7d9 100644 --- a/lib/components/base-edit-user-avatar-provider.react.js +++ b/lib/components/base-edit-user-avatar-provider.react.js @@ -33,7 +33,7 @@ const registrationModeOff = { registrationMode: 'off' }; export type EditUserAvatarContextType = { +userAvatarSaveInProgress: boolean, +updateImageUserAvatar: (selection: NativeMediaSelection) => Promise, - +setUserAvatar: (avatarRequest: UpdateUserAvatarRequest) => Promise, + +baseSetUserAvatar: (avatarRequest: UpdateUserAvatarRequest) => Promise, +setRegistrationMode: (registrationMode: RegistrationMode) => void, +getRegistrationModeEnabled: () => boolean, +getRegistrationModeSuccessCallback: () => ?(UserAvatarSelection) => mixed, @@ -101,7 +101,9 @@ function BaseEditUserAvatarProvider(props: Props): React.Node { [uploadSelectedMedia, dispatchActionPromise, updateUserAvatarCall], ); - const setUserAvatar = React.useCallback( + // NOTE: Do NOT consume `baseSetUserAvatar` directly. + // Use platform-specific `[web/native]SetUserAvatar` instead. + const baseSetUserAvatar = React.useCallback( async (request: UpdateUserAvatarRequest) => { const promise = updateUserAvatarCall(request); dispatchActionPromise(updateUserAvatarActionTypes, promise); @@ -129,7 +131,7 @@ function BaseEditUserAvatarProvider(props: Props): React.Node { () => ({ userAvatarSaveInProgress, updateImageUserAvatar, - setUserAvatar, + baseSetUserAvatar, setRegistrationMode, getRegistrationModeEnabled, getRegistrationModeSuccessCallback, @@ -137,7 +139,7 @@ function BaseEditUserAvatarProvider(props: Props): React.Node { [ userAvatarSaveInProgress, updateImageUserAvatar, - setUserAvatar, + baseSetUserAvatar, setRegistrationMode, getRegistrationModeEnabled, getRegistrationModeSuccessCallback, diff --git a/native/avatars/avatar-hooks.js b/native/avatars/avatar-hooks.js index de5a8bb43d..a4ebf358fa 100644 --- a/native/avatars/avatar-hooks.js +++ b/native/avatars/avatar-hooks.js @@ -201,7 +201,7 @@ function useNativeSetUserAvatar(): ( const editUserAvatarContext = React.useContext(EditUserAvatarContext); invariant(editUserAvatarContext, 'editUserAvatarContext must be defined'); const { - setUserAvatar, + baseSetUserAvatar, getRegistrationModeEnabled, getRegistrationModeSuccessCallback, } = editUserAvatarContext; @@ -223,7 +223,7 @@ function useNativeSetUserAvatar(): ( } try { - await setUserAvatar(request); + await baseSetUserAvatar(request); } catch { displayAvatarUpdateFailureAlert(); } @@ -231,7 +231,7 @@ function useNativeSetUserAvatar(): ( [ getRegistrationModeEnabled, getRegistrationModeSuccessCallback, - setUserAvatar, + baseSetUserAvatar, ], ); diff --git a/web/avatars/edit-user-avatar-menu.react.js b/web/avatars/edit-user-avatar-menu.react.js index c71e71220d..3ebcae545d 100644 --- a/web/avatars/edit-user-avatar-menu.react.js +++ b/web/avatars/edit-user-avatar-menu.react.js @@ -23,11 +23,11 @@ function EditUserAvatarMenu(): React.Node { const editUserAvatarContext = React.useContext(EditUserAvatarContext); invariant(editUserAvatarContext, 'editUserAvatarContext should be set'); - const { setUserAvatar } = editUserAvatarContext; + const { baseSetUserAvatar } = editUserAvatarContext; const removeUserAvatar = React.useCallback( - () => setUserAvatar({ type: 'remove' }), - [setUserAvatar], + () => baseSetUserAvatar({ type: 'remove' }), + [baseSetUserAvatar], ); const { pushModal } = useModalContext(); diff --git a/web/avatars/emoji-avatar-selection-modal.react.js b/web/avatars/emoji-avatar-selection-modal.react.js index b9f889a320..effb81453d 100644 --- a/web/avatars/emoji-avatar-selection-modal.react.js +++ b/web/avatars/emoji-avatar-selection-modal.react.js @@ -35,7 +35,7 @@ function EmojiAvatarSelectionModal(): React.Node { const editUserAvatarContext = React.useContext(EditUserAvatarContext); invariant(editUserAvatarContext, 'editUserAvatarContext should be set'); - const { setUserAvatar, userAvatarSaveInProgress } = editUserAvatarContext; + const { baseSetUserAvatar, userAvatarSaveInProgress } = editUserAvatarContext; const [updateAvatarStatus, setUpdateAvatarStatus] = React.useState(); @@ -80,12 +80,12 @@ function EmojiAvatarSelectionModal(): React.Node { const onSaveAvatar = React.useCallback(async () => { try { - await setUserAvatar(pendingEmojiAvatar); + await baseSetUserAvatar(pendingEmojiAvatar); setUpdateAvatarStatus('success'); } catch { setUpdateAvatarStatus('failure'); } - }, [pendingEmojiAvatar, setUserAvatar]); + }, [pendingEmojiAvatar, baseSetUserAvatar]); let saveButtonContent; let buttonColor;