Page MenuHomePhabricator

D8020.id27240.diff
No OneTemporary

D8020.id27240.diff

diff --git a/native/avatars/edit-thread-avatar-provider.react.js b/native/avatars/edit-thread-avatar-provider.react.js
--- a/native/avatars/edit-thread-avatar-provider.react.js
+++ b/native/avatars/edit-thread-avatar-provider.react.js
@@ -8,13 +8,16 @@
changeThreadSettingsActionTypes,
} from 'lib/actions/thread-actions.js';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js';
-import type { UpdateUserAvatarRemoveRequest } from 'lib/types/avatar-types.js';
+import type { UpdateUserAvatarRequest } from 'lib/types/avatar-types.js';
import type { LoadingStatus } from 'lib/types/loading-types.js';
import type {
MediaLibrarySelection,
NativeMediaSelection,
} from 'lib/types/media-types.js';
-import type { UpdateThreadRequest } from 'lib/types/thread-types.js';
+import type {
+ UpdateThreadRequest,
+ ChangeThreadSettingsPayload,
+} from 'lib/types/thread-types.js';
import {
useDispatchActionPromise,
useServerCall,
@@ -32,7 +35,10 @@
selection: NativeMediaSelection,
threadID: string,
) => Promise<void>,
- +removeThreadAvatar: (threadID: string) => void,
+ +setThreadAvatar: (
+ threadID: string,
+ avatarRequest: UpdateUserAvatarRequest,
+ ) => Promise<ChangeThreadSettingsPayload>,
};
const EditThreadAvatarContext: React.Context<?EditThreadAvatarContextType> =
@@ -138,32 +144,27 @@
[updateImageThreadAvatar],
);
- const removeThreadAvatar = React.useCallback(
- (threadID: string) => {
- const removeAvatarRequest: UpdateUserAvatarRemoveRequest = {
- type: 'remove',
- };
-
+ const setThreadAvatar = React.useCallback(
+ (threadID: string, avatarRequest: UpdateUserAvatarRequest) => {
const updateThreadRequest: UpdateThreadRequest = {
threadID,
changes: {
- avatar: removeAvatarRequest,
+ avatar: avatarRequest,
},
};
-
const action = changeThreadSettingsActionTypes.started;
- dispatchActionPromise(
- changeThreadSettingsActionTypes,
- (async () => {
- try {
- return await changeThreadSettingsCall(updateThreadRequest);
- } catch (e) {
- Alert.alert('Avatar update failed', 'Unable to update avatar.');
- throw e;
- }
- })(),
- { customKeyName: `${action}:${threadID}:avatar` },
- );
+ const promise = (async () => {
+ try {
+ return await changeThreadSettingsCall(updateThreadRequest);
+ } catch (e) {
+ Alert.alert('Avatar update failed', 'Unable to update avatar.');
+ throw e;
+ }
+ })();
+ dispatchActionPromise(changeThreadSettingsActionTypes, promise, {
+ customKeyName: `${action}:${threadID}:avatar`,
+ });
+ return promise;
},
[changeThreadSettingsCall, dispatchActionPromise],
);
@@ -173,13 +174,13 @@
threadAvatarSaveInProgress,
selectFromGalleryAndUpdateThreadAvatar,
updateImageThreadAvatar,
- removeThreadAvatar,
+ setThreadAvatar,
}),
[
- removeThreadAvatar,
+ threadAvatarSaveInProgress,
selectFromGalleryAndUpdateThreadAvatar,
updateImageThreadAvatar,
- threadAvatarSaveInProgress,
+ setThreadAvatar,
],
);
diff --git a/native/avatars/edit-thread-avatar.react.js b/native/avatars/edit-thread-avatar.react.js
--- a/native/avatars/edit-thread-avatar.react.js
+++ b/native/avatars/edit-thread-avatar.react.js
@@ -30,7 +30,7 @@
const {
threadAvatarSaveInProgress,
selectFromGalleryAndUpdateThreadAvatar,
- removeThreadAvatar,
+ setThreadAvatar,
} = editThreadAvatarContext;
const { navigate } = useNavigation();
@@ -58,8 +58,8 @@
}, [navigate, threadInfo.id]);
const removeAvatar = React.useCallback(
- () => removeThreadAvatar(threadInfo.id),
- [removeThreadAvatar, threadInfo.id],
+ () => setThreadAvatar(threadInfo.id, { type: 'remove' }),
+ [setThreadAvatar, threadInfo.id],
);
const actionSheetConfig = React.useMemo(() => {

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 5, 2:12 AM (14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2615604
Default Alt Text
D8020.id27240.diff (3 KB)

Event Timeline