Page MenuHomePhabricator

[native] Introduce `useNativeUpdateUserImageAvatar()` to `avatar-hooks.react`
ClosedPublic

Authored by atul on Jun 27 2023, 11:55 AM.
Tags
None
Referenced Files
F2141366: D8339.id.diff
Sat, Jun 29, 11:22 AM
Unknown Object (File)
Wed, Jun 26, 4:17 PM
Unknown Object (File)
Mon, Jun 24, 2:48 PM
Unknown Object (File)
Sun, Jun 16, 6:44 PM
Unknown Object (File)
Sat, Jun 15, 11:00 AM
Unknown Object (File)
Fri, Jun 14, 2:48 PM
Unknown Object (File)
Thu, Jun 13, 11:40 PM
Unknown Object (File)
Tue, Jun 11, 10:54 PM
Subscribers

Details

Summary

The updateImageUserAvatar function within *EditUserAvatarProvider previously contained a call to the displayFailureAlert(...) function, which was passed in via props. However, the displayFailureAlert function is only relevant on native as we surface errors differently on web.

As part of making EditUserAvatarProvider platform-agnostic, we introduce the useNativeUpdateUserImageAvatar() hook. The function it "creates" encapsulates its call to updateImageUserAvatar in a try/catch block that handles errors in a native-specific way. As a result, updateImageUserAvatar can throw a plain old exception that will be caught by platform-specific "wrapper" functions.

In subsequent diffs we'll do the same thing for setUserAvatar so we can completely remove the displayFailureAlert prop from *EditUserAvatarProvider. After that we'll work on removing the useUploadSelectedMedia prop so the provider is fully "platform-agnostic." At that point we'll be able to consolidate BaseEditUserAvatarProvider, NativeEditUserAvatarProvider, and WebEditUserAvatarProvider into a single EditUserAvatarProvider component.

Test Plan
  1. Modify update_user_avatar endpoint to throw ServerError (we can't just kill keyserver because we want to make sure the alert is triggered by the update_user_avatar-specific codepath which we modified).
  2. Try to set a user image avatar via "Camera" flow
  3. Ensure that I see expected Alert.

Also, make sure the "happy case" (unmodified update_user_avatar endpoint) continues working as expected).

WARNING: I haven't actually gone through the Test Plan yet, will sequence at the end of all of the refactors and definitely before landing.

9e3b9c.png (358×640 px, 132 KB)

cc01c7.png (64×820 px, 13 KB)

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

atul published this revision for review.Jun 27 2023, 12:00 PM
This revision is now accepted and ready to land.Jun 28 2023, 5:56 PM
This revision was landed with ongoing or failed builds.Jul 28 2023, 12:32 PM
This revision was automatically updated to reflect the committed changes.