tooot/src/screens/Shared/Account.tsx

96 lines
3.0 KiB
TypeScript
Raw Normal View History

import BottomSheet from '@components/BottomSheet'
import { HeaderRight } from '@components/Header'
import HeaderDefaultActionsAccount from '@components/Timelines/Timeline/Shared/HeaderDefault/ActionsAccount'
import { accountFetch } from '@utils/fetches/accountFetch'
import { getLocalAccountId } from '@utils/slices/instancesSlice'
2020-12-21 21:47:15 +01:00
import React, { useEffect, useReducer, useRef, useState } from 'react'
2020-12-26 00:53:49 +01:00
import { Animated, ScrollView } from 'react-native'
import { useQuery } from 'react-query'
import { useSelector } from 'react-redux'
import AccountHeader from './Account/Header'
import AccountInformation from './Account/Information'
import AccountNav from './Account/Nav'
import AccountSegmentedControl from './Account/SegmentedControl'
import AccountToots from './Account/Toots'
import AccountContext from './Account/utils/createContext'
import accountInitialState from './Account/utils/initialState'
import accountReducer from './Account/utils/reducer'
2020-10-28 00:02:37 +01:00
// Moved account example: https://m.cmx.im/web/accounts/27812
2020-10-31 21:04:46 +01:00
export interface Props {
route: {
params: {
account: Pick<Mastodon.Account, 'id' | 'username' | 'acct' | 'url'>
2020-10-31 21:04:46 +01:00
}
}
2020-12-21 21:47:15 +01:00
navigation: any
2020-10-31 21:04:46 +01:00
}
2020-11-21 13:19:05 +01:00
const ScreenSharedAccount: React.FC<Props> = ({
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
}) => {
2020-12-21 21:47:15 +01:00
const localAccountId = useSelector(getLocalAccountId)
const { data } = useQuery(['Account', { id: account.id }], accountFetch)
const scrollY = useRef(new Animated.Value(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'
2020-12-21 21:47:15 +01:00
onPress={() => setBottomSheetVisible(true)}
/>
)
})
return updateHeaderRight()
}, [])
2020-11-22 00:46:23 +01:00
return (
<AccountContext.Provider value={{ accountState, accountDispatch }}>
<AccountNav scrollY={scrollY} account={data} />
2020-12-21 22:58:53 +01:00
{accountState.informationLayout?.height &&
accountState.informationLayout.y ? (
<AccountSegmentedControl scrollY={scrollY} />
2020-12-21 22:58:53 +01:00
) : null}
<ScrollView
2021-01-01 16:48:16 +01:00
scrollEventThrottle={16}
showsVerticalScrollIndicator={false}
onScroll={Animated.event(
[{ nativeEvent: { contentOffset: { y: scrollY.current } } }],
{ useNativeDriver: false }
)}
>
<AccountHeader account={data} />
<AccountInformation account={data} />
<AccountToots id={account.id} />
</ScrollView>
2020-12-21 21:47:15 +01:00
<BottomSheet
visible={modalVisible}
handleDismiss={() => setBottomSheetVisible(false)}
>
{/* 添加到列表 */}
{localAccountId !== account.id && (
<HeaderDefaultActionsAccount
account={account}
setBottomSheetVisible={setBottomSheetVisible}
/>
)}
</BottomSheet>
</AccountContext.Provider>
2020-10-26 00:27:53 +01:00
)
}
2020-10-28 00:02:37 +01:00
2020-11-21 13:19:05 +01:00
export default ScreenSharedAccount