import {RouteProp, useNavigation} from '@react-navigation/native'; import React, {useEffect, useState} from 'react'; import {FlatList, StatusBar, StyleSheet} from 'react-native'; import {Image, Text} from 'react-native-animatable'; import {TouchableOpacity} from 'react-native-gesture-handler'; import {SafeAreaView} from 'react-native-safe-area-context'; import { SearchBackground, SearchCategories, TabsGradient, TaggLoadingIndicator, } from '../../components'; import ExploreSectionUser from '../../components/search/ExploreSectionUser'; import {headerBarOptions, MainStackParams} from '../../routes'; import {getDiscoverUsers} from '../../services/ExploreService'; import {ProfilePreviewType} from '../../types'; import { HeaderHeight, normalize, SCREEN_HEIGHT, SCREEN_WIDTH, shuffle, } from '../../utils'; type DiscoverUsersRouteProps = RouteProp; interface DiscoverUsersProps { route: DiscoverUsersRouteProps; } const DiscoverUsers: React.FC = ({route}) => { const {name} = route.params.searchCategory; const [categoryName, setCategoryName] = useState(); const [users, setUsers] = useState([]); const [shouldRefresh, setShouldRefresh] = useState(false); const [showIcon1, setShowIcon1] = useState(true); const mtUser = (key: number) => ({ id: key, username: '...', first_name: '', last_name: '', thumbnail_url: '', }); const dummyUsers = [ mtUser(-1), mtUser(-2), mtUser(-3), mtUser(-4), mtUser(-5), mtUser(-6), mtUser(-7), mtUser(-8), mtUser(-9), ]; const [loading, setLoading] = useState(true); const navigation = useNavigation(); navigation.setOptions({ ...headerBarOptions('white', name), headerRight: () => ( { setShowIcon1(!showIcon1); setShouldRefresh(true); }}> ), }); useEffect(() => { setCategoryName(name); }, []); useEffect(() => { if (shouldRefresh) { setLoading(true); setTimeout(() => { setUsers(shuffle(users)); setShouldRefresh(false); setLoading(false); }, 500); } }, [shouldRefresh, users]); useEffect(() => { const loadData = async () => { setLoading(true); if (!categoryName) { return; } const fetched_users = await getDiscoverUsers(categoryName); if (fetched_users) { setUsers(fetched_users); } setLoading(false); }; loadData(); }, [categoryName]); const _renderItem = ({item: user}: {item: ProfilePreviewType}) => ( ); return ( {loading && } item.id} renderItem={_renderItem} showsVerticalScrollIndicator={false} ListFooterComponent={() => ( <> Other Groups )} /> ); }; const styles = StyleSheet.create({ header: {width: SCREEN_WIDTH}, headerText: { top: HeaderHeight, textAlign: 'center', color: '#fff', fontWeight: '600', fontSize: normalize(18), lineHeight: normalize(35), marginBottom: '5%', }, scrollView: { top: HeaderHeight, marginTop: '10%', width: SCREEN_WIDTH * 0.95, height: SCREEN_HEIGHT - HeaderHeight, alignSelf: 'center', flexDirection: 'column', }, user: { margin: '2%', }, columnWrapperStyle: { width: SCREEN_WIDTH * 0.95, justifyContent: 'space-between', }, contentContainerStyle: { width: SCREEN_WIDTH * 0.95, paddingBottom: SCREEN_HEIGHT * 0.2, }, otherGroups: { color: 'white', fontSize: normalize(18), fontWeight: '600', lineHeight: normalize(35), alignSelf: 'center', marginTop: 20, }, shuffleIcon: { width: 40, height: 40, marginRight: 20, }, }); export default DiscoverUsers;