import ComponentAccount from '@components/Account' import { HeaderLeft } from '@components/Header' import Icon from '@components/Icon' import ComponentSeparator from '@components/Separator' import CustomText from '@components/Text' import apiInstance from '@utils/api/instance' import { TabSharedStackScreenProps } from '@utils/navigation/navigators' import { SearchResult } from '@utils/queryHooks/search' import { QueryKeyUsers, useUsersQuery } from '@utils/queryHooks/users' import { flattenPages } from '@utils/queryHooks/utils' import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { View } from 'react-native' import { Circle, Flow } from 'react-native-animated-spinkit' import { FlatList } from 'react-native-gesture-handler' const TabSharedUsers: React.FC> = ({ navigation, route: { params } }) => { const { colors } = useTheme() const { t } = useTranslation('screenTabs') useEffect(() => { navigation.setOptions({ title: t(`shared.users.${params.reference}.${params.type}`, { count: params.count } as any) as any, headerLeft: () => navigation.goBack()} /> }) }, []) const queryKey: QueryKeyUsers = ['Users', params] const { data, isFetching, hasNextPage, fetchNextPage, isFetchingNextPage } = useUsersQuery({ ...queryKey[1], options: { getPreviousPageParam: firstPage => firstPage.links?.prev?.id && { min_id: firstPage.links.prev.id }, getNextPageParam: lastPage => lastPage.links?.next?.id && { max_id: lastPage.links.next.id } } }) const [isSearching, setIsSearching] = useState(false) return ( ( { if (data?.pages[0]?.remoteData) { setIsSearching(true) apiInstance({ version: 'v2', method: 'get', url: 'search', params: { q: `@${item.acct}`, type: 'accounts', limit: 1, resolve: true } }) .then(res => { setIsSearching(false) if (res.body.accounts[0]) { navigation.push('Tab-Shared-Account', { account: res.body.accounts[0] }) } }) .catch(() => setIsSearching(false)) } else { navigation.push('Tab-Shared-Account', { account: item }) } } }} children={} /> )} onEndReached={() => hasNextPage && !isFetchingNextPage && fetchNextPage()} onEndReachedThreshold={0.75} ItemSeparatorComponent={ComponentSeparator} ListEmptyComponent={ isFetching ? ( ) : null } maintainVisibleContentPosition={{ minIndexForVisible: 0, autoscrollToTopThreshold: 2 }} ListHeaderComponent={ data?.pages[0]?.warnIncomplete === true ? ( {t('shared.users.resultIncomplete')} ) : null } /> ) } export default TabSharedUsers