Page MenuHomePhabricator

D7427.diff
No OneTemporary

D7427.diff

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
@@ -3,6 +3,10 @@
import * as React from 'react';
import { Alert } from 'react-native';
+import {
+ changeThreadSettings,
+ changeThreadSettingsActionTypes,
+} from 'lib/actions/thread-actions.js';
import {
updateUserAvatar,
updateUserAvatarActionTypes,
@@ -56,4 +60,45 @@
);
}
-export { useShouldRenderAvatars, useSaveUserAvatar };
+function useSaveThreadAvatar(): (
+ newEmojiAvatarRequest: ClientEmojiAvatar,
+ threadID: string,
+) => mixed {
+ const callChangeThreadSettings = useServerCall(changeThreadSettings);
+ const dispatchActionPromise = useDispatchActionPromise();
+
+ return React.useCallback(
+ (newEmojiAvatarRequest, threadID) => {
+ const saveAvatarPromise = (async () => {
+ try {
+ const response = await callChangeThreadSettings({
+ threadID,
+ changes: { avatar: newEmojiAvatarRequest },
+ });
+ displayActionResultModal('Avatar updated!');
+
+ return response;
+ } catch (e) {
+ Alert.alert(
+ 'Couldn’t save avatar',
+ 'Please try again later',
+ [{ text: 'OK' }],
+ {
+ cancelable: true,
+ },
+ );
+ throw e;
+ }
+ })();
+
+ dispatchActionPromise(
+ changeThreadSettingsActionTypes,
+ saveAvatarPromise,
+ { customKeyName: `${changeThreadSettingsActionTypes.started}:avatar` },
+ );
+ },
+ [callChangeThreadSettings, dispatchActionPromise],
+ );
+}
+
+export { useShouldRenderAvatars, useSaveUserAvatar, useSaveThreadAvatar };

File Metadata

Mime Type
text/plain
Expires
Thu, Jan 9, 11:20 AM (9 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2833935
Default Alt Text
D7427.diff (1 KB)

Event Timeline