land on the correct feed

This commit is contained in:
Hailey
2024-06-10 13:01:13 -07:00
parent 402d65ab42
commit 179c7829a9
4 changed files with 28 additions and 4 deletions
+7 -1
View File
@@ -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')
+1
View File
@@ -92,6 +92,7 @@ export const schema = z.object({
.object({
uri: z.string(),
cid: z.string(),
initialFeed: z.string().optional(),
})
.optional(),
})
+1 -1
View File
@@ -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<StateContext>(undefined)
+19 -2
View File
@@ -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<PagerRef>(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()