import React, { useState } from 'react'; import { View, Text, TouchableOpacity, Image } from 'react-native'; import { TabView, TabBar } from 'react-native-tab-view'; import ReactModal from 'react-native-modal'; import { FlashList } from '@shopify/flash-list'; import { useNavigation } from '@react-navigation/native'; import { Colors } from 'src/theme'; import { styles } from './styles'; import { NAVIGATION_PAGES } from 'src/types'; import { API_HOST } from 'src/constants'; import { Loading, WarningModal } from 'src/components'; import { StoreType, storage } from 'src/storage'; const SearchModal = ({ searchVisible, handleCloseModal, handleFindRegion, index, searchData, setIndex, token }: { searchVisible: boolean; handleCloseModal: () => void; handleFindRegion: (id: number, type: string) => void; index: number; searchData: any; setIndex: (index: number) => void; token: string | undefined; }) => { const navigation = useNavigation(); const [routes] = useState([ { key: 'users', title: 'Nomads' }, { key: 'regions', title: 'NM regions' }, { key: 'dare', title: 'DARE places' } ]); const [shouldOpenModal, setShouldOpenModal] = useState<{ id: number; type: string } | null>(null); const [warningVisible, setWarningVisible] = useState(false); const renderItem = ({ item }: { item: any }) => { const [name, ...rest] = item.name?.split(/ – | - /); const subname = rest?.join(' - '); return index === 0 ? ( { if (!token) { setWarningVisible(true); } else { handleCloseModal(); navigation.navigate( ...([NAVIGATION_PAGES.PUBLIC_PROFILE_VIEW, { userId: item.id }] as never) ); } }} > {item.name} {item.flag2 && item.flag2 !== item.flag1 && ( )} ) : ( { handleCloseModal(); if (index === 1) { setShouldOpenModal({ id: item.id, type: 'regions' }); } else { setShouldOpenModal({ id: item.id, type: 'places' }); } }} > {item.flag1 && } {item.flag2 && ( )} {name} {subname} ); }; const renderScene = ({ route }: { route: any }) => { return ( {searchData?.[route.key] ? ( item.id.toString()} showsVerticalScrollIndicator={false} contentContainerStyle={{ paddingVertical: 16, paddingHorizontal: 8 }} /> ) : ( )} setWarningVisible(false)} action={handleCloseModal} /> ); }; return ( { if (shouldOpenModal) { handleFindRegion(shouldOpenModal.id, shouldOpenModal.type); setShouldOpenModal(null); } }} > ( ( {route.title} )} /> )} /> ); }; export default SearchModal;