diff options
author | Cooper Edmunds <cooper6789@gmail.com> | 2023-11-29 14:49:18 -0500 |
---|---|---|
committer | Cooper Edmunds <cooper6789@gmail.com> | 2023-11-29 14:49:18 -0500 |
commit | 8ceabe2a11742973447a6e3b4489c8a5660f48c3 (patch) | |
tree | 20f3ddff97ea9100b18960ee68c6b0d6335b50b0 /src | |
parent | ed391c346d6e6858d0d24c08def2974df8ccbde7 (diff) | |
download | voidsky-8ceabe2a11742973447a6e3b4489c8a5660f48c3.tar.zst |
Conditionally render feeds link in feeds tab bar
Diffstat (limited to 'src')
-rw-r--r-- | src/view/com/pager/FeedsTabBar.web.tsx | 33 | ||||
-rw-r--r-- | src/view/com/pager/FeedsTabBarMobile.tsx | 34 |
2 files changed, 62 insertions, 5 deletions
diff --git a/src/view/com/pager/FeedsTabBar.web.tsx b/src/view/com/pager/FeedsTabBar.web.tsx index 5ec6c68c3..2445d4523 100644 --- a/src/view/com/pager/FeedsTabBar.web.tsx +++ b/src/view/com/pager/FeedsTabBar.web.tsx @@ -12,6 +12,9 @@ import {usePinnedFeedsInfos} from '#/state/queries/feed' import {useSession} from '#/state/session' import {TextLink} from '#/view/com/util/Link' import {CenteredView} from '../util/Views' +import {isWeb} from 'platform/detection' +import {useNavigation} from '@react-navigation/native' +import {NavigationProp} from 'lib/routes/types' export function FeedsTabBar( props: RenderTabBarFnProps & {testID?: string; onPressSelected: () => void}, @@ -79,12 +82,37 @@ function FeedsTabBarPublic() { function FeedsTabBarTablet( props: RenderTabBarFnProps & {testID?: string; onPressSelected: () => void}, ) { - const {feeds} = usePinnedFeedsInfos() + const {feeds, hasPinnedCustomFeedOrList} = usePinnedFeedsInfos() const pal = usePalette('default') const {hasSession} = useSession() + const navigation = useNavigation<NavigationProp>() const {headerMinimalShellTransform} = useMinimalShellMode() const {headerHeight} = useShellLayout() - const items = hasSession ? feeds.map(f => f.displayName) : [] + const pinnedDisplayNames = hasSession ? feeds.map(f => f.displayName) : [] + const showFeedsLinkInTabBar = hasSession && !hasPinnedCustomFeedOrList + const items = showFeedsLinkInTabBar + ? pinnedDisplayNames.concat('Feeds ✨') + : pinnedDisplayNames + + const onPressDiscoverFeeds = React.useCallback(() => { + if (isWeb) { + navigation.navigate('Feeds') + } else { + navigation.navigate('FeedsTab') + navigation.popToTop() + } + }, [navigation]) + + const onSelect = React.useCallback( + (index: number) => { + if (showFeedsLinkInTabBar && index === items.length - 1) { + onPressDiscoverFeeds() + } else if (props.onSelect) { + props.onSelect(index) + } + }, + [items.length, onPressDiscoverFeeds, props, showFeedsLinkInTabBar], + ) return ( // @ts-ignore the type signature for transform wrong here, translateX and translateY need to be in separate objects -prf @@ -96,6 +124,7 @@ function FeedsTabBarTablet( <TabBar key={items.join(',')} {...props} + onSelect={onSelect} items={items} indicatorColor={pal.colors.link} /> diff --git a/src/view/com/pager/FeedsTabBarMobile.tsx b/src/view/com/pager/FeedsTabBarMobile.tsx index 46cb488d5..fc9eb8f14 100644 --- a/src/view/com/pager/FeedsTabBarMobile.tsx +++ b/src/view/com/pager/FeedsTabBarMobile.tsx @@ -18,6 +18,9 @@ import {useSetDrawerOpen} from '#/state/shell/drawer-open' import {useShellLayout} from '#/state/shell/shell-layout' import {useSession} from '#/state/session' import {usePinnedFeedsInfos} from '#/state/queries/feed' +import {isWeb} from 'platform/detection' +import {useNavigation} from '@react-navigation/native' +import {NavigationProp} from 'lib/routes/types' export function FeedsTabBar( props: RenderTabBarFnProps & {testID?: string; onPressSelected: () => void}, @@ -26,11 +29,36 @@ export function FeedsTabBar( const {isSandbox, hasSession} = useSession() const {_} = useLingui() const setDrawerOpen = useSetDrawerOpen() - const {feeds} = usePinnedFeedsInfos() + const navigation = useNavigation<NavigationProp>() + const {feeds, hasPinnedCustomFeedOrList} = usePinnedFeedsInfos() const brandBlue = useColorSchemeStyle(s.brandBlue, s.blue3) const {headerHeight} = useShellLayout() const {headerMinimalShellTransform} = useMinimalShellMode() - const items = hasSession ? feeds.map(f => f.displayName) : [] + const pinnedDisplayNames = hasSession ? feeds.map(f => f.displayName) : [] + const showFeedsLinkInTabBar = hasSession && !hasPinnedCustomFeedOrList + const items = showFeedsLinkInTabBar + ? pinnedDisplayNames.concat('Feeds ✨') + : pinnedDisplayNames + + const onPressFeedsLink = React.useCallback(() => { + if (isWeb) { + navigation.navigate('Feeds') + } else { + navigation.navigate('FeedsTab') + navigation.popToTop() + } + }, [navigation]) + + const onSelect = React.useCallback( + (index: number) => { + if (showFeedsLinkInTabBar && index === items.length - 1) { + onPressFeedsLink() + } else if (props.onSelect) { + props.onSelect(index) + } + }, + [items.length, onPressFeedsLink, props, showFeedsLinkInTabBar], + ) const onPressAvi = React.useCallback(() => { setDrawerOpen(true) @@ -84,7 +112,7 @@ export function FeedsTabBar( key={items.join(',')} onPressSelected={props.onPressSelected} selectedPage={props.selectedPage} - onSelect={props.onSelect} + onSelect={onSelect} testID={props.testID} items={items} indicatorColor={pal.colors.link} |