Bluesky app fork with some witchin' additions 💫 witchsky.app
bluesky fork client
at main 80 lines 2.2 kB view raw
1import React from 'react' 2import {useNavigation} from '@react-navigation/native' 3 4import {type NavigationProp} from '#/lib/routes/types' 5import {useHideFeedsPromoTab} from '#/state/preferences/hide-feeds-promo-tab' 6import {type FeedSourceInfo} from '#/state/queries/feed' 7import {useSession} from '#/state/session' 8import {type RenderTabBarFnProps} from '#/view/com/pager/Pager' 9import {TabBar} from '../pager/TabBar' 10import {HomeHeaderLayout} from './HomeHeaderLayout' 11 12export function HomeHeader( 13 props: RenderTabBarFnProps & { 14 testID?: string 15 onPressSelected: () => void 16 feeds: FeedSourceInfo[] 17 }, 18) { 19 const {feeds, onSelect: onSelectProp} = props 20 const {hasSession} = useSession() 21 const hideFeedsPromoTab = useHideFeedsPromoTab() 22 const navigation = useNavigation<NavigationProp>() 23 24 const hasPinnedCustom = React.useMemo<boolean>(() => { 25 if (!hasSession) return false 26 return feeds.some(tab => { 27 const isFollowing = tab.uri === 'following' 28 return !isFollowing 29 }) 30 }, [feeds, hasSession]) 31 32 const items = React.useMemo(() => { 33 const pinnedNames = feeds.map(f => f.displayName) 34 if (!hasPinnedCustom && !hideFeedsPromoTab) { 35 return pinnedNames.concat('Feeds ✨') 36 } 37 return pinnedNames 38 }, [hasPinnedCustom, hideFeedsPromoTab, feeds]) 39 40 const onPressFeedsLink = React.useCallback(() => { 41 navigation.navigate('Feeds') 42 }, [navigation]) 43 44 const onSelect = React.useCallback( 45 (index: number) => { 46 if ( 47 !hasPinnedCustom && 48 !hideFeedsPromoTab && 49 index === items.length - 1 50 ) { 51 onPressFeedsLink() 52 } else if (onSelectProp) { 53 onSelectProp(index) 54 } 55 }, 56 [ 57 items.length, 58 onPressFeedsLink, 59 onSelectProp, 60 hasPinnedCustom, 61 hideFeedsPromoTab, 62 ], 63 ) 64 65 return ( 66 <HomeHeaderLayout tabBarAnchor={props.tabBarAnchor}> 67 <TabBar 68 key={items.join(',')} 69 onPressSelected={props.onPressSelected} 70 selectedPage={props.selectedPage} 71 onSelect={onSelect} 72 testID={props.testID} 73 items={items} 74 dragProgress={props.dragProgress} 75 dragState={props.dragState} 76 transparent 77 /> 78 </HomeHeaderLayout> 79 ) 80}