import {useNavigation} from '@react-navigation/native'; import React, {useEffect, useState} from 'react'; import { StyleProp, StyleSheet, Text, TextStyle, TouchableOpacity, ViewProps, ViewStyle, } from 'react-native'; import LinearGradient from 'react-native-linear-gradient'; import {useDispatch, useSelector, useStore} from 'react-redux'; import {loadImageFromURL} from '../../services'; import {RootState} from '../../store/rootReducer'; import {ProfilePreviewType, ScreenType} from '../../types'; import {fetchUserX, normalize, userXInStore} from '../../utils'; import {Avatar} from '../common'; /** * Search Screen for user recommendations and a search * tool to allow user to find other users */ interface ExploreSectionUserProps extends ViewProps { user: ProfilePreviewType; externalStyles?: Record>; } const ExploreSectionUser: React.FC = ({ user, externalStyles, }) => { const {id, username, first_name, last_name} = user; const [avatar, setAvatar] = useState(); const navigation = useNavigation(); const {user: loggedInUser} = useSelector((state: RootState) => state.user); const state: RootState = useStore().getState(); const screenType = ScreenType.Search; const dispatch = useDispatch(); useEffect(() => { (async () => { const response = await loadImageFromURL(user.thumbnail_url); if (response) { setAvatar(response); } })(); }, []); const handlePress = async () => { if (!userXInStore(state, screenType, user.id)) { await fetchUserX( dispatch, {userId: user.id, username: user.username}, screenType, ); } const userXId = loggedInUser.username === user.username ? undefined : id; navigation.push('Profile', { userXId, screenType, }); }; return ( {first_name} {last_name} {`@${username}`} ); }; const styles = StyleSheet.create({ container: { alignItems: 'center', width: 100, paddingVertical: 10, }, gradient: { height: 62, aspectRatio: 1, borderRadius: 40, justifyContent: 'center', alignItems: 'center', marginBottom: 10, }, profile: { height: 55, aspectRatio: 1, borderRadius: 38, }, name: { fontWeight: '600', flexWrap: 'wrap', fontSize: normalize(14), lineHeight: normalize(15), color: '#fff', textAlign: 'center', }, username: { fontWeight: '500', fontSize: normalize(11), lineHeight: normalize(15), color: '#fff', }, }); export default ExploreSectionUser;