Page MenuHomePhabricator

D8343.id29202.diff
No OneTemporary

D8343.id29202.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
@@ -36,6 +36,7 @@
+setUserAvatar: (avatarRequest: UpdateUserAvatarRequest) => Promise<void>,
+setRegistrationMode: (registrationMode: RegistrationMode) => void,
+getRegistrationModeEnabled: () => boolean,
+ +getRegistrationModeSuccessCallback: () => ?(UserAvatarSelection) => mixed,
};
const EditUserAvatarContext: React.Context<?EditUserAvatarContextType> =
@@ -102,15 +103,6 @@
const setUserAvatar = React.useCallback(
async (request: UpdateUserAvatarRequest) => {
- const regMode = registrationModeRef.current;
- if (regMode.registrationMode === 'on') {
- regMode.successCallback({
- needsUpload: false,
- updateUserAvatarRequest: request,
- });
- return;
- }
-
const promise = updateUserAvatarCall(request);
dispatchActionPromise(updateUserAvatarActionTypes, promise);
await promise;
@@ -125,6 +117,13 @@
() => registrationModeRef.current.registrationMode === 'on',
[],
);
+ const getRegistrationModeSuccessCallback = React.useCallback(
+ () =>
+ registrationModeRef.current.registrationMode === 'on'
+ ? registrationModeRef.current.successCallback
+ : null,
+ [],
+ );
const context = React.useMemo(
() => ({
@@ -133,6 +132,7 @@
setUserAvatar,
setRegistrationMode,
getRegistrationModeEnabled,
+ getRegistrationModeSuccessCallback,
}),
[
userAvatarSaveInProgress,
@@ -140,6 +140,7 @@
setUserAvatar,
setRegistrationMode,
getRegistrationModeEnabled,
+ getRegistrationModeSuccessCallback,
],
);
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
@@ -200,17 +200,39 @@
) => Promise<void> {
const editUserAvatarContext = React.useContext(EditUserAvatarContext);
invariant(editUserAvatarContext, 'editUserAvatarContext must be defined');
- const { setUserAvatar } = editUserAvatarContext;
+ const {
+ setUserAvatar,
+ getRegistrationModeEnabled,
+ getRegistrationModeSuccessCallback,
+ } = editUserAvatarContext;
const nativeSetUserAvatar = React.useCallback(
async (request: UpdateUserAvatarRequest) => {
+ const registrationModeEnabled = getRegistrationModeEnabled();
+ if (registrationModeEnabled) {
+ const successCallback = getRegistrationModeSuccessCallback();
+ invariant(
+ successCallback,
+ 'successCallback must be defined if registrationModeEnabled is true',
+ );
+ successCallback({
+ needsUpload: false,
+ updateUserAvatarRequest: request,
+ });
+ return;
+ }
+
try {
await setUserAvatar(request);
} catch {
displayAvatarUpdateFailureAlert();
}
},
- [setUserAvatar],
+ [
+ getRegistrationModeEnabled,
+ getRegistrationModeSuccessCallback,
+ setUserAvatar,
+ ],
);
return nativeSetUserAvatar;

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 24, 12:14 AM (19 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2696195
Default Alt Text
D8343.id29202.diff (3 KB)

Event Timeline