import React, { FC, useState } from 'react'; import { Text, TouchableOpacity, View } from 'react-native'; import { Image } from 'expo-image'; import { useNavigation } from '@react-navigation/native'; import * as FileSystem from 'expo-file-system'; import { ProfileStyles, ScoreStyles, TBTStyles } from './styles'; import { storage, StoreType } from 'src/storage'; import { AvatarWithInitials, WarningModal } from 'src/components'; import { API_HOST } from '../../../../constants'; import { getFontSize } from '../../../../utils'; import { adaptiveStyle, Colors } from '../../../../theme'; import TickIcon from '../../../../../assets/icons/tick.svg'; import UNIcon from '../../../../../assets/icons/un_icon.svg'; import NMIcon from '../../../../../assets/icons/nm_icon.svg'; import TBTIcon from '../../../../../assets/icons/tbt.svg'; import { NAVIGATION_PAGES } from '../../../../types'; import { useConnection } from 'src/contexts/ConnectionContext'; import Tooltip from 'react-native-walkthrough-tooltip'; type Props = { avatar: string | null; first_name: string; last_name: string; date_of_birth: number; homebase_flag: string; homebase2_flag: string | null; index: number; score: any[]; active_score: number; tbt_score?: number; tbt_rank?: number; badge_tbt?: number; badge_1281: number; badge_un: number; auth: number; userId: number; }; //TODO: Profile export const Profile: FC = ({ avatar, first_name, last_name, date_of_birth, homebase_flag, homebase2_flag, index, score, active_score, tbt_rank, badge_tbt, badge_1281, badge_un, auth, userId }) => { const navigation = useNavigation(); const scoreNames = ['NM', 'DARE', 'UN', 'UN+', 'TCC', 'DEEP', 'YES', 'SLOW', 'WHS', 'KYE']; const netInfo = useConnection(); const token = storage.get('token', StoreType.STRING); const [modalType, setModalType] = useState(null); const [toolTipVisible, setToolTipVisible] = useState(null); const handlePress = () => { if (!netInfo?.isInternetReachable) { setModalType('offline'); } else if (!token) { setModalType('unauthorized'); } else { navigation.navigate(...([NAVIGATION_PAGES.PUBLIC_PROFILE_VIEW, { userId }] as never)); } }; const avatarBaseUri = netInfo?.isInternetReachable ? `${API_HOST}/img/avatars/` : `${FileSystem.documentDirectory}avatars/`; const flagBaseUri = netInfo?.isInternetReachable ? `${API_HOST}/img/flags_new/` : `${FileSystem.documentDirectory}flags/`; const TBRanking = () => { const colors = [ 'rgba(237, 147, 52, 1)', 'rgba(128, 128, 128, 1)', 'rgba(211, 211, 211, 1)', 'rgba(187, 95, 5, 1)', '#808080' ]; const Rank = ({ color }: { color: string }) => ( ); return ( {handleGetTooltip('TBT')}} contentStyle={{ backgroundColor: Colors.WHITE }} placement="top" onClose={() => setToolTipVisible(null)} backgroundColor="transparent" allowChildInteraction={false} parentWrapperStyle={adaptiveStyle(TBTStyles.badgeRoot, {})} > setToolTipVisible('TBT')} > {badge_tbt && tbt_rank ? ( ) : ( )} {tbt_rank && tbt_rank >= 1 ? ( TBT # {tbt_rank} ) : ( )} ); }; const EmptyScore: FC<{ scoreName: string; index: number }> = ({ scoreName, index }) => { return ( {handleGetTooltip(scoreName)}} contentStyle={{ backgroundColor: Colors.WHITE }} placement="top" onClose={() => setToolTipVisible(null)} backgroundColor="transparent" allowChildInteraction={false} parentWrapperStyle={adaptiveStyle(ScoreStyles.scoreWrapper, {})} > setToolTipVisible(index)}> - {scoreName} ); }; const handleGetTooltip = (score: string) => { switch (score) { case 'NM': return 'NM list of regions'; case 'DARE': return ( Distinctive{' '} Alternative{' '} Remote{' '} E xtreme places ); case 'UN': return 'UN countries'; case 'UN+': return 'UN countries and territories'; case 'TCC': return ( Travelers’ Century Club list ); case 'DEEP': return ( Definite{' '} Exhaustive{'\n'} Exploring{' '} P roportion{'\n'}NM regions to UN countries ratio{'\n'} For travellers with minimum 30 UN countries visited. ); case 'YES': return 'Years Elapsed Since list'; case 'SLOW': return 'SLOW travel list'; case 'WHS': return 'World Heritage Sites'; case 'KYE': return 'Know Your Earth geographic based list'; case 'TBT': return 'The Biggest Travellers based on all rankings'; } return score; }; return ( {index + 1} handlePress()}> {avatar ? ( ) : homebase_flag ? ( ) : null} {first_name ?? ''} {last_name ?? ''} Age: {date_of_birth ?? ''} {homebase_flag && ( )} {homebase2_flag && homebase2_flag !== homebase_flag ? ( ) : null} {auth ? : null} {badge_un ? : null} {badge_1281 ? : null} {score[active_score]} {scoreNames[active_score]} {score.map((number, index) => { if (scoreNames[index] === 'SLOW' && number >= 4500) return ; if (scoreNames[index] === 'YES' && number >= 10000) return ; if (!number) return ; return ( {handleGetTooltip(scoreNames[index])} } contentStyle={{ backgroundColor: Colors.WHITE }} placement="top" onClose={() => setToolTipVisible(null)} backgroundColor="transparent" allowChildInteraction={false} key={index} parentWrapperStyle={adaptiveStyle(ScoreStyles.scoreWrapper, {})} > setToolTipVisible(index)}> {number} {scoreNames[index]} ); })} {modalType && ( setModalType(null)} /> )} ); };