tooot/src/screens/Shared/Account.tsx

123 lines
3.5 KiB
TypeScript
Raw Normal View History

2021-01-24 02:25:43 +01:00
import analytics from '@components/analytics'
import BottomSheet from '@components/BottomSheet'
import { HeaderRight } from '@components/Header'
2021-01-15 01:15:27 +01:00
import Timeline from '@components/Timelines/Timeline'
2021-01-19 01:13:45 +01:00
import HeaderActionsAccount from '@components/Timelines/Timeline/Shared/HeaderActions/Account'
import HeaderActionsShare from '@components/Timelines/Timeline/Shared/HeaderActions/Share'
2021-01-11 21:36:57 +01:00
import { useAccountQuery } from '@utils/queryHooks/account'
2021-01-07 19:13:09 +01:00
import { getLocalAccount } from '@utils/slices/instancesSlice'
2021-01-16 00:00:31 +01:00
import { useTheme } from '@utils/styles/ThemeManager'
import React, {
useCallback,
useEffect,
useMemo,
useReducer,
useState
} from 'react'
import { StyleSheet, View } from 'react-native'
2021-01-15 01:15:27 +01:00
import { useSharedValue } from 'react-native-reanimated'
import { useSelector } from 'react-redux'
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-07 22:18:14 +01:00
const ScreenSharedAccount: 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-07 19:13:09 +01:00
const localAccount = useSelector(getLocalAccount)
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
const [modalVisible, setBottomSheetVisible] = useState(false)
useEffect(() => {
const updateHeaderRight = () =>
navigation.setOptions({
headerRight: () => (
<HeaderRight
content='MoreHorizontal'
2021-01-24 02:25:43 +01:00
onPress={() => {
analytics('bottomsheet_open_press', {
page: 'account'
})
setBottomSheetVisible(true)
}}
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
}}
/>
2020-12-21 21:47:15 +01:00
<BottomSheet
visible={modalVisible}
handleDismiss={() => setBottomSheetVisible(false)}
>
{/* 添加到列表 */}
2021-01-07 19:13:09 +01:00
{localAccount?.id !== account.id && (
2021-01-12 00:12:44 +01:00
<HeaderActionsAccount
2020-12-21 21:47:15 +01:00
account={account}
setBottomSheetVisible={setBottomSheetVisible}
/>
)}
2021-01-19 01:13:45 +01:00
<HeaderActionsShare
url={account.url}
type='account'
setBottomSheetVisible={setBottomSheetVisible}
/>
2020-12-21 21:47:15 +01:00
</BottomSheet>
</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
}
})
2020-11-21 13:19:05 +01:00
export default ScreenSharedAccount