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

105 lines
2.9 KiB
TypeScript
Raw Normal View History

2021-01-24 02:25:43 +01:00
import analytics from '@components/analytics'
import { HeaderRight } from '@components/Header'
2021-02-08 23:47:20 +01:00
import Timeline from '@components/Timeline'
2021-02-27 16:33:54 +01:00
import TimelineDefault from '@components/Timeline/Default'
2021-01-11 21:36:57 +01:00
import { useAccountQuery } from '@utils/queryHooks/account'
2021-02-27 16:33:54 +01:00
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
2021-01-16 00:00:31 +01:00
import { useTheme } from '@utils/styles/ThemeManager'
2021-05-09 21:59:03 +02:00
import React, { useCallback, useEffect, useMemo } from 'react'
2021-04-09 21:43:12 +02:00
import { useTranslation } from 'react-i18next'
2021-01-16 00:00:31 +01:00
import { StyleSheet, View } from 'react-native'
2021-01-15 01:15:27 +01:00
import { useSharedValue } from 'react-native-reanimated'
2021-01-16 00:00:31 +01:00
import AccountAttachments from './Account/Attachments'
import AccountHeader from './Account/Header'
import AccountInformation from './Account/Information'
import AccountNav from './Account/Nav'
2021-01-07 22:18:14 +01:00
import { SharedAccountProp } from './sharedScreens'
2020-10-28 00:02:37 +01:00
2021-01-30 01:29:15 +01:00
const TabSharedAccount: React.FC<SharedAccountProp> = ({
2020-10-26 00:27:53 +01:00
route: {
2020-12-21 21:47:15 +01:00
params: { account }
},
navigation
2020-10-31 21:04:46 +01:00
}) => {
2021-04-09 21:43:12 +02:00
const { t, i18n } = useTranslation('screenTabs')
2021-01-16 00:00:31 +01:00
const { theme } = useTheme()
2021-01-11 21:36:57 +01:00
const { data } = useAccountQuery({ id: account.id })
const scrollY = useSharedValue(0)
2020-10-26 00:27:53 +01:00
2020-12-21 21:47:15 +01:00
useEffect(() => {
const updateHeaderRight = () =>
navigation.setOptions({
headerRight: () => (
<HeaderRight
2021-04-09 21:43:12 +02:00
accessibilityLabel={t('shared.account.actions.accessibilityLabel', {
user: data?.acct
})}
accessibilityHint={t('shared.account.actions.accessibilityHint')}
content='MoreHorizontal'
2021-01-24 02:25:43 +01:00
onPress={() => {
analytics('bottomsheet_open_press', {
page: 'account'
})
2021-02-11 01:33:31 +01:00
// @ts-ignore
2021-01-31 03:09:35 +01:00
navigation.navigate('Screen-Actions', {
type: 'account',
account
})
2021-01-24 02:25:43 +01:00
}}
2021-03-22 00:25:53 +01:00
background
2020-12-21 21:47:15 +01:00
/>
)
})
return updateHeaderRight()
2021-04-09 21:43:12 +02:00
}, [i18n.language])
2020-12-21 21:47:15 +01:00
2021-01-15 01:15:27 +01:00
const onScroll = useCallback(({ nativeEvent }) => {
scrollY.value = nativeEvent.contentOffset.y
}, [])
2021-01-16 00:00:31 +01:00
const ListHeaderComponent = useMemo(() => {
return (
<View style={[styles.header, { borderBottomColor: theme.border }]}>
<AccountHeader account={data} />
<AccountInformation account={data} />
<AccountAttachments account={data} />
</View>
)
}, [data])
2021-02-27 16:33:54 +01:00
const queryKey: QueryKeyTimeline = [
'Timeline',
{ page: 'Account_Default', account: account.id }
]
const renderItem = useCallback(
({ item }) => <TimelineDefault item={item} queryKey={queryKey} />,
[]
)
2020-11-22 00:46:23 +01:00
return (
2021-05-09 21:59:03 +02:00
<>
<AccountNav scrollY={scrollY} account={data} />
2021-01-15 01:15:27 +01:00
<Timeline
2021-02-27 16:33:54 +01:00
queryKey={queryKey}
2021-01-15 01:15:27 +01:00
disableRefresh
customProps={{
2021-02-27 16:33:54 +01:00
renderItem,
2021-01-15 01:15:27 +01:00
onScroll,
2021-01-16 00:00:31 +01:00
ListHeaderComponent
2021-01-15 01:15:27 +01:00
}}
/>
2021-05-09 21:59:03 +02:00
</>
2020-10-26 00:27:53 +01:00
)
}
2020-10-28 00:02:37 +01:00
2021-01-16 00:00:31 +01:00
const styles = StyleSheet.create({
header: {
borderBottomWidth: 1
}
})
2021-01-30 01:29:15 +01:00
export default TabSharedAccount