diff options
author | Ivan Chen <ivan@tagg.id> | 2021-04-09 19:22:30 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-04-09 19:23:23 -0400 |
commit | ad9db5ffd0b2fb6334fd8237e0600a76d25c7053 (patch) | |
tree | 7d7c58cbdb67e3e0945a6ed2ccaa658f0048e887 /src/components/messages | |
parent | 2a9b090ad62c2d157e06c978ba4cbc663f7c550f (diff) |
added navigation to profile
Diffstat (limited to 'src/components/messages')
-rw-r--r-- | src/components/messages/ChatHeader.tsx | 81 |
1 files changed, 58 insertions, 23 deletions
diff --git a/src/components/messages/ChatHeader.tsx b/src/components/messages/ChatHeader.tsx index 2bc096ec..67a7f1fe 100644 --- a/src/components/messages/ChatHeader.tsx +++ b/src/components/messages/ChatHeader.tsx @@ -1,39 +1,71 @@ +import {useNavigation} from '@react-navigation/native'; import React, {useContext} from 'react'; import {Image, StyleSheet, View} from 'react-native'; import {Text} from 'react-native-animatable'; -import {useStore} from 'react-redux'; +import {TouchableOpacity} from 'react-native-gesture-handler'; +import {useDispatch, useStore} from 'react-redux'; import {ChatContext} from '../../App'; -import {ChatHeaderHeight, normalize, StatusBarHeight} from '../../utils'; +import {ScreenType} from '../../types'; +import { + ChatHeaderHeight, + fetchUserX, + normalize, + StatusBarHeight, + userXInStore, +} from '../../utils'; import {formatLastSeenText, getMember, isOnline} from '../../utils/messages'; -type ChatHeaderProps = {}; +type ChatHeaderProps = { + screenType: ScreenType; +}; -const ChatHeader: React.FC<ChatHeaderProps> = () => { +const ChatHeader: React.FC<ChatHeaderProps> = (props) => { + const {screenType} = props; const {channel} = useContext(ChatContext); + const dispatch = useDispatch(); + const navigation = useNavigation(); const state = useStore().getState(); const member = getMember(channel, state); const online = isOnline(member?.user?.last_active); const lastSeen = formatLastSeenText(member?.user?.last_active); + const toProfile = async () => { + if (member && member.user && member.user.username) { + if (!userXInStore(state, screenType, member.user.id)) { + await fetchUserX( + dispatch, + {userId: member.user.id, username: member.user.username}, + screenType, + ); + } + navigation.navigate('Profile', { + userXId: member.user.id, + screenType, + }); + } + }; + return ( <View style={styles.container}> - <View> - <Image - style={styles.avatar} - source={ - member - ? {uri: member.user?.thumbnail_url} - : require('../../assets/images/avatar-placeholder.png') - } - /> - {online && <View style={styles.online} />} - </View> - <View style={styles.content}> - <Text style={styles.name} numberOfLines={1}> - {member?.user?.first_name} {member?.user?.last_name} - </Text> - <Text style={styles.lastSeen}>{lastSeen}</Text> - </View> + <TouchableOpacity style={styles.tappables} onPress={toProfile}> + <View> + <Image + style={styles.avatar} + source={ + member + ? {uri: member.user?.thumbnail_url} + : require('../../assets/images/avatar-placeholder.png') + } + /> + {online && <View style={styles.online} />} + </View> + <View style={styles.content}> + <Text style={styles.name} numberOfLines={1}> + {member?.user?.first_name} {member?.user?.last_name} + </Text> + <Text style={styles.lastSeen}>{lastSeen}</Text> + </View> + </TouchableOpacity> </View> ); }; @@ -41,10 +73,13 @@ const ChatHeader: React.FC<ChatHeaderProps> = () => { const styles = StyleSheet.create({ container: { height: ChatHeaderHeight - StatusBarHeight, - flexDirection: 'row', - alignItems: 'center', paddingLeft: '15%', }, + tappables: { + alignItems: 'center', + flexDirection: 'row', + width: '100%', + }, avatar: { width: normalize(40), height: normalize(40), |