Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3408302
D8018.id27281.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
D8018.id27281.diff
View Options
diff --git a/native/profile/emoji-user-avatar-creation.react.js b/native/profile/emoji-user-avatar-creation.react.js
--- a/native/profile/emoji-user-avatar-creation.react.js
+++ b/native/profile/emoji-user-avatar-creation.react.js
@@ -1,30 +1,33 @@
// @flow
+import invariant from 'invariant';
import * as React from 'react';
-import { updateUserAvatarActionTypes } from 'lib/actions/user-actions.js';
-import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js';
import { savedEmojiAvatarSelectorForCurrentUser } from 'lib/selectors/user-selectors.js';
+import { EditUserAvatarContext } from '../avatars/edit-user-avatar-provider.react.js';
import EmojiAvatarCreation from '../avatars/emoji-avatar-creation.react.js';
-import { useSelector } from '../redux/redux-utils.js';
-import { useSaveUserAvatar } from '../utils/avatar-utils.js';
-
-const userAvatarLoadingStatusSelector = createLoadingStatusSelector(
- updateUserAvatarActionTypes,
-);
+import { displayActionResultModal } from '../navigation/action-result-modal.js';
// eslint-disable-next-line no-unused-vars
function EmojiUserAvatarCreation(props: { ... }): React.Node {
- const saveUserAvatar = useSaveUserAvatar();
- const saveUserAvatarCallLoading = useSelector(
- state => userAvatarLoadingStatusSelector(state) === 'loading',
+ const editUserAvatarContext = React.useContext(EditUserAvatarContext);
+ invariant(editUserAvatarContext, 'editUserAvatarContext should be set');
+
+ const { setUserAvatar, userAvatarSaveInProgress } = editUserAvatarContext;
+ const setAvatar = React.useCallback(
+ async avatarRequest => {
+ const result = await setUserAvatar(avatarRequest);
+ displayActionResultModal('Avatar updated!');
+ return result;
+ },
+ [setUserAvatar],
);
return (
<EmojiAvatarCreation
- saveAvatarCall={saveUserAvatar}
- saveAvatarCallLoading={saveUserAvatarCallLoading}
+ saveAvatarCall={setAvatar}
+ saveAvatarCallLoading={userAvatarSaveInProgress}
savedEmojiAvatarSelector={savedEmojiAvatarSelectorForCurrentUser}
/>
);
diff --git a/native/utils/avatar-utils.js b/native/utils/avatar-utils.js
--- a/native/utils/avatar-utils.js
+++ b/native/utils/avatar-utils.js
@@ -7,10 +7,6 @@
changeThreadSettings,
changeThreadSettingsActionTypes,
} from 'lib/actions/thread-actions.js';
-import {
- updateUserAvatar,
- updateUserAvatarActionTypes,
-} from 'lib/actions/user-actions.js';
import type { UpdateUserAvatarRequest } from 'lib/types/avatar-types.js';
import {
useServerCall,
@@ -23,39 +19,6 @@
return true;
}
-function useSaveUserAvatar(): (
- newAvatarRequest: UpdateUserAvatarRequest,
-) => mixed {
- const callUpdateUserAvatar = useServerCall(updateUserAvatar);
- const dispatchActionPromise = useDispatchActionPromise();
-
- return React.useCallback(
- newAvatarRequest => {
- const saveAvatarPromise = (async () => {
- try {
- const response = await callUpdateUserAvatar(newAvatarRequest);
- displayActionResultModal('Avatar updated!');
-
- return response;
- } catch (e) {
- Alert.alert(
- 'Couldn’t save avatar',
- 'Please try again later',
- [{ text: 'OK' }],
- {
- cancelable: true,
- },
- );
- throw e;
- }
- })();
-
- dispatchActionPromise(updateUserAvatarActionTypes, saveAvatarPromise);
- },
- [callUpdateUserAvatar, dispatchActionPromise],
- );
-}
-
function useSaveThreadAvatar(): (
newAvatarRequest: UpdateUserAvatarRequest,
threadID: string,
@@ -97,4 +60,4 @@
);
}
-export { useShouldRenderAvatars, useSaveUserAvatar, useSaveThreadAvatar };
+export { useShouldRenderAvatars, useSaveThreadAvatar };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 5, 10:50 AM (16 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2615200
Default Alt Text
D8018.id27281.diff (3 KB)
Attached To
Mode
D8018: [native] Replace generic useSaveUserAvatar with new generic setUserAvatar
Attached
Detach File
Event Timeline
Log In to Comment