Page MenuHomePhabricator

D8343.id28196.diff
No OneTemporary

D8343.id28196.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 = (async () => {
return await updateUserAvatarCall(request);
})();
@@ -127,6 +119,13 @@
() => registrationModeRef.current.registrationMode === 'on',
[],
);
+ const getRegistrationModeSuccessCallback = React.useCallback(
+ () =>
+ registrationModeRef.current.registrationMode === 'on'
+ ? registrationModeRef.current.successCallback
+ : null,
+ [],
+ );
const context = React.useMemo(
() => ({
@@ -135,6 +134,7 @@
setUserAvatar,
setRegistrationMode,
getRegistrationModeEnabled,
+ getRegistrationModeSuccessCallback,
}),
[
userAvatarSaveInProgress,
@@ -142,6 +142,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
Mon, Dec 23, 11:56 PM (18 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2697430
Default Alt Text
D8343.id28196.diff (3 KB)

Event Timeline