Page MenuHomePhabricator

D7628.id25798.diff
No OneTemporary

D7628.id25798.diff

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
@@ -128,7 +128,7 @@
function useUploadSelectedMedia(
setProcessingOrUploadInProgress: SetState<boolean>,
-): (selection: ?NativeMediaSelection) => Promise<?string> {
+): (selection: ?NativeMediaSelection) => Promise<?ImageAvatarDBContent> {
const processSelectedMedia = useProcessSelectedMedia();
const uploadProcessedMedia = useUploadProcessedMedia();
@@ -177,7 +177,14 @@
return undefined;
}
- return uploadedMedia.id;
+ if (!uploadedMedia.id) {
+ return undefined;
+ }
+
+ return {
+ type: 'image',
+ uploadID: uploadedMedia.id,
+ };
},
[
processSelectedMedia,
@@ -218,17 +225,12 @@
const selectFromGalleryAndUpdateThreadAvatar = React.useCallback(async () => {
const selection: ?MediaLibrarySelection = await selectFromGallery();
- const uploadedMediaID = await uploadSelectedMedia(selection);
+ const imageAvatarUpdateRequest = await uploadSelectedMedia(selection);
- if (!uploadedMediaID) {
+ if (!imageAvatarUpdateRequest) {
return;
}
- const imageAvatarUpdateRequest: ImageAvatarDBContent = {
- type: 'image',
- uploadID: uploadedMediaID,
- };
-
const updateThreadRequest: UpdateThreadRequest = {
threadID,
changes: {
diff --git a/native/avatars/edit-user-avatar-provider.react.js b/native/avatars/edit-user-avatar-provider.react.js
--- a/native/avatars/edit-user-avatar-provider.react.js
+++ b/native/avatars/edit-user-avatar-provider.react.js
@@ -9,7 +9,6 @@
} from 'lib/actions/user-actions.js';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js';
import type {
- ImageAvatarDBContent,
ENSAvatarDBContent,
UpdateUserAvatarRemoveRequest,
} from 'lib/types/avatar-types.js';
@@ -60,36 +59,41 @@
const uploadUserAvatarSelectedMedia = useUploadSelectedMedia(
setUserAvatarMediaUploadInProgress,
);
- const selectFromGalleryAndUpdateUserAvatar = React.useCallback(async () => {
- const selection: ?MediaLibrarySelection = await selectFromGallery();
- const uploadedMediaID = await uploadUserAvatarSelectedMedia(selection);
-
- if (!uploadedMediaID) {
- return;
- }
- const imageAvatarUpdateRequest: ImageAvatarDBContent = {
- type: 'image',
- uploadID: uploadedMediaID,
- };
+ const updateImageUserAvatar = React.useCallback(
+ async (selection: ?MediaLibrarySelection) => {
+ const imageAvatarUpdateRequest = await uploadUserAvatarSelectedMedia(
+ selection,
+ );
+
+ if (!imageAvatarUpdateRequest) {
+ return;
+ }
+
+ dispatchActionPromise(
+ updateUserAvatarActionTypes,
+ (async () => {
+ setUserAvatarMediaUploadInProgress(false);
+ try {
+ return await updateUserAvatarCall(imageAvatarUpdateRequest);
+ } catch (e) {
+ Alert.alert('Avatar update failed', 'Unable to update avatar.');
+ throw e;
+ }
+ })(),
+ );
+ },
+ [
+ dispatchActionPromise,
+ updateUserAvatarCall,
+ uploadUserAvatarSelectedMedia,
+ ],
+ );
- dispatchActionPromise(
- updateUserAvatarActionTypes,
- (async () => {
- setUserAvatarMediaUploadInProgress(false);
- try {
- return await updateUserAvatarCall(imageAvatarUpdateRequest);
- } catch (e) {
- Alert.alert('Avatar update failed', 'Unable to update avatar.');
- throw e;
- }
- })(),
- );
- }, [
- dispatchActionPromise,
- updateUserAvatarCall,
- uploadUserAvatarSelectedMedia,
- ]);
+ const selectFromGalleryAndUpdateUserAvatar = React.useCallback(async () => {
+ const selection = await selectFromGallery();
+ await updateImageUserAvatar(selection);
+ }, [updateImageUserAvatar]);
const setENSUserAvatar = React.useCallback(() => {
const ensAvatarRequest: ENSAvatarDBContent = {

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 15, 5:29 PM (21 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2494922
Default Alt Text
D7628.id25798.diff (3 KB)

Event Timeline