2021-01-14 17:06:19 +00:00
|
|
|
import React from 'react';
|
2022-01-17 16:10:39 +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';
|
|
|
|
import { withTheme } 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-01-17 16:10:39 +00:00
|
|
|
item: Partial<TThreadModel>;
|
2021-09-13 20:41:05 +00:00
|
|
|
user: {
|
|
|
|
id: string;
|
|
|
|
};
|
2022-01-17 16:10:39 +00:00
|
|
|
badgeColor?: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
toggleFollowThread: Function;
|
2022-01-17 16:10:39 +00:00
|
|
|
style: ViewStyle;
|
|
|
|
theme?: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const ThreadDetails = ({ item, user, badgeColor, toggleFollowThread, style, theme }: IThreadDetails) => {
|
2021-01-14 17:06:19 +00:00
|
|
|
let { tcount } = item;
|
2022-01-17 16:10:39 +00:00
|
|
|
if (tcount! >= 1000) {
|
2021-01-14 17:06:19 +00:00
|
|
|
tcount = '+999';
|
|
|
|
}
|
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const isFollowing = item.replies?.find((u: any) => 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-01-17 16:10:39 +00:00
|
|
|
<CustomIcon name='threads' size={24} color={themes[theme!].auxiliaryText} />
|
|
|
|
<Text style={[styles.detailText, { color: themes[theme!].auxiliaryText }]} numberOfLines={1}>
|
2021-09-13 20:41:05 +00:00
|
|
|
{tcount}
|
|
|
|
</Text>
|
2021-01-14 17:06:19 +00:00
|
|
|
</View>
|
|
|
|
|
|
|
|
<View style={styles.detailContainer}>
|
2022-01-17 16:10:39 +00:00
|
|
|
<CustomIcon name='user' size={24} color={themes[theme!].auxiliaryText} />
|
|
|
|
<Text style={[styles.detailText, { color: themes[theme!].auxiliaryText }]} numberOfLines={1}>
|
2021-09-13 20:41:05 +00:00
|
|
|
{replies}
|
|
|
|
</Text>
|
2021-01-14 17:06:19 +00:00
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
|
|
|
|
<View style={styles.badgeContainer}>
|
2021-09-13 20:41:05 +00:00
|
|
|
{badgeColor ? <View style={[styles.badge, { backgroundColor: badgeColor }]} /> : null}
|
2021-01-14 17:06:19 +00:00
|
|
|
<Touchable onPress={() => toggleFollowThread?.(isFollowing, item.id)}>
|
|
|
|
<CustomIcon
|
|
|
|
size={24}
|
|
|
|
name={isFollowing ? 'notification' : 'notification-disabled'}
|
2022-01-17 16:10:39 +00:00
|
|
|
color={themes[theme!].auxiliaryTintColor}
|
2021-01-14 17:06:19 +00:00
|
|
|
/>
|
|
|
|
</Touchable>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default withTheme(ThreadDetails);
|