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

92 lines
2.9 KiB
TypeScript
Raw Normal View History

2021-03-15 00:18:44 +01:00
import ComponentAccount from '@components/Account'
2022-12-15 01:41:34 +01:00
import Icon from '@components/Icon'
import { Loading } from '@components/Loading'
2021-03-15 00:18:44 +01:00
import ComponentSeparator from '@components/Separator'
2022-12-15 01:41:34 +01:00
import CustomText from '@components/Text'
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'
2022-12-31 00:07:28 +01:00
import { flattenPages } from '@utils/queryHooks/utils'
2022-12-15 01:41:34 +01:00
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
2024-02-07 00:22:22 +01:00
import React from 'react'
2022-12-03 16:50:54 +01:00
import { useTranslation } from 'react-i18next'
2022-12-15 01:41:34 +01:00
import { View } from 'react-native'
import { FlatList } from 'react-native-gesture-handler'
2021-03-15 00:18:44 +01:00
2022-12-03 16:50:54 +01:00
const TabSharedUsers: React.FC<TabSharedStackScreenProps<'Tab-Shared-Users'>> = ({
navigation,
route: { params }
}) => {
2022-12-15 01:41:34 +01:00
const { colors } = useTheme()
2022-12-03 16:50:54 +01:00
const { t } = useTranslation('screenTabs')
2021-03-15 00:18:44 +01:00
2022-12-03 16:50:54 +01:00
const queryKey: QueryKeyUsers = ['Users', params]
2022-12-15 14:28:36 +01:00
const { data, isFetching, hasNextPage, fetchNextPage, isFetchingNextPage } = useUsersQuery({
2023-01-07 18:01:08 +01:00
...queryKey[1]
2022-12-03 16:50:54 +01:00
})
2021-03-15 00:18:44 +01:00
2022-12-03 16:50:54 +01:00
return (
<FlatList
2022-12-31 00:07:28 +01:00
data={flattenPages(data)}
2022-12-03 16:50:54 +01:00
style={{
2022-12-15 14:28:36 +01:00
minHeight: '100%',
paddingVertical: StyleConstants.Spacing.Global.PagePadding
2022-12-03 16:50:54 +01:00
}}
renderItem={({ item }) => (
2022-12-15 14:28:36 +01:00
<ComponentAccount
account={item}
props={{ onPress: () => navigation.push('Tab-Shared-Account', { account: item }) }}
2022-12-15 14:28:36 +01:00
/>
)}
onEndReached={() => hasNextPage && !isFetchingNextPage && fetchNextPage()}
2022-12-03 16:50:54 +01:00
onEndReachedThreshold={0.75}
ItemSeparatorComponent={ComponentSeparator}
2022-12-15 14:28:36 +01:00
ListEmptyComponent={
isFetching ? (
<View
style={{
flex: 1,
minHeight: '100%',
justifyContent: 'center',
alignItems: 'center'
}}
>
<Loading />
2022-12-15 14:28:36 +01:00
</View>
) : null
}
2022-12-03 16:50:54 +01:00
maintainVisibleContentPosition={{
minIndexForVisible: 0,
autoscrollToTopThreshold: 2
}}
2022-12-15 01:41:34 +01:00
ListHeaderComponent={
data?.pages[0]?.warnIncomplete === true ? (
<View
style={{
flexDirection: 'row',
alignItems: 'center',
marginHorizontal: StyleConstants.Spacing.Global.PagePadding,
padding: StyleConstants.Spacing.S,
borderColor: colors.border,
borderWidth: 1,
2023-02-12 18:38:06 +01:00
borderRadius: StyleConstants.BorderRadius
2022-12-15 01:41:34 +01:00
}}
>
<Icon
name='alert-circle'
2022-12-15 01:41:34 +01:00
color={colors.secondary}
size={StyleConstants.Font.Size.M}
style={{ marginRight: StyleConstants.Spacing.S }}
/>
<CustomText fontStyle='S' style={{ flexShrink: 1, color: colors.secondary }}>
{t('shared.users.resultIncomplete')}
</CustomText>
</View>
) : null
}
2022-12-03 16:50:54 +01:00
/>
)
}
2021-03-15 00:18:44 +01:00
export default TabSharedUsers