diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-11-29 17:35:57 -0800 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2023-11-29 17:35:57 -0800 |
commit | 4c7b9652dbe858d5357d4e983c110c84c9e5a46e (patch) | |
tree | cf012d95b87edaec87c492ab4a20d8fd64d9b1c5 /src | |
parent | dc53ef1ec17d4c89ace36ed64d1217caaa54cdb9 (diff) | |
parent | 3fbac466ac8554fcb690fccbe0053a5be07801d7 (diff) | |
download | voidsky-4c7b9652dbe858d5357d4e983c110c84c9e5a46e.tar.zst |
Merge branch '2011-link-in-feeds-tab-bar' of https://github.com/CooperEdmunds/social-app into CooperEdmunds-2011-link-in-feeds-tab-bar
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/constants.ts | 4 | ||||
-rw-r--r-- | src/state/queries/feed.ts | 11 | ||||
-rw-r--r-- | src/view/com/pager/FeedsTabBar.web.tsx | 33 | ||||
-rw-r--r-- | src/view/com/pager/FeedsTabBarMobile.tsx | 34 | ||||
-rw-r--r-- | src/view/com/pager/PagerWithHeader.tsx | 2 | ||||
-rw-r--r-- | src/view/com/pager/TabBar.tsx | 2 | ||||
-rw-r--r-- | src/view/screens/Profile.tsx | 1 | ||||
-rw-r--r-- | src/view/screens/ProfileFeed.tsx | 1 | ||||
-rw-r--r-- | src/view/shell/desktop/Feeds.tsx | 2 |
9 files changed, 80 insertions, 10 deletions
diff --git a/src/lib/constants.ts b/src/lib/constants.ts index f8f651305..aa5983be7 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -116,8 +116,8 @@ export async function DEFAULT_FEEDS( } else { // production return { - pinned: [PROD_DEFAULT_FEED('whats-hot')], - saved: [PROD_DEFAULT_FEED('whats-hot')], + pinned: [], + saved: [], } } } diff --git a/src/state/queries/feed.ts b/src/state/queries/feed.ts index b5d491a5c..3266b0f6b 100644 --- a/src/state/queries/feed.ts +++ b/src/state/queries/feed.ts @@ -246,13 +246,20 @@ const FOLLOWING_FEED_STUB: FeedSourceInfo = { likeUri: '', } -export function usePinnedFeedsInfos(): FeedSourceInfo[] { +export function usePinnedFeedsInfos(): { + feeds: FeedSourceInfo[] + hasPinnedCustomFeedOrList: boolean +} { const queryClient = useQueryClient() const [tabs, setTabs] = React.useState<FeedSourceInfo[]>([ FOLLOWING_FEED_STUB, ]) const {data: preferences} = usePreferencesQuery() + const hasPinnedCustomFeedOrList = React.useMemo<boolean>(() => { + return tabs.some(tab => tab !== FOLLOWING_FEED_STUB) + }, [tabs]) + React.useEffect(() => { if (!preferences?.feeds?.pinned) return const uris = preferences.feeds.pinned @@ -300,5 +307,5 @@ export function usePinnedFeedsInfos(): FeedSourceInfo[] { fetchFeedInfo() }, [queryClient, setTabs, preferences?.feeds?.pinned]) - return tabs + return {feeds: tabs, hasPinnedCustomFeedOrList} } diff --git a/src/view/com/pager/FeedsTabBar.web.tsx b/src/view/com/pager/FeedsTabBar.web.tsx index fdb4df171..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 735aa1bac..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} diff --git a/src/view/com/pager/PagerWithHeader.tsx b/src/view/com/pager/PagerWithHeader.tsx index 3d2a3c55f..2c7640c43 100644 --- a/src/view/com/pager/PagerWithHeader.tsx +++ b/src/view/com/pager/PagerWithHeader.tsx @@ -108,6 +108,7 @@ export const PagerWithHeader = React.forwardRef<PagerRef, PagerWithHeaderProps>( pointerEvents: isHeaderReady ? 'auto' : 'none', }}> <TabBar + testID={testID} items={items} selectedPage={currentPage} onSelect={props.onSelect} @@ -127,6 +128,7 @@ export const PagerWithHeader = React.forwardRef<PagerRef, PagerWithHeaderProps>( isMobile, onTabBarLayout, onHeaderOnlyLayout, + testID, ], ) diff --git a/src/view/com/pager/TabBar.tsx b/src/view/com/pager/TabBar.tsx index 0e08b22d8..c3a95c5c0 100644 --- a/src/view/com/pager/TabBar.tsx +++ b/src/view/com/pager/TabBar.tsx @@ -68,6 +68,7 @@ export function TabBar({ return ( <View testID={testID} style={[pal.view, styles.outer]}> <DraggableScrollView + testID={`${testID}-selector`} horizontal={true} showsHorizontalScrollIndicator={false} ref={scrollElRef} @@ -76,6 +77,7 @@ export function TabBar({ const selected = i === selectedPage return ( <PressableWithHover + testID={`${testID}-selector-${i}`} key={item} onLayout={e => onItemLayout(e, i)} style={[styles.item, selected && indicatorStyle]} diff --git a/src/view/screens/Profile.tsx b/src/view/screens/Profile.tsx index 89dec5f97..3e9a59929 100644 --- a/src/view/screens/Profile.tsx +++ b/src/view/screens/Profile.tsx @@ -267,6 +267,7 @@ function ProfileScreenLoaded({ screenDescription="profile" moderation={moderation.account}> <PagerWithHeader + testID="profilePager" isHeaderReady={true} items={sectionTitles} onPageSelected={onPageSelected} diff --git a/src/view/screens/ProfileFeed.tsx b/src/view/screens/ProfileFeed.tsx index 6d4c0c237..e38543e6b 100644 --- a/src/view/screens/ProfileFeed.tsx +++ b/src/view/screens/ProfileFeed.tsx @@ -353,6 +353,7 @@ export function ProfileFeedScreenInner({ style={styles.btn} /> <Button + testID={isPinned ? 'unpinBtn' : 'pinBtn'} disabled={isPinPending || isUnpinPending} type={isPinned ? 'default' : 'inverted'} label={isPinned ? 'Unpin' : 'Pin to home'} diff --git a/src/view/shell/desktop/Feeds.tsx b/src/view/shell/desktop/Feeds.tsx index eeeca4fd8..ff51ffe22 100644 --- a/src/view/shell/desktop/Feeds.tsx +++ b/src/view/shell/desktop/Feeds.tsx @@ -11,7 +11,7 @@ import {usePinnedFeedsInfos} from '#/state/queries/feed' export function DesktopFeeds() { const pal = usePalette('default') const {_} = useLingui() - const feeds = usePinnedFeedsInfos() + const {feeds} = usePinnedFeedsInfos() const route = useNavigationState(state => { if (!state) { |