From fe0a35cbea7ff8430f9538d6a641e41ab74ed0a0 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Sun, 24 Dec 2023 10:00:29 -0800 Subject: [PATCH] Fix blank home screen (close #2281) (#2291) --- src/state/queries/feed.ts | 5 ++++- src/view/screens/Home.tsx | 13 ++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/state/queries/feed.ts b/src/state/queries/feed.ts index c87e95f030..7a55b4e186 100644 --- a/src/state/queries/feed.ts +++ b/src/state/queries/feed.ts @@ -218,11 +218,13 @@ const FOLLOWING_FEED_STUB: FeedSourceInfo = { export function usePinnedFeedsInfos(): { feeds: FeedSourceInfo[] hasPinnedCustom: boolean + isLoading: boolean } { const queryClient = useQueryClient() const [tabs, setTabs] = React.useState([ FOLLOWING_FEED_STUB, ]) + const [isLoading, setLoading] = React.useState(true) const {data: preferences} = usePreferencesQuery() const hasPinnedCustom = React.useMemo(() => { @@ -284,10 +286,11 @@ export function usePinnedFeedsInfos(): { ) as FeedSourceInfo[] setTabs([FOLLOWING_FEED_STUB].concat(views)) + setLoading(false) } fetchFeedInfo() }, [queryClient, setTabs, preferences?.feeds?.pinned]) - return {feeds: tabs, hasPinnedCustom} + return {feeds: tabs, hasPinnedCustom, isLoading} } diff --git a/src/view/screens/Home.tsx b/src/view/screens/Home.tsx index 82dd1365cf..b8033f0b45 100644 --- a/src/view/screens/Home.tsx +++ b/src/view/screens/Home.tsx @@ -18,11 +18,13 @@ import {emitSoftReset} from '#/state/events' import {useSession} from '#/state/session' import {loadString, saveString} from '#/lib/storage' import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries' +import {clamp} from '#/lib/numbers' type Props = NativeStackScreenProps export function HomeScreen(props: Props) { const {data: preferences} = usePreferencesQuery() - const {feeds: pinnedFeeds} = usePinnedFeedsInfos() + const {feeds: pinnedFeeds, isLoading: isPinnedFeedsLoading} = + usePinnedFeedsInfos() const {isDesktop} = useWebMediaQueries() const [initialPage, setInitialPage] = React.useState( undefined, @@ -41,7 +43,12 @@ export function HomeScreen(props: Props) { loadLastActivePage() }, []) - if (preferences && pinnedFeeds && initialPage !== undefined) { + if ( + preferences && + pinnedFeeds && + initialPage !== undefined && + !isPinnedFeedsLoading + ) { return (