tooot/src/screens/Tabs/Shared/Users.tsx

59 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-03-15 00:18:44 +01:00
import ComponentAccount from '@components/Account'
import ComponentSeparator from '@components/Separator'
2021-08-29 15:25:38 +02:00
import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
2021-03-15 00:18:44 +01:00
import { QueryKeyUsers, useUsersQuery } from '@utils/queryHooks/users'
import React, { useCallback } from 'react'
import { StyleSheet } from 'react-native'
import { FlatList } from 'react-native-gesture-handler'
const TabSharedUsers = React.memo(
2021-08-29 15:25:38 +02:00
({ route: { params } }: TabSharedStackScreenProps<'Tab-Shared-Users'>) => {
2021-03-15 00:18:44 +01:00
const queryKey: QueryKeyUsers = ['Users', params]
2022-08-07 01:18:10 +02:00
const { data, hasNextPage, fetchNextPage, isFetchingNextPage } =
useUsersQuery({
...queryKey[1],
options: {
getPreviousPageParam: firstPage =>
firstPage.links?.prev && { since_id: firstPage.links.next },
getNextPageParam: lastPage =>
lastPage.links?.next && { max_id: lastPage.links.next }
}
})
2021-03-15 00:18:44 +01:00
const flattenData = data?.pages
? data.pages.flatMap(page => [...page.body])
: []
const onEndReached = useCallback(
() => hasNextPage && !isFetchingNextPage && fetchNextPage(),
[hasNextPage, isFetchingNextPage]
)
return (
<FlatList
windowSize={7}
2021-03-15 00:18:44 +01:00
data={flattenData}
style={styles.flatList}
2022-08-07 01:18:10 +02:00
renderItem={({ item }) => (
2022-11-29 23:44:11 +01:00
<ComponentAccount account={item} />
2022-08-07 01:18:10 +02:00
)}
2021-03-15 00:18:44 +01:00
onEndReached={onEndReached}
onEndReachedThreshold={0.75}
ItemSeparatorComponent={ComponentSeparator}
maintainVisibleContentPosition={{
minIndexForVisible: 0,
autoscrollToTopThreshold: 2
}}
/>
)
},
() => true
)
const styles = StyleSheet.create({
flatList: {
minHeight: '100%'
}
})
export default TabSharedUsers