Skip to content

Commit

Permalink
[lib] Rename updateImageUserAvatar to baseUpdateImageUserAvatar i…
Browse files Browse the repository at this point in the history
…n `EditUserAvatarProvider`

Summary:
Effectively the same as D8344, but for `updateImageUserAvatar`.

We want devs to use the platform-specific `updateImageUserAvatar` wrappers rather than interfacing with `updateImageUserAvatar` directly... so renaming with `base` prefix to make that more clear.

Also left a comment.

---

Depends on D8348

Test Plan: flow/eslint/searched codebase for "updateImageUserAvatar".

Reviewers: ashoat, ginsu, rohan

Reviewed By: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D8360
  • Loading branch information
atulsmadhugiri committed Jul 28, 2023
1 parent 875404b commit faab4fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions lib/components/edit-user-avatar-provider.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const registrationModeOff = { registrationMode: 'off' };
export type EditUserAvatarContextType = {
+setUserAvatarMediaUploadInProgress: SetState<boolean>,
+userAvatarSaveInProgress: boolean,
+updateImageUserAvatar: (
+baseUpdateImageUserAvatar: (
imageAvatarUpdateRequest: ImageAvatarDBContent,
) => Promise<void>,
+baseSetUserAvatar: (avatarRequest: UpdateUserAvatarRequest) => Promise<void>,
Expand Down Expand Up @@ -73,7 +73,9 @@ function EditUserAvatarProvider(props: Props): React.Node {
userAvatarMediaUploadInProgress ||
updateUserAvatarLoadingStatus === 'loading';

const updateImageUserAvatar = React.useCallback(
// NOTE: Do **NOT** consume `baseUpdateImageUserAvatar` directly.
// Use platform-specific `[web/native]UpdateImageUserAvatar` instead.
const baseUpdateImageUserAvatar = React.useCallback(
async (imageAvatarUpdateRequest: ImageAvatarDBContent) => {
const promise = (async () => {
setUserAvatarMediaUploadInProgress(false);
Expand All @@ -85,7 +87,7 @@ function EditUserAvatarProvider(props: Props): React.Node {
[dispatchActionPromise, updateUserAvatarCall],
);

// NOTE: Do NOT consume `baseSetUserAvatar` directly.
// NOTE: Do **NOT** consume `baseSetUserAvatar` directly.
// Use platform-specific `[web/native]SetUserAvatar` instead.
const baseSetUserAvatar = React.useCallback(
async (request: UpdateUserAvatarRequest) => {
Expand Down Expand Up @@ -115,7 +117,7 @@ function EditUserAvatarProvider(props: Props): React.Node {
() => ({
setUserAvatarMediaUploadInProgress,
userAvatarSaveInProgress,
updateImageUserAvatar,
baseUpdateImageUserAvatar,
baseSetUserAvatar,
setRegistrationMode,
getRegistrationModeEnabled,
Expand All @@ -124,7 +126,7 @@ function EditUserAvatarProvider(props: Props): React.Node {
[
setUserAvatarMediaUploadInProgress,
userAvatarSaveInProgress,
updateImageUserAvatar,
baseUpdateImageUserAvatar,
baseSetUserAvatar,
setRegistrationMode,
getRegistrationModeEnabled,
Expand Down
6 changes: 3 additions & 3 deletions native/avatars/avatar-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function useNativeUpdateUserImageAvatar(): (
const editUserAvatarContext = React.useContext(EditUserAvatarContext);
invariant(editUserAvatarContext, 'editUserAvatarContext must be defined');
const {
updateImageUserAvatar,
baseUpdateImageUserAvatar,
getRegistrationModeEnabled,
getRegistrationModeSuccessCallback,
setUserAvatarMediaUploadInProgress,
Expand Down Expand Up @@ -276,15 +276,15 @@ function useNativeUpdateUserImageAvatar(): (
}

try {
await updateImageUserAvatar(imageAvatarUpdateRequest);
await baseUpdateImageUserAvatar(imageAvatarUpdateRequest);
} catch {
displayAvatarUpdateFailureAlert();
}
},
[
getRegistrationModeEnabled,
getRegistrationModeSuccessCallback,
updateImageUserAvatar,
baseUpdateImageUserAvatar,
uploadSelectedMedia,
],
);
Expand Down

0 comments on commit faab4fd

Please sign in to comment.