Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3719319
D7427.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D7427.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D7427: [native] introduce useSaveThreadAvatar hook
Attached
Detach File
Event Timeline
Log In to Comment