HomePhabricator
Diffusion Comm fb4f1746fb42

[lib] Introduce `useNativeUpdateThreadImageAvatar` to `AvatarHooks`

Description

[lib] Introduce useNativeUpdateThreadImageAvatar to AvatarHooks

Summary:
The updateThreadImageAvatar function within EditThreadAvatarProvider 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 EditThreadAvatarProvider platform-agnostic, we introduce the useNativeUpdateThreadImageAvatar() hook. The function it "creates" encapsulates the call to updateThreadImageAvatar in a try/catch block that handles errors in a native-specific way. As a result, updateImageThreadAvatar can throw a plain old exception that will be caught by the platform-specific "wrapper" functions.

In subsequent diffs we'll do the same thing for setThreadAvatar so we can completely removed the displayFailureAlert prop from EditThreadAvatarProvider. 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 things into a single EditThreadAvatarProvider component.

NOTE: This is the "thread avatar version" of D8339.

Test Plan:

  1. Modify thread update endpoint to throw ServerError
  2. Try to set thread avatar via "Camera" flow
  3. Ensure that alert still appears as expected (via displayFailureAlert)

Reviewers: ashoat, ginsu

Reviewed By: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D8740

Details

Provenance
atulAuthored on Aug 7 2023, 11:15 PM
Reviewer
ashoat
Differential Revision
D8740: [lib] Introduce `useNativeUpdateThreadImageAvatar` to `AvatarHooks`
Parents
rCOMM5877e6575861: [native] codeVersion -> 244
Branches
Unknown
Tags
Unknown