2022-04-07 20:25:25 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Text, View, ViewStyle } from 'react-native';
|
|
|
|
|
2022-08-17 13:32:21 +00:00
|
|
|
import Touch from '../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';
|
2023-12-18 18:22:46 +00:00
|
|
|
import { MarkdownPreview } from '../markdown';
|
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;
|
|
|
|
}
|
2024-04-18 10:19:54 +00:00
|
|
|
return <Text style={[styles.directoryItemLabel, { color: themes[theme].fontSecondaryInfo }]}>{text}</Text>;
|
2022-04-07 20:25:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const DirectoryItem = ({
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
avatar,
|
|
|
|
onPress,
|
|
|
|
testID,
|
|
|
|
style,
|
|
|
|
rightLabel,
|
|
|
|
type,
|
|
|
|
rid,
|
|
|
|
teamMain
|
|
|
|
}: IDirectoryItem): React.ReactElement => {
|
|
|
|
const { theme } = useTheme();
|
|
|
|
return (
|
2024-04-18 10:19:54 +00:00
|
|
|
<Touch onPress={onPress} style={{ backgroundColor: themes[theme].surfaceRoom }} testID={testID}>
|
2022-04-07 20:25:25 +00:00
|
|
|
<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}
|
2024-04-18 10:19:54 +00:00
|
|
|
<Text style={[styles.directoryItemName, { color: themes[theme].fontTitlesLabels }]} numberOfLines={1}>
|
2022-04-07 20:25:25 +00:00
|
|
|
{title}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
{description ? (
|
2023-12-18 18:22:46 +00:00
|
|
|
<MarkdownPreview
|
|
|
|
msg={description}
|
2024-04-18 10:19:54 +00:00
|
|
|
style={[styles.directoryItemUsername, { color: themes[theme].fontSecondaryInfo }]}
|
2023-12-18 18:22:46 +00:00
|
|
|
numberOfLines={1}
|
|
|
|
/>
|
2022-04-07 20:25:25 +00:00
|
|
|
) : null}
|
|
|
|
</View>
|
|
|
|
<DirectoryItemLabel text={rightLabel} theme={theme} />
|
|
|
|
</View>
|
|
|
|
</Touch>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DirectoryItem;
|