From 3de1d556a9e1a782ef1103251685d9693312c8d8 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 21 Nov 2023 17:36:29 -0600 Subject: [PATCH] [PWI] Feeds (#1970) * Feeds page * Hide save buttons on Feeds page * ProfileFeed --- src/view/screens/Feeds.tsx | 73 +++++++++++++++++--------------- src/view/screens/ProfileFeed.tsx | 15 ++++--- 2 files changed, 49 insertions(+), 39 deletions(-) diff --git a/src/view/screens/Feeds.tsx b/src/view/screens/Feeds.tsx index 301c87d1..28433911 100644 --- a/src/view/screens/Feeds.tsx +++ b/src/view/screens/Feeds.tsx @@ -34,6 +34,7 @@ import { } from '#/state/queries/feed' import {cleanError} from 'lib/strings/errors' import {useComposerControls} from '#/state/shell/composer' +import {useSession} from '#/state/session' type Props = NativeStackScreenProps @@ -117,6 +118,7 @@ export const FeedsScreen = withAuthRequired( isPending: isSearchPending, error: searchError, } = useSearchPopularFeedsMutation() + const {hasSession} = useSession() /** * A search query is present. We may not have search results yet. @@ -180,50 +182,52 @@ export const FeedsScreen = withAuthRequired( const items = React.useMemo(() => { let slices: FlatlistSlice[] = [] - slices.push({ - key: 'savedFeedsHeader', - type: 'savedFeedsHeader', - }) - - if (preferencesError) { + if (hasSession) { slices.push({ - key: 'savedFeedsError', - type: 'error', - error: cleanError(preferencesError.toString()), + key: 'savedFeedsHeader', + type: 'savedFeedsHeader', }) - } else { - if (isPreferencesLoading || !preferences?.feeds?.saved) { + + if (preferencesError) { slices.push({ - key: 'savedFeedsLoading', - type: 'savedFeedsLoading', - // pendingItems: this.rootStore.preferences.savedFeeds.length || 3, + key: 'savedFeedsError', + type: 'error', + error: cleanError(preferencesError.toString()), }) } else { - if (preferences?.feeds?.saved.length === 0) { + if (isPreferencesLoading || !preferences?.feeds?.saved) { slices.push({ - key: 'savedFeedNoResults', - type: 'savedFeedNoResults', + key: 'savedFeedsLoading', + type: 'savedFeedsLoading', + // pendingItems: this.rootStore.preferences.savedFeeds.length || 3, }) } else { - const {saved, pinned} = preferences.feeds + if (preferences?.feeds?.saved.length === 0) { + slices.push({ + key: 'savedFeedNoResults', + type: 'savedFeedNoResults', + }) + } else { + const {saved, pinned} = preferences.feeds - slices = slices.concat( - pinned.map(uri => ({ - key: `savedFeed:${uri}`, - type: 'savedFeed', - feedUri: uri, - })), - ) - - slices = slices.concat( - saved - .filter(uri => !pinned.includes(uri)) - .map(uri => ({ + slices = slices.concat( + pinned.map(uri => ({ key: `savedFeed:${uri}`, type: 'savedFeed', feedUri: uri, })), - ) + ) + + slices = slices.concat( + saved + .filter(uri => !pinned.includes(uri)) + .map(uri => ({ + key: `savedFeed:${uri}`, + type: 'savedFeed', + feedUri: uri, + })), + ) + } } } } @@ -307,6 +311,7 @@ export const FeedsScreen = withAuthRequired( return slices }, [ + hasSession, preferences, isPreferencesLoading, preferencesError, @@ -393,7 +398,8 @@ export const FeedsScreen = withAuthRequired( pal.view, styles.header, { - marginTop: 16, + // This is first in the flatlist without a session -esb + marginTop: hasSession ? 16 : 0, paddingLeft: isMobile ? 12 : undefined, paddingRight: 10, paddingBottom: isMobile ? 6 : undefined, @@ -432,7 +438,7 @@ export const FeedsScreen = withAuthRequired( return ( @@ -455,6 +461,7 @@ export const FeedsScreen = withAuthRequired( }, [ _, + hasSession, isMobile, pal, query, diff --git a/src/view/screens/ProfileFeed.tsx b/src/view/screens/ProfileFeed.tsx index 2cdcdb3b..28a61bea 100644 --- a/src/view/screens/ProfileFeed.tsx +++ b/src/view/screens/ProfileFeed.tsx @@ -165,7 +165,7 @@ export function ProfileFeedScreenInner({ }) { const {_} = useLingui() const pal = usePalette('default') - const {currentAccount} = useSession() + const {hasSession, currentAccount} = useSession() const {openModal} = useModalControls() const {openComposer} = useComposerControls() const {track} = useAnalytics() @@ -270,7 +270,7 @@ export function ProfileFeedScreenInner({ const dropdownItems: DropdownItem[] = React.useMemo(() => { return [ - { + hasSession && { testID: 'feedHeaderDropdownToggleSavedBtn', label: isSaved ? _(msg`Remove from my feeds`) : _(msg`Add to my feeds`), onPress: isSavePending || isRemovePending ? undefined : onToggleSaved, @@ -290,7 +290,7 @@ export function ProfileFeedScreenInner({ web: 'plus', }, }, - { + hasSession && { testID: 'feedHeaderDropdownReportBtn', label: _(msg`Report feed`), onPress: onPressReport, @@ -314,8 +314,9 @@ export function ProfileFeedScreenInner({ web: 'share', }, }, - ] as DropdownItem[] + ].filter(Boolean) as DropdownItem[] }, [ + hasSession, onToggleSaved, onPressReport, onPressShare, @@ -339,7 +340,7 @@ export function ProfileFeedScreenInner({ : undefined } avatarType="algo"> - {feedInfo && ( + {feedInfo && hasSession && ( <>