Page MenuHomePhabricator

D8318.diff
No OneTemporary

D8318.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
@@ -12,10 +12,7 @@
UpdateUserAvatarRequest,
} from '../types/avatar-types.js';
import type { LoadingStatus } from '../types/loading-types.js';
-import type {
- MediaLibrarySelection,
- NativeMediaSelection,
-} from '../types/media-types.js';
+import type { NativeMediaSelection } from '../types/media-types.js';
import {
useDispatchActionPromise,
useServerCall,
@@ -35,7 +32,6 @@
export type EditUserAvatarContextType = {
+userAvatarSaveInProgress: boolean,
- +selectFromGalleryAndUpdateUserAvatar: () => Promise<void>,
+updateImageUserAvatar: (selection: NativeMediaSelection) => Promise<void>,
+setUserAvatar: (avatarRequest: UpdateUserAvatarRequest) => Promise<void>,
+setRegistrationMode: (registrationMode: RegistrationMode) => void,
@@ -51,19 +47,13 @@
type Props = {
+displayFailureAlert?: () => mixed,
- +selectFromGallery: () => Promise<?MediaLibrarySelection>,
+useUploadSelectedMedia: (
setProcessingOrUploadInProgress?: (inProgress: boolean) => mixed,
) => (selection: NativeMediaSelection) => Promise<?ImageAvatarDBContent>,
+children: React.Node,
};
function BaseEditUserAvatarProvider(props: Props): React.Node {
- const {
- displayFailureAlert,
- selectFromGallery,
- useUploadSelectedMedia,
- children,
- } = props;
+ const { displayFailureAlert, useUploadSelectedMedia, children } = props;
const registrationModeRef =
React.useRef<RegistrationMode>(registrationModeOff);
@@ -121,14 +111,6 @@
],
);
- const selectFromGalleryAndUpdateUserAvatar = React.useCallback(async () => {
- const selection = await selectFromGallery();
- if (!selection) {
- return;
- }
- await updateImageUserAvatar(selection);
- }, [selectFromGallery, updateImageUserAvatar]);
-
const setUserAvatar = React.useCallback(
async (request: UpdateUserAvatarRequest) => {
const regMode = registrationModeRef.current;
@@ -165,7 +147,6 @@
const context = React.useMemo(
() => ({
userAvatarSaveInProgress,
- selectFromGalleryAndUpdateUserAvatar,
updateImageUserAvatar,
setUserAvatar,
setRegistrationMode,
@@ -173,7 +154,6 @@
}),
[
userAvatarSaveInProgress,
- selectFromGalleryAndUpdateUserAvatar,
updateImageUserAvatar,
setUserAvatar,
setRegistrationMode,
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
@@ -2,6 +2,7 @@
import { useActionSheet } from '@expo/react-native-action-sheet';
import * as ImagePicker from 'expo-image-picker';
+import invariant from 'invariant';
import * as React from 'react';
import { Platform } from 'react-native';
import Alert from 'react-native/Libraries/Alert/Alert.js';
@@ -9,6 +10,7 @@
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { uploadMultimedia } from 'lib/actions/upload-actions.js';
+import { EditUserAvatarContext } from 'lib/components/base-edit-user-avatar-provider.react.js';
import {
extensionFromFilename,
filenameFromPathOrURI,
@@ -181,6 +183,23 @@
);
}
+function useSelectFromGalleryAndUpdateUserAvatar(): () => Promise<void> {
+ const editUserAvatarContext = React.useContext(EditUserAvatarContext);
+ invariant(editUserAvatarContext, 'updateImageUserAvatar must be defined');
+ const { updateImageUserAvatar } = editUserAvatarContext;
+
+ const selectFromGalleryAndUpdateUserAvatar =
+ React.useCallback(async (): Promise<void> => {
+ const selection = await selectFromGallery();
+ if (!selection) {
+ return;
+ }
+ await updateImageUserAvatar(selection);
+ }, [updateImageUserAvatar]);
+
+ return selectFromGalleryAndUpdateUserAvatar;
+}
+
type ShowAvatarActionSheetOptions = {
+id: 'emoji' | 'image' | 'camera' | 'ens' | 'cancel' | 'remove',
+onPress?: () => mixed,
@@ -310,4 +329,5 @@
useUploadProcessedMedia,
useProcessSelectedMedia,
useShowAvatarActionSheet,
+ useSelectFromGalleryAndUpdateUserAvatar,
};
diff --git a/native/avatars/edit-user-avatar.react.js b/native/avatars/edit-user-avatar.react.js
--- a/native/avatars/edit-user-avatar.react.js
+++ b/native/avatars/edit-user-avatar.react.js
@@ -10,7 +10,10 @@
import { getETHAddressForUserInfo } from 'lib/shared/account-utils.js';
import type { GenericUserInfoWithAvatar } from 'lib/types/avatar-types.js';
-import { useShowAvatarActionSheet } from './avatar-hooks.js';
+import {
+ useSelectFromGalleryAndUpdateUserAvatar,
+ useShowAvatarActionSheet,
+} from './avatar-hooks.js';
import EditAvatarBadge from './edit-avatar-badge.react.js';
import UserAvatar from './user-avatar.react.js';
import {
@@ -34,11 +37,13 @@
invariant(editUserAvatarContext, 'editUserAvatarContext should be set');
const {
userAvatarSaveInProgress,
- selectFromGalleryAndUpdateUserAvatar,
setUserAvatar,
getRegistrationModeEnabled,
} = editUserAvatarContext;
+ const selectFromGalleryAndUpdateUserAvatar =
+ useSelectFromGalleryAndUpdateUserAvatar();
+
const currentUserInfo = useSelector(state => state.currentUserInfo);
const userInfoProp = props.userInfo;
const userInfo: ?GenericUserInfoWithAvatar = userInfoProp ?? currentUserInfo;
diff --git a/native/avatars/native-edit-user-avatar-provider.react.js b/native/avatars/native-edit-user-avatar-provider.react.js
--- a/native/avatars/native-edit-user-avatar-provider.react.js
+++ b/native/avatars/native-edit-user-avatar-provider.react.js
@@ -5,7 +5,7 @@
import { BaseEditUserAvatarProvider } from 'lib/components/base-edit-user-avatar-provider.react.js';
-import { selectFromGallery, useUploadSelectedMedia } from './avatar-hooks.js';
+import { useUploadSelectedMedia } from './avatar-hooks.js';
const displayAvatarUpdateFailureAlert = () =>
Alert.alert(
@@ -23,7 +23,6 @@
return (
<BaseEditUserAvatarProvider
displayFailureAlert={displayAvatarUpdateFailureAlert}
- selectFromGallery={selectFromGallery}
useUploadSelectedMedia={useUploadSelectedMedia}
>
{children}
diff --git a/web/avatars/web-edit-user-avatar-provider.react.js b/web/avatars/web-edit-user-avatar-provider.react.js
--- a/web/avatars/web-edit-user-avatar-provider.react.js
+++ b/web/avatars/web-edit-user-avatar-provider.react.js
@@ -4,9 +4,6 @@
import { BaseEditUserAvatarProvider } from 'lib/components/base-edit-user-avatar-provider.react.js';
-// TODO: Implement `selectFromGallery(...)` for `web`.
-const selectFromGallery = async () => null;
-
// TODO: Implement `useUploadSelectedMedia(...)` for `web`.
const useUploadSelectedMedia = () => async () => null;
@@ -16,10 +13,7 @@
function WebEditUserAvatarProvider(props: Props): React.Node {
const { children } = props;
return (
- <BaseEditUserAvatarProvider
- selectFromGallery={selectFromGallery}
- useUploadSelectedMedia={useUploadSelectedMedia}
- >
+ <BaseEditUserAvatarProvider useUploadSelectedMedia={useUploadSelectedMedia}>
{children}
</BaseEditUserAvatarProvider>
);

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 3, 12:12 AM (21 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2609394
Default Alt Text
D8318.diff (7 KB)

Event Timeline