Skip to content

Commit

Permalink
Merge pull request #40090 from kubabutkiewicz/ts-migration/ProfileAva…
Browse files Browse the repository at this point in the history
…tarWithIndicator

[TS migration] Migrate ProfileAvatarWithIndicator.js component to TypeScript
  • Loading branch information
roryabraham authored Apr 12, 2024
2 parents 44de443 + b9e32ab commit 159bb6d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 65 deletions.
4 changes: 2 additions & 2 deletions __mocks__/react-native-onyx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/* eslint-disable rulesdir/prefer-onyx-connect-in-libs */
import type {ConnectOptions, OnyxKey} from 'react-native-onyx';
import Onyx, {withOnyx} from 'react-native-onyx';
import Onyx, {useOnyx, withOnyx} from 'react-native-onyx';

let connectCallbackDelay = 0;
function addDelayToConnectCallback(delay: number) {
Expand Down Expand Up @@ -40,4 +40,4 @@ const reactNativeOnyxMock: ReactNativeOnyxMock = {
};

export default reactNativeOnyxMock;
export {withOnyx};
export {withOnyx, useOnyx};
63 changes: 0 additions & 63 deletions src/pages/home/sidebar/ProfileAvatarWithIndicator.js

This file was deleted.

37 changes: 37 additions & 0 deletions src/pages/home/sidebar/ProfileAvatarWithIndicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import AvatarWithIndicator from '@components/AvatarWithIndicator';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useThemeStyles from '@hooks/useThemeStyles';
import * as UserUtils from '@libs/UserUtils';
import ONYXKEYS from '@src/ONYXKEYS';

type ProfileAvatarWithIndicatorProps = {
/** Whether the avatar is selected */
isSelected?: boolean;
};

function ProfileAvatarWithIndicator({isSelected = false}: ProfileAvatarWithIndicatorProps) {
const styles = useThemeStyles();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const [isLoadingOnyxValue] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const isLoading = isLoadingOnyxValue ?? true;

return (
<OfflineWithFeedback pendingAction={currentUserPersonalDetails.pendingFields?.avatar}>
<View style={[isSelected && styles.selectedAvatarBorder]}>
<AvatarWithIndicator
source={UserUtils.getAvatar(currentUserPersonalDetails.avatar, currentUserPersonalDetails.accountID)}
fallbackIcon={currentUserPersonalDetails.fallbackIcon}
isLoading={isLoading && !currentUserPersonalDetails.avatar}
/>
</View>
</OfflineWithFeedback>
);
}

ProfileAvatarWithIndicator.displayName = 'ProfileAvatarWithIndicator';

export default ProfileAvatarWithIndicator;

0 comments on commit 159bb6d

Please sign in to comment.