import React from 'react' import {useNavigation} from '@react-navigation/native' import {NavigationProp} from '#/lib/routes/types' import {FeedSourceInfo} from '#/state/queries/feed' import {useSession} from '#/state/session' import {RenderTabBarFnProps} from '#/view/com/pager/Pager' import {TabBar} from '../pager/TabBar' import {HomeHeaderLayout} from './HomeHeaderLayout' export function HomeHeader( props: RenderTabBarFnProps & { testID?: string onPressSelected: () => void feeds: FeedSourceInfo[] }, ) { const {feeds} = props const {hasSession} = useSession() const navigation = useNavigation() const hasPinnedCustom = React.useMemo(() => { if (!hasSession) return false return feeds.some(tab => { const isFollowing = tab.uri === 'following' return !isFollowing }) }, [feeds, hasSession]) const items = React.useMemo(() => { const pinnedNames = feeds.map(f => f.displayName) if (!hasPinnedCustom) { return pinnedNames.concat('Feeds ✨') } return pinnedNames }, [hasPinnedCustom, feeds]) const onPressFeedsLink = React.useCallback(() => { navigation.navigate('Feeds') }, [navigation]) const onSelect = React.useCallback( (index: number) => { if (!hasPinnedCustom && index === items.length - 1) { onPressFeedsLink() } else if (props.onSelect) { props.onSelect(index) } }, [items.length, onPressFeedsLink, props, hasPinnedCustom], ) return ( ) }