import {useNavigation} from '@react-navigation/core'; import React, {useContext} from 'react'; import {Image, StyleSheet, Text, View} from 'react-native'; import {TouchableOpacity} from 'react-native-gesture-handler'; import {useSelector, useStore} from 'react-redux'; import {ChannelPreviewMessengerProps} from 'stream-chat-react-native'; import {ChatContext} from '../../App'; import {RootState} from '../../store/rootReducer'; import { LocalAttachmentType, LocalChannelType, LocalCommandType, LocalEventType, LocalMessageType, LocalReactionType, LocalUserType, } from '../../types'; import {normalize, SCREEN_HEIGHT} from '../../utils'; import {getMember, isOnline} from '../../utils/messages'; const ChannelPreview: React.FC< ChannelPreviewMessengerProps< LocalAttachmentType, LocalChannelType, LocalCommandType, LocalEventType, LocalMessageType, LocalReactionType, LocalUserType > > = (props) => { const {setChannel} = useContext(ChatContext); const state = useStore().getState(); const navigation = useNavigation(); const {channel} = props; const member = getMember(channel, state); const online = isOnline(member?.user?.last_active); const unread = channel.state.unreadCount > 0; return ( { setChannel(channel); navigation.navigate('Chat'); }}> {online && } {member?.user?.first_name} {member?.user?.last_name} {channel.state.messages.length > 0 ? channel.state.messages[channel.state.messages.length - 1].text : ''} {unread && } ); }; const styles = StyleSheet.create({ container: { flex: 1, flexDirection: 'row', height: Math.round(SCREEN_HEIGHT / 10), alignItems: 'center', paddingHorizontal: '8%', paddingVertical: '5%', }, avatar: { width: normalize(62), height: normalize(62), borderRadius: normalize(62) / 2, }, online: { position: 'absolute', backgroundColor: '#6EE7E7', width: normalize(18), height: normalize(18), borderRadius: normalize(18) / 2, borderColor: 'white', borderWidth: 2, bottom: 0, right: 0, }, content: { flex: 1, height: '100%', justifyContent: 'space-between', flexDirection: 'column', marginLeft: '5%', }, name: { fontWeight: '500', fontSize: normalize(14), lineHeight: normalize(17), }, lastMessage: { color: '#828282', fontWeight: '500', fontSize: normalize(12), lineHeight: normalize(14), }, unread: { fontWeight: '700', color: 'black', }, purpleDot: { backgroundColor: '#8F01FF', width: normalize(10), height: normalize(10), borderRadius: normalize(10) / 2, }, }); export default ChannelPreview;