2021-01-14 17:06:19 +00:00
|
|
|
import React from 'react';
|
2022-01-14 17:38:08 +00:00
|
|
|
import { StyleSheet, Text, View, ViewStyle } from 'react-native';
|
2021-01-14 17:06:19 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
|
|
|
|
|
|
|
import { CustomIcon } from '../lib/Icons';
|
|
|
|
import { themes } from '../constants/colors';
|
|
|
|
import sharedStyles from '../views/Styles';
|
2022-01-14 17:38:08 +00:00
|
|
|
import { useTheme } from '../theme';
|
2022-01-17 16:10:39 +00:00
|
|
|
import { TThreadModel } from '../definitions/IThread';
|
2021-01-14 17:06:19 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center'
|
|
|
|
},
|
|
|
|
detailsContainer: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row'
|
|
|
|
},
|
|
|
|
detailContainer: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
marginRight: 8
|
|
|
|
},
|
|
|
|
detailText: {
|
|
|
|
fontSize: 10,
|
|
|
|
marginLeft: 2,
|
|
|
|
...sharedStyles.textSemibold
|
|
|
|
},
|
|
|
|
badgeContainer: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center'
|
|
|
|
},
|
|
|
|
badge: {
|
|
|
|
width: 8,
|
|
|
|
height: 8,
|
|
|
|
borderRadius: 4,
|
|
|
|
marginRight: 8
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IThreadDetails {
|
2022-03-22 14:16:41 +00:00
|
|
|
item: Pick<TThreadModel, 'tcount' | 'replies' | 'id'>;
|
2021-09-13 20:41:05 +00:00
|
|
|
user: {
|
|
|
|
id: string;
|
|
|
|
};
|
2022-01-17 14:18:32 +00:00
|
|
|
badgeColor?: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
toggleFollowThread: Function;
|
2022-01-14 17:38:08 +00:00
|
|
|
style: ViewStyle;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
2022-01-17 14:18:32 +00:00
|
|
|
const ThreadDetails = ({ item, user, badgeColor, toggleFollowThread, style }: IThreadDetails): JSX.Element => {
|
2022-01-14 17:38:08 +00:00
|
|
|
const { theme } = useTheme();
|
2022-03-02 14:18:01 +00:00
|
|
|
let count: string | number | undefined = item.tcount;
|
|
|
|
if (count && count >= 1000) {
|
|
|
|
count = '+999';
|
2021-01-14 17:06:19 +00:00
|
|
|
}
|
|
|
|
|
2022-01-17 16:10:39 +00:00
|
|
|
let replies: number | string = item?.replies?.length ?? 0;
|
2021-01-14 17:06:19 +00:00
|
|
|
if (replies >= 1000) {
|
|
|
|
replies = '+999';
|
|
|
|
}
|
|
|
|
|
2022-03-22 14:16:41 +00:00
|
|
|
const isFollowing = item.replies?.find((u: string) => u === user?.id);
|
2021-01-14 17:06:19 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={[styles.container, style]}>
|
|
|
|
<View style={styles.detailsContainer}>
|
|
|
|
<View style={styles.detailContainer}>
|
2022-03-22 14:16:41 +00:00
|
|
|
<CustomIcon name='threads' size={24} color={themes[theme].auxiliaryText} />
|
|
|
|
<Text style={[styles.detailText, { color: themes[theme].auxiliaryText }]} numberOfLines={1}>
|
2022-03-02 14:18:01 +00:00
|
|
|
{count}
|
2021-09-13 20:41:05 +00:00
|
|
|
</Text>
|
2021-01-14 17:06:19 +00:00
|
|
|
</View>
|
|
|
|
|
2021-09-17 20:22:02 +00:00
|
|
|
<View style={styles.detailContainer}>
|
2022-03-22 14:16:41 +00:00
|
|
|
<CustomIcon name='user' size={24} color={themes[theme].auxiliaryText} />
|
|
|
|
<Text style={[styles.detailText, { color: themes[theme].auxiliaryText }]} numberOfLines={1}>
|
2022-01-14 17:38:08 +00:00
|
|
|
{replies}
|
2021-09-17 20:22:02 +00:00
|
|
|
</Text>
|
|
|
|
</View>
|
2021-01-14 17:06:19 +00:00
|
|
|
</View>
|
2022-01-14 17:38:08 +00:00
|
|
|
<View style={styles.badgeContainer}>
|
|
|
|
{badgeColor ? <View style={[styles.badge, { backgroundColor: badgeColor }]} /> : null}
|
|
|
|
<Touchable onPress={() => toggleFollowThread?.(isFollowing, item.id)}>
|
|
|
|
<CustomIcon
|
|
|
|
size={24}
|
|
|
|
name={isFollowing ? 'notification' : 'notification-disabled'}
|
2022-03-22 14:16:41 +00:00
|
|
|
color={themes[theme].auxiliaryTintColor}
|
2022-01-14 17:38:08 +00:00
|
|
|
/>
|
|
|
|
</Touchable>
|
|
|
|
</View>
|
2021-01-14 17:06:19 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-01-14 17:38:08 +00:00
|
|
|
export default ThreadDetails;
|