Fix blank feed (#1935)

* Split feed into two components

* Rm unused

* Add a spinner
zio/stable
dan 2023-11-16 22:37:48 +00:00 committed by GitHub
parent 8475312422
commit 22df70b3cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 18 deletions

View File

@ -1,4 +1,5 @@
import React from 'react' import React from 'react'
import {View, ActivityIndicator, StyleSheet} from 'react-native'
import {useFocusEffect} from '@react-navigation/native' import {useFocusEffect} from '@react-navigation/native'
import {NativeStackScreenProps, HomeTabNavigatorParams} from 'lib/routes/types' import {NativeStackScreenProps, HomeTabNavigatorParams} from 'lib/routes/types'
import {FeedDescriptor, FeedParams} from '#/state/queries/post-feed' import {FeedDescriptor, FeedParams} from '#/state/queries/post-feed'
@ -7,28 +8,41 @@ import {FollowingEmptyState} from 'view/com/posts/FollowingEmptyState'
import {FollowingEndOfFeed} from 'view/com/posts/FollowingEndOfFeed' import {FollowingEndOfFeed} from 'view/com/posts/FollowingEndOfFeed'
import {CustomFeedEmptyState} from 'view/com/posts/CustomFeedEmptyState' import {CustomFeedEmptyState} from 'view/com/posts/CustomFeedEmptyState'
import {FeedsTabBar} from '../com/pager/FeedsTabBar' import {FeedsTabBar} from '../com/pager/FeedsTabBar'
import {Pager, PagerRef, RenderTabBarFnProps} from 'view/com/pager/Pager' import {Pager, RenderTabBarFnProps} from 'view/com/pager/Pager'
import {FeedPage} from 'view/com/feeds/FeedPage' import {FeedPage} from 'view/com/feeds/FeedPage'
import {useSetMinimalShellMode, useSetDrawerSwipeDisabled} from '#/state/shell' import {useSetMinimalShellMode, useSetDrawerSwipeDisabled} from '#/state/shell'
import {usePreferencesQuery} from '#/state/queries/preferences' import {usePreferencesQuery} from '#/state/queries/preferences'
import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types'
import {emitSoftReset} from '#/state/events' import {emitSoftReset} from '#/state/events'
type Props = NativeStackScreenProps<HomeTabNavigatorParams, 'Home'> type Props = NativeStackScreenProps<HomeTabNavigatorParams, 'Home'>
export const HomeScreen = withAuthRequired(function HomeScreenImpl({}: Props) { export const HomeScreen = withAuthRequired(function HomeScreenImpl(
props: Props,
) {
const {data: preferences} = usePreferencesQuery()
if (preferences) {
return <HomeScreenReady {...props} preferences={preferences} />
} else {
return (
<View style={styles.loading}>
<ActivityIndicator size="large" />
</View>
)
}
})
function HomeScreenReady({
preferences,
}: Props & {
preferences: UsePreferencesQueryResponse
}) {
const setMinimalShellMode = useSetMinimalShellMode() const setMinimalShellMode = useSetMinimalShellMode()
const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled() const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled()
const pagerRef = React.useRef<PagerRef>(null)
const [selectedPage, setSelectedPage] = React.useState(0) const [selectedPage, setSelectedPage] = React.useState(0)
const [customFeeds, setCustomFeeds] = React.useState<FeedDescriptor[]>([])
const {data: preferences} = usePreferencesQuery()
React.useEffect(() => {
if (!preferences?.feeds?.pinned) return
const customFeeds = React.useMemo(() => {
const pinned = preferences.feeds.pinned const pinned = preferences.feeds.pinned
const feeds: FeedDescriptor[] = [] const feeds: FeedDescriptor[] = []
for (const uri of pinned) { for (const uri of pinned) {
if (uri.includes('app.bsky.feed.generator')) { if (uri.includes('app.bsky.feed.generator')) {
feeds.push(`feedgen|${uri}`) feeds.push(`feedgen|${uri}`)
@ -36,15 +50,10 @@ export const HomeScreen = withAuthRequired(function HomeScreenImpl({}: Props) {
feeds.push(`list|${uri}`) feeds.push(`list|${uri}`)
} }
} }
return feeds
setCustomFeeds(feeds) }, [preferences.feeds.pinned])
pagerRef.current?.setPage(0)
}, [preferences?.feeds?.pinned, setCustomFeeds, pagerRef])
const homeFeedParams = React.useMemo<FeedParams>(() => { const homeFeedParams = React.useMemo<FeedParams>(() => {
if (!preferences) return {}
return { return {
mergeFeedEnabled: Boolean(preferences.feedViewPrefs.lab_mergeFeedEnabled), mergeFeedEnabled: Boolean(preferences.feedViewPrefs.lab_mergeFeedEnabled),
mergeFeedSources: preferences.feeds.saved, mergeFeedSources: preferences.feeds.saved,
@ -108,7 +117,6 @@ export const HomeScreen = withAuthRequired(function HomeScreenImpl({}: Props) {
return ( return (
<Pager <Pager
ref={pagerRef}
testID="homeScreen" testID="homeScreen"
onPageSelected={onPageSelected} onPageSelected={onPageSelected}
onPageScrollStateChanged={onPageScrollStateChanged} onPageScrollStateChanged={onPageScrollStateChanged}
@ -136,4 +144,13 @@ export const HomeScreen = withAuthRequired(function HomeScreenImpl({}: Props) {
})} })}
</Pager> </Pager>
) )
}
const styles = StyleSheet.create({
loading: {
height: '100%',
alignContent: 'center',
justifyContent: 'center',
paddingBottom: 100,
},
}) })