2022-04-07 20:25:25 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Text, View, ViewStyle } from 'react-native';
|
|
|
|
|
2022-06-06 14:17:51 +00:00
|
|
|
import Touch from '../../lib/methods/helpers/touch';
|
2022-04-07 20:25:25 +00:00
|
|
|
import Avatar from '../Avatar';
|
|
|
|
import RoomTypeIcon from '../RoomTypeIcon';
|
|
|
|
import styles, { ROW_HEIGHT } from './styles';
|
|
|
|
import { themes } from '../../lib/constants';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes, useTheme } from '../../theme';
|
2022-04-07 20:25:25 +00:00
|
|
|
|
|
|
|
export { ROW_HEIGHT };
|
|
|
|
|
|
|
|
interface IDirectoryItemLabel {
|
|
|
|
text?: string;
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2022-04-07 20:25:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface IDirectoryItem {
|
|
|
|
title: string;
|
2022-05-02 11:53:47 +00:00
|
|
|
description?: string;
|
|
|
|
avatar?: string;
|
2022-04-07 20:25:25 +00:00
|
|
|
type: string;
|
|
|
|
onPress(): void;
|
|
|
|
testID: string;
|
|
|
|
style?: ViewStyle;
|
|
|
|
rightLabel?: string;
|
|
|
|
rid?: string;
|
|
|
|
teamMain?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const DirectoryItemLabel = React.memo(({ text, theme }: IDirectoryItemLabel) => {
|
|
|
|
if (!text) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return <Text style={[styles.directoryItemLabel, { color: themes[theme].auxiliaryText }]}>{text}</Text>;
|
|
|
|
});
|
|
|
|
|
|
|
|
const DirectoryItem = ({
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
avatar,
|
|
|
|
onPress,
|
|
|
|
testID,
|
|
|
|
style,
|
|
|
|
rightLabel,
|
|
|
|
type,
|
|
|
|
rid,
|
|
|
|
teamMain
|
|
|
|
}: IDirectoryItem): React.ReactElement => {
|
|
|
|
const { theme } = useTheme();
|
|
|
|
return (
|
|
|
|
<Touch onPress={onPress} style={{ backgroundColor: themes[theme].backgroundColor }} testID={testID} theme={theme}>
|
|
|
|
<View style={[styles.directoryItemContainer, styles.directoryItemButton, style]}>
|
|
|
|
<Avatar text={avatar} size={30} type={type} rid={rid} style={styles.directoryItemAvatar} />
|
|
|
|
<View style={styles.directoryItemTextContainer}>
|
|
|
|
<View style={styles.directoryItemTextTitle}>
|
2022-06-21 19:44:02 +00:00
|
|
|
{type !== 'd' ? <RoomTypeIcon type={type} teamMain={teamMain} /> : null}
|
2022-04-07 20:25:25 +00:00
|
|
|
<Text style={[styles.directoryItemName, { color: themes[theme].titleText }]} numberOfLines={1}>
|
|
|
|
{title}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
{description ? (
|
|
|
|
<Text style={[styles.directoryItemUsername, { color: themes[theme].auxiliaryText }]} numberOfLines={1}>
|
|
|
|
{description}
|
|
|
|
</Text>
|
|
|
|
) : null}
|
|
|
|
</View>
|
|
|
|
<DirectoryItemLabel text={rightLabel} theme={theme} />
|
|
|
|
</View>
|
|
|
|
</Touch>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DirectoryItem;
|