Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869import {useCallback, useMemo} from 'react'import {useNavigation} from '@react-navigation/native'
import {type NavigationProp} from '#/lib/routes/types'import {type FeedSourceInfo} from '#/state/queries/feed'import {useSession} from '#/state/session'import {type 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: Pick<FeedSourceInfo, 'displayName' | 'uri'>[] },) { const {feeds, onSelect: onSelectProp} = props const {hasSession} = useSession() const navigation = useNavigation<NavigationProp>()
const hasPinnedCustom = useMemo<boolean>(() => { if (!hasSession) return false return feeds.some(tab => { const isFollowing = tab.uri === 'following' return !isFollowing }) }, [feeds, hasSession])
const items = useMemo(() => { const pinnedNames = feeds.map(f => f.displayName) if (!hasPinnedCustom) { return pinnedNames.concat('Feeds ✨') } return pinnedNames }, [hasPinnedCustom, feeds])
const onPressFeedsLink = useCallback(() => { navigation.navigate('Feeds') }, [navigation])
const onSelect = useCallback( (index: number) => { if (!hasPinnedCustom && index === items.length - 1) { onPressFeedsLink() } else if (onSelectProp) { onSelectProp(index) } }, [items.length, onPressFeedsLink, onSelectProp, hasPinnedCustom], )
return ( <HomeHeaderLayout tabBarAnchor={props.tabBarAnchor}> <TabBar key={items.join(',')} onPressSelected={props.onPressSelected} selectedPage={props.selectedPage} onSelect={onSelect} testID={props.testID} items={items} dragProgress={props.dragProgress} dragState={props.dragState} transparent /> </HomeHeaderLayout> )}