diff --git a/src/screens/Onboarding/StepFinished.tsx b/src/screens/Onboarding/StepFinished.tsx index 6ea170f980..b845e58924 100644 --- a/src/screens/Onboarding/StepFinished.tsx +++ b/src/screens/Onboarding/StepFinished.tsx @@ -132,6 +132,13 @@ export function StepFinished() { })(), requestNotificationsPermission('AfterOnboarding'), ]) + + if (usedStarterPack) { + setUsedStarterPack({ + ...usedStarterPack, + initialFeed: starterPack?.feeds?.[0].uri ?? undefined, + }) + } } catch (e: any) { logger.info(`onboarding: bulk save failed`) logger.error(e) @@ -152,7 +159,6 @@ export function StepFinished() { }) setSaving(false) - setUsedStarterPack(undefined) dispatch({type: 'finish'}) onboardDispatch({type: 'finish'}) track('OnboardingV2:StepFinished:End') diff --git a/src/state/persisted/schema.ts b/src/state/persisted/schema.ts index 78e90760a9..e32a9979e4 100644 --- a/src/state/persisted/schema.ts +++ b/src/state/persisted/schema.ts @@ -92,6 +92,7 @@ export const schema = z.object({ .object({ uri: z.string(), cid: z.string(), + initialFeed: z.string().optional(), }) .optional(), }) diff --git a/src/state/preferences/starter-pack.tsx b/src/state/preferences/starter-pack.tsx index be1832fe42..33fa190869 100644 --- a/src/state/preferences/starter-pack.tsx +++ b/src/state/preferences/starter-pack.tsx @@ -2,7 +2,7 @@ import React from 'react' import * as persisted from '#/state/persisted' -type StateContext = {uri: string; cid: string} | undefined +type StateContext = {uri: string; cid: string; initialFeed?: string} | undefined type SetContext = (v: StateContext) => void const stateContext = React.createContext(undefined) diff --git a/src/view/screens/Home.tsx b/src/view/screens/Home.tsx index 34d3abf266..41d8bfe98a 100644 --- a/src/view/screens/Home.tsx +++ b/src/view/screens/Home.tsx @@ -21,6 +21,10 @@ import { import {useSelectedFeed, useSetSelectedFeed} from '#/state/shell/selected-feed' import {useOTAUpdates} from 'lib/hooks/useOTAUpdates' import {HomeTabNavigatorParams, NativeStackScreenProps} from 'lib/routes/types' +import { + useSetUsedStarterPack, + useUsedStarterPack, +} from 'state/preferences/starter-pack' import {FeedPage} from 'view/com/feeds/FeedPage' import {Pager, PagerRef, RenderTabBarFnProps} from 'view/com/pager/Pager' import {CustomFeedEmptyState} from 'view/com/posts/CustomFeedEmptyState' @@ -67,6 +71,8 @@ function HomeScreenReady({ const maybeFoundIndex = allFeeds.indexOf(rawSelectedFeed) const selectedIndex = Math.max(0, maybeFoundIndex) const selectedFeed = allFeeds[selectedIndex] + const usedStarterPack = useUsedStarterPack() + const setUsedStarterPack = useSetUsedStarterPack() useSetTitle(pinnedFeedInfos[selectedIndex]?.displayName) useOTAUpdates() @@ -74,14 +80,25 @@ function HomeScreenReady({ const pagerRef = React.useRef(null) const lastPagerReportedIndexRef = React.useRef(selectedIndex) React.useLayoutEffect(() => { + let initialIndex = selectedIndex + if (usedStarterPack) { + initialIndex = allFeeds.findIndex( + f => f === `feedgen|${usedStarterPack.initialFeed}`, + ) + setUsedStarterPack(undefined) + } + // Since the pager is not a controlled component, adjust it imperatively // if the selected index gets out of sync with what it last reported. // This is supposed to only happen on the web when you use the right nav. - if (selectedIndex !== lastPagerReportedIndexRef.current) { + if (initialIndex !== selectedIndex) { + lastPagerReportedIndexRef.current = initialIndex + pagerRef.current?.setPage(initialIndex, 'desktop-sidebar-click') + } else if (selectedIndex !== lastPagerReportedIndexRef.current) { lastPagerReportedIndexRef.current = selectedIndex pagerRef.current?.setPage(selectedIndex, 'desktop-sidebar-click') } - }, [selectedIndex]) + }, [selectedIndex, usedStarterPack, setUsedStarterPack, allFeeds]) const {hasSession} = useSession() const setMinimalShellMode = useSetMinimalShellMode()