Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3518516
D8343.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D8343.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 8:08 PM (15 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2696195
Default Alt Text
D8343.diff (3 KB)
Attached To
Mode
D8343: Move registrationMode-related logic from `setUserAvatar` to `nativeSetUserAvatar`
Attached
Detach File
Event Timeline
Log In to Comment