2020-10-30 17:35:07 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { StyleSheet, Text, View } from 'react-native';
|
2021-01-14 17:06:19 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
2020-10-30 17:35:07 +00:00
|
|
|
|
2022-01-17 20:15:58 +00:00
|
|
|
import { useTheme } from '../../theme';
|
2020-10-30 17:35:07 +00:00
|
|
|
import Avatar from '../../containers/Avatar';
|
|
|
|
import sharedStyles from '../Styles';
|
|
|
|
import { themes } from '../../constants/colors';
|
2022-02-17 15:27:01 +00:00
|
|
|
import { MarkdownPreview } from '../../containers/markdown';
|
2020-10-30 17:35:07 +00:00
|
|
|
import { formatDateThreads, makeThreadName } from '../../utils/room';
|
2021-01-14 17:06:19 +00:00
|
|
|
import ThreadDetails from '../../containers/ThreadDetails';
|
2022-01-12 13:53:06 +00:00
|
|
|
import { TThreadModel } from '../../definitions/IThread';
|
2020-10-30 17:35:07 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
padding: 16
|
|
|
|
},
|
|
|
|
contentContainer: {
|
|
|
|
flexDirection: 'column',
|
|
|
|
flex: 1
|
|
|
|
},
|
|
|
|
titleContainer: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
marginBottom: 2,
|
|
|
|
alignItems: 'center'
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
flexShrink: 1,
|
|
|
|
fontSize: 18,
|
|
|
|
...sharedStyles.textMedium
|
|
|
|
},
|
|
|
|
time: {
|
|
|
|
fontSize: 14,
|
|
|
|
marginLeft: 4,
|
|
|
|
...sharedStyles.textRegular
|
|
|
|
},
|
|
|
|
avatar: {
|
|
|
|
marginRight: 8
|
|
|
|
},
|
2021-01-14 17:06:19 +00:00
|
|
|
threadDetails: {
|
|
|
|
marginTop: 8
|
2020-10-30 17:35:07 +00:00
|
|
|
},
|
2021-01-14 17:06:19 +00:00
|
|
|
badge: {
|
|
|
|
width: 8,
|
|
|
|
height: 8,
|
|
|
|
borderRadius: 4,
|
|
|
|
marginHorizontal: 8,
|
|
|
|
alignSelf: 'center'
|
2020-10-30 17:35:07 +00:00
|
|
|
},
|
2021-01-14 17:06:19 +00:00
|
|
|
messageContainer: {
|
|
|
|
flexDirection: 'row'
|
2020-10-30 17:35:07 +00:00
|
|
|
},
|
2021-01-14 17:06:19 +00:00
|
|
|
markdown: {
|
|
|
|
flex: 1
|
2020-10-30 17:35:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-12 13:53:06 +00:00
|
|
|
interface IItem {
|
|
|
|
item: TThreadModel;
|
|
|
|
useRealName: boolean;
|
|
|
|
user: any;
|
2022-01-17 16:10:39 +00:00
|
|
|
badgeColor?: string;
|
2022-01-12 13:53:06 +00:00
|
|
|
onPress: (item: TThreadModel) => void;
|
|
|
|
toggleFollowThread: (isFollowing: boolean, id: string) => void;
|
|
|
|
}
|
|
|
|
|
2022-02-17 15:27:01 +00:00
|
|
|
const Item = ({ item, useRealName, user, badgeColor, onPress, toggleFollowThread }: IItem) => {
|
2022-01-17 14:12:19 +00:00
|
|
|
const { theme } = useTheme();
|
2020-10-30 17:35:07 +00:00
|
|
|
const username = (useRealName && item?.u?.name) || item?.u?.username;
|
2022-01-17 20:15:58 +00:00
|
|
|
let time;
|
|
|
|
if (item?.ts) {
|
|
|
|
time = formatDateThreads(item.ts);
|
|
|
|
}
|
2020-10-30 17:35:07 +00:00
|
|
|
|
|
|
|
return (
|
2021-09-13 20:41:05 +00:00
|
|
|
<Touchable
|
|
|
|
onPress={() => onPress(item)}
|
|
|
|
testID={`thread-messages-view-${item.msg}`}
|
2022-03-22 14:16:41 +00:00
|
|
|
style={{ backgroundColor: themes[theme].backgroundColor }}>
|
2020-10-30 17:35:07 +00:00
|
|
|
<View style={styles.container}>
|
2022-01-12 13:53:06 +00:00
|
|
|
<Avatar style={styles.avatar} text={item?.u?.username} size={36} borderRadius={4} theme={theme} />
|
2020-10-30 17:35:07 +00:00
|
|
|
<View style={styles.contentContainer}>
|
|
|
|
<View style={styles.titleContainer}>
|
2022-03-22 14:16:41 +00:00
|
|
|
<Text style={[styles.title, { color: themes[theme].titleText }]} numberOfLines={1}>
|
2021-09-13 20:41:05 +00:00
|
|
|
{username}
|
|
|
|
</Text>
|
2022-03-22 14:16:41 +00:00
|
|
|
<Text style={[styles.time, { color: themes[theme].auxiliaryText }]}>{time}</Text>
|
2020-10-30 17:35:07 +00:00
|
|
|
</View>
|
2021-01-14 17:06:19 +00:00
|
|
|
<View style={styles.messageContainer}>
|
2022-02-17 15:27:01 +00:00
|
|
|
<MarkdownPreview msg={makeThreadName(item)} numberOfLines={2} style={[styles.markdown]} />
|
2021-09-13 20:41:05 +00:00
|
|
|
{badgeColor ? <View style={[styles.badge, { backgroundColor: badgeColor }]} /> : null}
|
2020-10-30 17:35:07 +00:00
|
|
|
</View>
|
2021-09-13 20:41:05 +00:00
|
|
|
<ThreadDetails item={item} user={user} toggleFollowThread={toggleFollowThread} style={styles.threadDetails} />
|
2020-10-30 17:35:07 +00:00
|
|
|
</View>
|
|
|
|
</View>
|
2021-01-14 17:06:19 +00:00
|
|
|
</Touchable>
|
2020-10-30 17:35:07 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-01-17 20:15:58 +00:00
|
|
|
export default Item;
|