import menuAccount from '@components/contextMenu/account' import menuShare from '@components/contextMenu/share' import { HeaderLeft, HeaderRight } from '@components/Header' import Timeline from '@components/Timeline' import TimelineDefault from '@components/Timeline/Default' import SegmentedControl from '@react-native-community/segmented-control' import { useQueryClient } from '@tanstack/react-query' import { TabSharedStackScreenProps } from '@utils/navigation/navigators' import { useAccountQuery } from '@utils/queryHooks/account' import { useRelationshipQuery } from '@utils/queryHooks/relationship' import { QueryKeyTimeline } from '@utils/queryHooks/timeline' import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import React, { Fragment, useEffect, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { Platform, Text, View } from 'react-native' import { useSharedValue } from 'react-native-reanimated' import * as DropdownMenu from 'zeego/dropdown-menu' import AccountAttachments from './Attachments' import AccountContext from './Context' import AccountHeader from './Header' import AccountInformation from './Information' import AccountNav from './Nav' const TabSharedAccount: React.FC> = ({ navigation, route: { params: { account } } }) => { const { t } = useTranslation('screenTabs') const { colors, mode } = useTheme() const { data, dataUpdatedAt } = useAccountQuery({ account, _local: true, options: { onSuccess: a => { if (account._remote) { setQueryKey([ queryKey[0], { ...queryKey[1], page: 'Account', id: a.id, exclude_reblogs: true, only_media: false } ]) } }, onError: () => navigation.goBack() } }) const { data: dataRelationship } = useRelationshipQuery({ id: account._remote ? data?.id : account.id, options: { enabled: account._remote ? !!data?.id : true } }) const queryClient = useQueryClient() const [queryKey, setQueryKey] = useState([ 'Timeline', { page: 'Account', id: account._remote ? data?.id : account.id, exclude_reblogs: true, only_media: false } ]) const mShare = menuShare({ type: 'account', url: data?.url }) const mAccount = menuAccount({ type: 'account', openChange: true, account: data }) useEffect(() => { navigation.setOptions({ headerTransparent: true, headerStyle: { backgroundColor: `rgba(255, 255, 255, 0)` }, title: '', headerLeft: () => navigation.goBack()} background />, headerRight: () => { return ( {}} background /> {[mShare, mAccount].map((menu, i) => ( {menu.map((group, index) => ( {group.map(item => { switch (item.type) { case 'item': return ( {item.icon ? ( ) : null} ) case 'sub': if (Platform.OS === 'ios') { return ( // @ts-ignore {item.trigger.icon ? ( ) : null} {item.items.map(sub => ( {sub.icon ? ( ) : null} ))} ) } else { return ( {item.items.map(sub => ( {sub.icon ? ( ) : null} ))} ) } } })} ))} ))} ) } }) }, [mAccount]) useEffect(() => { navigation.setParams({ queryKey }) }, [queryKey[1]]) const scrollY = useSharedValue(0) const page = queryKey[1] const [segment, setSegment] = useState(0) const ListHeaderComponent = useMemo(() => { return ( <> {!data?.suspended ? ( { setSegment(nativeEvent.selectedSegmentIndex) switch (nativeEvent.selectedSegmentIndex) { case 0: setQueryKey([ queryKey[0], { ...page, page: 'Account', id: data?.id, exclude_reblogs: true, only_media: false } ]) break case 1: setQueryKey([ queryKey[0], { ...page, page: 'Account', id: data?.id, exclude_reblogs: false, only_media: false } ]) break } }} style={{ marginTop: StyleConstants.Spacing.M, marginHorizontal: StyleConstants.Spacing.Global.PagePadding }} /> ) : null} {data?.suspended ? ( {t('shared.account.suspended')} ) : null} ) }, [segment, dataUpdatedAt, mode]) return ( {data?.suspended ? ( ListHeaderComponent ) : ( , onScroll: ({ nativeEvent }) => (scrollY.value = nativeEvent.contentOffset.y), ListHeaderComponent, maintainVisibleContentPosition: undefined, onRefresh: () => queryClient.refetchQueries(queryKey), refreshing: false }} /> )} ) } export default TabSharedAccount