Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3245292
D7628.id25891.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D7628.id25891.diff
View Options
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';
@@ -57,39 +56,38 @@
userAvatarMediaUploadInProgress ||
updateUserAvatarLoadingStatus === 'loading';
- const uploadUserAvatarSelectedMedia = useUploadSelectedMedia(
+ const uploadSelectedMedia = 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 uploadSelectedMedia(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, uploadSelectedMedia],
+ );
- 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
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 15, 5:42 PM (21 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2494947
Default Alt Text
D7628.id25891.diff (4 KB)
Attached To
Mode
D7628: [native] improve factoring out redundant logic for saving an image user avatar
Attached
Detach File
Event Timeline
Log In to Comment