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

95 lines
2.6 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-01-11 21:36:57 +01:00
import { useAccountQuery } from '@utils/queryHooks/account'
2021-01-16 00:00:31 +01:00
import { useTheme } from '@utils/styles/ThemeManager'
2021-01-31 03:09:35 +01:00
import React, { useCallback, useEffect, useMemo, useReducer } from 'react'
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'
import AccountContext from './Account/utils/createContext'
import accountInitialState from './Account/utils/initialState'
import accountReducer from './Account/utils/reducer'
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-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)
const [accountState, accountDispatch] = useReducer(
accountReducer,
accountInitialState
)
2020-10-26 00:27:53 +01:00
2020-12-21 21:47:15 +01:00
useEffect(() => {
const updateHeaderRight = () =>
navigation.setOptions({
headerRight: () => (
<HeaderRight
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
}}
2020-12-21 21:47:15 +01:00
/>
)
})
return updateHeaderRight()
}, [])
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])
2020-11-22 00:46:23 +01:00
return (
<AccountContext.Provider value={{ accountState, accountDispatch }}>
<AccountNav scrollY={scrollY} account={data} />
2021-01-15 01:15:27 +01:00
<Timeline
page='Account_Default'
account={account.id}
disableRefresh
customProps={{
onScroll,
scrollEventThrottle: 16,
2021-01-16 00:00:31 +01:00
ListHeaderComponent
2021-01-15 01:15:27 +01:00
}}
/>
</AccountContext.Provider>
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