Fix blank home screen (close #2281) (#2291)

zio/stable
Paul Frazee 2023-12-24 10:00:29 -08:00 committed by GitHub
parent 64bad57eb3
commit fe0a35cbea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -218,11 +218,13 @@ const FOLLOWING_FEED_STUB: FeedSourceInfo = {
export function usePinnedFeedsInfos(): { export function usePinnedFeedsInfos(): {
feeds: FeedSourceInfo[] feeds: FeedSourceInfo[]
hasPinnedCustom: boolean hasPinnedCustom: boolean
isLoading: boolean
} { } {
const queryClient = useQueryClient() const queryClient = useQueryClient()
const [tabs, setTabs] = React.useState<FeedSourceInfo[]>([ const [tabs, setTabs] = React.useState<FeedSourceInfo[]>([
FOLLOWING_FEED_STUB, FOLLOWING_FEED_STUB,
]) ])
const [isLoading, setLoading] = React.useState(true)
const {data: preferences} = usePreferencesQuery() const {data: preferences} = usePreferencesQuery()
const hasPinnedCustom = React.useMemo<boolean>(() => { const hasPinnedCustom = React.useMemo<boolean>(() => {
@ -284,10 +286,11 @@ export function usePinnedFeedsInfos(): {
) as FeedSourceInfo[] ) as FeedSourceInfo[]
setTabs([FOLLOWING_FEED_STUB].concat(views)) setTabs([FOLLOWING_FEED_STUB].concat(views))
setLoading(false)
} }
fetchFeedInfo() fetchFeedInfo()
}, [queryClient, setTabs, preferences?.feeds?.pinned]) }, [queryClient, setTabs, preferences?.feeds?.pinned])
return {feeds: tabs, hasPinnedCustom} return {feeds: tabs, hasPinnedCustom, isLoading}
} }

View File

@ -18,11 +18,13 @@ import {emitSoftReset} from '#/state/events'
import {useSession} from '#/state/session' import {useSession} from '#/state/session'
import {loadString, saveString} from '#/lib/storage' import {loadString, saveString} from '#/lib/storage'
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries' import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
import {clamp} from '#/lib/numbers'
type Props = NativeStackScreenProps<HomeTabNavigatorParams, 'Home'> type Props = NativeStackScreenProps<HomeTabNavigatorParams, 'Home'>
export function HomeScreen(props: Props) { export function HomeScreen(props: Props) {
const {data: preferences} = usePreferencesQuery() const {data: preferences} = usePreferencesQuery()
const {feeds: pinnedFeeds} = usePinnedFeedsInfos() const {feeds: pinnedFeeds, isLoading: isPinnedFeedsLoading} =
usePinnedFeedsInfos()
const {isDesktop} = useWebMediaQueries() const {isDesktop} = useWebMediaQueries()
const [initialPage, setInitialPage] = React.useState<string | undefined>( const [initialPage, setInitialPage] = React.useState<string | undefined>(
undefined, undefined,
@ -41,7 +43,12 @@ export function HomeScreen(props: Props) {
loadLastActivePage() loadLastActivePage()
}, []) }, [])
if (preferences && pinnedFeeds && initialPage !== undefined) { if (
preferences &&
pinnedFeeds &&
initialPage !== undefined &&
!isPinnedFeedsLoading
) {
return ( return (
<HomeScreenReady <HomeScreenReady
{...props} {...props}
@ -172,7 +179,7 @@ function HomeScreenReady({
<Pager <Pager
key={pinnedFeedOrderKey} key={pinnedFeedOrderKey}
testID="homeScreen" testID="homeScreen"
initialPage={selectedPageIndex} initialPage={clamp(selectedPageIndex, 0, customFeeds.length)}
onPageSelected={onPageSelected} onPageSelected={onPageSelected}
onPageScrollStateChanged={onPageScrollStateChanged} onPageScrollStateChanged={onPageScrollStateChanged}
renderTabBar={renderTabBar} renderTabBar={renderTabBar}