Page MenuHomePhabricator

D8346.id29210.diff
No OneTemporary

D8346.id29210.diff

diff --git a/lib/components/base-edit-user-avatar-provider.react.js b/lib/components/base-edit-user-avatar-provider.react.js
--- a/lib/components/base-edit-user-avatar-provider.react.js
+++ b/lib/components/base-edit-user-avatar-provider.react.js
@@ -11,6 +11,7 @@
ImageAvatarDBContent,
UpdateUserAvatarRequest,
} from '../types/avatar-types.js';
+import type { SetState } from '../types/hook-types.js';
import type { LoadingStatus } from '../types/loading-types.js';
import type { NativeMediaSelection } from '../types/media-types.js';
import {
@@ -31,8 +32,11 @@
const registrationModeOff = { registrationMode: 'off' };
export type EditUserAvatarContextType = {
+ +setUserAvatarMediaUploadInProgress: SetState<boolean>,
+userAvatarSaveInProgress: boolean,
- +updateImageUserAvatar: (selection: NativeMediaSelection) => Promise<void>,
+ +updateImageUserAvatar: (
+ imageAvatarUpdateRequest: ImageAvatarDBContent,
+ ) => Promise<void>,
+baseSetUserAvatar: (avatarRequest: UpdateUserAvatarRequest) => Promise<void>,
+setRegistrationMode: (registrationMode: RegistrationMode) => void,
+getRegistrationModeEnabled: () => boolean,
@@ -53,7 +57,7 @@
+children: React.Node,
};
function BaseEditUserAvatarProvider(props: Props): React.Node {
- const { useUploadSelectedMedia, children } = props;
+ const { children } = props;
const registrationModeRef =
React.useRef<RegistrationMode>(registrationModeOff);
@@ -72,17 +76,8 @@
userAvatarMediaUploadInProgress ||
updateUserAvatarLoadingStatus === 'loading';
- const uploadSelectedMedia = useUploadSelectedMedia(
- setUserAvatarMediaUploadInProgress,
- );
-
const updateImageUserAvatar = React.useCallback(
- async (selection: NativeMediaSelection) => {
- const imageAvatarUpdateRequest = await uploadSelectedMedia(selection);
- if (!imageAvatarUpdateRequest) {
- return;
- }
-
+ async (imageAvatarUpdateRequest: ImageAvatarDBContent) => {
const promise = (async () => {
setUserAvatarMediaUploadInProgress(false);
return await updateUserAvatarCall(imageAvatarUpdateRequest);
@@ -90,7 +85,7 @@
dispatchActionPromise(updateUserAvatarActionTypes, promise);
await promise;
},
- [uploadSelectedMedia, dispatchActionPromise, updateUserAvatarCall],
+ [dispatchActionPromise, updateUserAvatarCall],
);
// NOTE: Do NOT consume `baseSetUserAvatar` directly.
@@ -121,6 +116,7 @@
const context = React.useMemo(
() => ({
+ setUserAvatarMediaUploadInProgress,
userAvatarSaveInProgress,
updateImageUserAvatar,
baseSetUserAvatar,
@@ -129,6 +125,7 @@
getRegistrationModeSuccessCallback,
}),
[
+ setUserAvatarMediaUploadInProgress,
userAvatarSaveInProgress,
updateImageUserAvatar,
baseSetUserAvatar,
diff --git a/native/avatars/avatar-hooks.js b/native/avatars/avatar-hooks.js
--- a/native/avatars/avatar-hooks.js
+++ b/native/avatars/avatar-hooks.js
@@ -247,8 +247,13 @@
updateImageUserAvatar,
getRegistrationModeEnabled,
getRegistrationModeSuccessCallback,
+ setUserAvatarMediaUploadInProgress,
} = editUserAvatarContext;
+ const uploadSelectedMedia = useUploadSelectedMedia(
+ setUserAvatarMediaUploadInProgress,
+ );
+
const nativeUpdateUserImageAvatar = React.useCallback(
async (selection: NativeMediaSelection) => {
const registrationModeEnabled = getRegistrationModeEnabled();
@@ -265,8 +270,13 @@
return;
}
+ const imageAvatarUpdateRequest = await uploadSelectedMedia(selection);
+ if (!imageAvatarUpdateRequest) {
+ return;
+ }
+
try {
- await updateImageUserAvatar(selection);
+ await updateImageUserAvatar(imageAvatarUpdateRequest);
} catch {
displayAvatarUpdateFailureAlert();
}
@@ -275,6 +285,7 @@
getRegistrationModeEnabled,
getRegistrationModeSuccessCallback,
updateImageUserAvatar,
+ uploadSelectedMedia,
],
);

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 23, 11:32 PM (18 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2696018
Default Alt Text
D8346.id29210.diff (3 KB)

Event Timeline