2022-01-14 17:38:08 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { StyleSheet, Text, View } from 'react-native';
|
|
|
|
import Touchable from 'react-native-platform-touchable';
|
2022-01-17 19:55:33 +00:00
|
|
|
import moment from 'moment';
|
2022-01-14 17:38:08 +00:00
|
|
|
|
|
|
|
import { useTheme } from '../../theme';
|
|
|
|
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';
|
2022-01-14 17:38:08 +00:00
|
|
|
import { formatDateThreads, makeThreadName } from '../../utils/room';
|
|
|
|
import DiscussionDetails from './DiscussionDetails';
|
2022-01-17 14:18:32 +00:00
|
|
|
import { TThreadModel } from '../../definitions/IThread';
|
2022-01-14 17:38:08 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
padding: 16
|
|
|
|
},
|
|
|
|
contentContainer: {
|
|
|
|
flexDirection: 'column',
|
|
|
|
flex: 1
|
|
|
|
},
|
|
|
|
titleContainer: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
marginBottom: 2,
|
|
|
|
justifyContent: 'space-between'
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
flexShrink: 1,
|
|
|
|
fontSize: 18,
|
|
|
|
...sharedStyles.textMedium
|
|
|
|
},
|
|
|
|
time: {
|
|
|
|
fontSize: 14,
|
|
|
|
marginLeft: 4,
|
|
|
|
...sharedStyles.textRegular
|
|
|
|
},
|
|
|
|
avatar: {
|
|
|
|
marginRight: 8
|
|
|
|
},
|
|
|
|
messageContainer: {
|
|
|
|
flexDirection: 'row'
|
|
|
|
},
|
|
|
|
markdown: {
|
|
|
|
flex: 1
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
interface IItem {
|
2022-01-17 14:18:32 +00:00
|
|
|
item: TThreadModel;
|
2022-01-14 17:38:08 +00:00
|
|
|
onPress: {
|
|
|
|
(...args: any[]): void;
|
|
|
|
stop(): void;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-02-17 15:27:01 +00:00
|
|
|
const Item = ({ item, onPress }: IItem): JSX.Element => {
|
2022-01-14 17:38:08 +00:00
|
|
|
const { theme } = useTheme();
|
|
|
|
const username = item?.u?.username;
|
2022-01-24 17:40:39 +00:00
|
|
|
let messageTime = '';
|
|
|
|
let messageDate = '';
|
2022-01-17 20:15:58 +00:00
|
|
|
|
|
|
|
if (item?.ts) {
|
|
|
|
messageTime = moment(item.ts).format('LT');
|
|
|
|
messageDate = formatDateThreads(item.ts);
|
|
|
|
}
|
2022-01-14 17:38:08 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Touchable
|
|
|
|
onPress={() => onPress(item)}
|
|
|
|
testID={`discussions-view-${item.msg}`}
|
2022-01-24 19:12:09 +00:00
|
|
|
style={{ backgroundColor: themes[theme].backgroundColor }}>
|
2022-01-14 17:38:08 +00:00
|
|
|
<View style={styles.container}>
|
|
|
|
<Avatar style={styles.avatar} text={item?.u?.username} size={36} borderRadius={4} theme={theme} />
|
|
|
|
<View style={styles.contentContainer}>
|
|
|
|
<View style={styles.titleContainer}>
|
2022-01-24 19:12:09 +00:00
|
|
|
<Text style={[styles.title, { color: themes[theme].titleText }]} numberOfLines={1}>
|
2022-01-14 17:38:08 +00:00
|
|
|
{username}
|
|
|
|
</Text>
|
2022-01-24 19:12:09 +00:00
|
|
|
{messageTime ? <Text style={[styles.time, { color: themes[theme].auxiliaryText }]}>{messageTime}</Text> : null}
|
2022-01-14 17:38:08 +00:00
|
|
|
</View>
|
|
|
|
<View style={styles.messageContainer}>
|
2022-02-17 15:27:01 +00:00
|
|
|
{username ? <MarkdownPreview msg={makeThreadName(item)} numberOfLines={2} style={[styles.markdown]} /> : null}
|
2022-01-14 17:38:08 +00:00
|
|
|
</View>
|
2022-01-24 17:40:39 +00:00
|
|
|
{messageDate ? <DiscussionDetails item={item} date={messageDate} /> : null}
|
2022-01-14 17:38:08 +00:00
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</Touchable>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Item;
|