Skip to content

Commit

Permalink
[native] Consume useNativeUpdateUserImageAvatar in `useSelectFromGa…
Browse files Browse the repository at this point in the history
…lleryAndUpdateUserAvatar`

Summary:
There is now only one usage of `updateImageUserAvatar` from `*EditUserAvatarProvider` and it's in `useNativeUpdateUserImageAvatar` where the call is wrapped in a `try/catch` with `native`-specific "error surfacing" handled in the `catch` block.

---

Depends on D8339

Test Plan:
`selectFromGalleryAndUpdateUserAvatar` is used in one place: `EditUserAvatar`. Specifically the select image from gallery flow.

Similar to D8339, will break `update_user_avatar` endpoint and ensure that alert surfaces as expected:

{F609751}

Will also test "happy case" where the `update_user_avatar` endpoint is working as expected.

Reviewers: ashoat, ginsu, rohan

Reviewed By: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D8340
  • Loading branch information
atulsmadhugiri committed Jul 28, 2023
1 parent 3e3e93c commit 13c5d23
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions native/avatars/avatar-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,16 @@ function useNativeUpdateUserImageAvatar(): (
}

function useSelectFromGalleryAndUpdateUserAvatar(): () => Promise<void> {
const editUserAvatarContext = React.useContext(EditUserAvatarContext);
invariant(editUserAvatarContext, 'updateImageUserAvatar must be defined');
const { updateImageUserAvatar } = editUserAvatarContext;
const nativeUpdateUserImageAvatar = useNativeUpdateUserImageAvatar();

const selectFromGalleryAndUpdateUserAvatar =
React.useCallback(async (): Promise<void> => {
const selection = await selectFromGallery();
if (!selection) {
return;
}
await updateImageUserAvatar(selection);
}, [updateImageUserAvatar]);
await nativeUpdateUserImageAvatar(selection);
}, [nativeUpdateUserImageAvatar]);

return selectFromGalleryAndUpdateUserAvatar;
}
Expand Down

0 comments on commit 13c5d23

Please sign in to comment.