Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3520614
D8346.id28199.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
D8346.id28199.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
@@ -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.
@@ -123,6 +118,7 @@
const context = React.useMemo(
() => ({
+ setUserAvatarMediaUploadInProgress,
userAvatarSaveInProgress,
updateImageUserAvatar,
baseSetUserAvatar,
@@ -131,6 +127,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
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 12:49 AM (20 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2697625
Default Alt Text
D8346.id28199.diff (3 KB)
Attached To
Mode
D8346: Move `native`-specific `uploadSelectedMedia` from `updateImageUserAvatar` to `nativeUpdateUserImageAvatar`
Attached
Detach File
Event Timeline
Log In to Comment