From 13c5d23b5537c45425e1807a8fef82cad55b623c Mon Sep 17 00:00:00 2001 From: Atul Madhugiri Date: Fri, 28 Jul 2023 12:35:56 -0700 Subject: [PATCH] [native] Consume `useNativeUpdateUserImageAvatar` in `useSelectFromGalleryAndUpdateUserAvatar` 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 --- native/avatars/avatar-hooks.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/native/avatars/avatar-hooks.js b/native/avatars/avatar-hooks.js index e6a3f3df32..9510444481 100644 --- a/native/avatars/avatar-hooks.js +++ b/native/avatars/avatar-hooks.js @@ -214,9 +214,7 @@ function useNativeUpdateUserImageAvatar(): ( } function useSelectFromGalleryAndUpdateUserAvatar(): () => Promise { - const editUserAvatarContext = React.useContext(EditUserAvatarContext); - invariant(editUserAvatarContext, 'updateImageUserAvatar must be defined'); - const { updateImageUserAvatar } = editUserAvatarContext; + const nativeUpdateUserImageAvatar = useNativeUpdateUserImageAvatar(); const selectFromGalleryAndUpdateUserAvatar = React.useCallback(async (): Promise => { @@ -224,8 +222,8 @@ function useSelectFromGalleryAndUpdateUserAvatar(): () => Promise { if (!selection) { return; } - await updateImageUserAvatar(selection); - }, [updateImageUserAvatar]); + await nativeUpdateUserImageAvatar(selection); + }, [nativeUpdateUserImageAvatar]); return selectFromGalleryAndUpdateUserAvatar; }