Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Migrate RoomHeaderAvatars component files to TypeScript #37829

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ROUTES = {
},
PROFILE_AVATAR: {
route: 'a/:accountID/avatar',
getRoute: (accountID: string) => `a/${accountID}/avatar` as const,
getRoute: (accountID: string | number) => `a/${accountID}/avatar` as const,
},

TRANSITION_BETWEEN_APPS: 'transition',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,63 +1,60 @@
import PropTypes from 'prop-types';
import React, {memo} from 'react';
import {View} from 'react-native';
import _ from 'underscore';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {Icon} from '@src/types/onyx/OnyxCommon';
import Avatar from './Avatar';
import avatarPropTypes from './avatarPropTypes';
import PressableWithoutFocus from './Pressable/PressableWithoutFocus';
import Text from './Text';

const propTypes = {
icons: PropTypes.arrayOf(avatarPropTypes),
reportID: PropTypes.string,
type RoomHeaderAvatarsProps = {
icons: Icon[];
reportID: string;
};

const defaultProps = {
icons: [],
reportID: '',
};

function RoomHeaderAvatars(props) {
const navigateToAvatarPage = (icon) => {
function RoomHeaderAvatars({icons, reportID}: RoomHeaderAvatarsProps) {
const navigateToAvatarPage = (icon: Icon) => {
if (icon.type === CONST.ICON_TYPE_WORKSPACE) {
Navigation.navigate(ROUTES.REPORT_AVATAR.getRoute(props.reportID));
Navigation.navigate(ROUTES.REPORT_AVATAR.getRoute(reportID));
return;
}
Navigation.navigate(ROUTES.PROFILE_AVATAR.getRoute(icon.id));

if (icon.id) {
Navigation.navigate(ROUTES.PROFILE_AVATAR.getRoute(icon.id));
}
};

const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
if (!props.icons.length) {

if (!icons.length) {
return null;
}

if (props.icons.length === 1) {
if (icons.length === 1) {
return (
<PressableWithoutFocus
style={[styles.noOutline]}
onPress={() => navigateToAvatarPage(props.icons[0])}
style={styles.noOutline}
onPress={() => navigateToAvatarPage(icons[0])}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON}
accessibilityLabel={props.icons[0].name}
accessibilityLabel={icons[0].name ?? ''}
>
<Avatar
source={props.icons[0].source}
imageStyles={[styles.avatarLarge]}
source={icons[0].source}
imageStyles={styles.avatarLarge}
size={CONST.AVATAR_SIZE.LARGE}
name={props.icons[0].name}
type={props.icons[0].type}
fallbackIcon={props.icons[0].fallbackIcon}
name={icons[0].name}
type={icons[0].type}
fallbackIcon={icons[0].fallbackIcon}
/>
</PressableWithoutFocus>
);
}

const iconsToDisplay = props.icons.slice(0, CONST.REPORT.MAX_PREVIEW_AVATARS);
const iconsToDisplay = icons.slice(0, CONST.REPORT.MAX_PREVIEW_AVATARS);

const iconStyle = [
styles.roomHeaderAvatar,
Expand All @@ -68,16 +65,17 @@ function RoomHeaderAvatars(props) {
return (
<View style={styles.pointerEventsBoxNone}>
<View style={[styles.flexRow, styles.wAuto, styles.ml3]}>
{_.map(iconsToDisplay, (icon, index) => (
{iconsToDisplay.map((icon, index) => (
<View
// eslint-disable-next-line react/no-array-index-key
key={`${icon.id}${index}`}
style={[styles.justifyContentCenter, styles.alignItemsCenter]}
>
<PressableWithoutFocus
style={[styles.mln4, StyleUtils.getAvatarBorderRadius(CONST.AVATAR_SIZE.LARGE_BORDERED, icon.type)]}
onPress={() => navigateToAvatarPage(icon)}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON}
accessibilityLabel={icon.name}
accessibilityLabel={icon.name ?? ''}
>
<Avatar
source={icon.source}
Expand All @@ -88,7 +86,7 @@ function RoomHeaderAvatars(props) {
fallbackIcon={icon.fallbackIcon}
/>
</PressableWithoutFocus>
{index === CONST.REPORT.MAX_PREVIEW_AVATARS - 1 && props.icons.length - CONST.REPORT.MAX_PREVIEW_AVATARS !== 0 && (
{index === CONST.REPORT.MAX_PREVIEW_AVATARS - 1 && icons.length - CONST.REPORT.MAX_PREVIEW_AVATARS !== 0 && (
<>
<View
style={[
Expand All @@ -100,7 +98,7 @@ function RoomHeaderAvatars(props) {
styles.roomHeaderAvatarOverlay,
]}
/>
<Text style={styles.avatarInnerTextChat}>{`+${props.icons.length - CONST.REPORT.MAX_PREVIEW_AVATARS}`}</Text>
<Text style={styles.avatarInnerTextChat}>{`+${icons.length - CONST.REPORT.MAX_PREVIEW_AVATARS}`}</Text>
</>
)}
</View>
Expand All @@ -110,8 +108,6 @@ function RoomHeaderAvatars(props) {
);
}

RoomHeaderAvatars.defaultProps = defaultProps;
RoomHeaderAvatars.propTypes = propTypes;
RoomHeaderAvatars.displayName = 'RoomHeaderAvatars';

export default memo(RoomHeaderAvatars);
Loading