Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information