fix initial index selecton
This commit is contained in:
+16
-17
@@ -95,14 +95,27 @@ function HomeScreenReady({
|
|||||||
() => pinnedFeedInfos.map(f => f.feedDescriptor),
|
() => pinnedFeedInfos.map(f => f.feedDescriptor),
|
||||||
[pinnedFeedInfos],
|
[pinnedFeedInfos],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const currentStarterPack = useCurrentStarterPack()
|
||||||
|
const setCurrentStarterPack = useSetCurrentStarterPack()
|
||||||
|
|
||||||
|
const starterPackInitialFeed = currentStarterPack?.initialFeed
|
||||||
|
? allFeeds.find(f => {
|
||||||
|
if (currentStarterPack.initialFeed === 'following') {
|
||||||
|
return f === 'following'
|
||||||
|
} else {
|
||||||
|
return f === `feedgen|${currentStarterPack.initialFeed}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
: undefined
|
||||||
const rawSelectedFeed = useSelectedFeed() ?? allFeeds[0]
|
const rawSelectedFeed = useSelectedFeed() ?? allFeeds[0]
|
||||||
const setSelectedFeed = useSetSelectedFeed()
|
const setSelectedFeed = useSetSelectedFeed()
|
||||||
const maybeFoundIndex = allFeeds.indexOf(rawSelectedFeed)
|
const maybeFoundIndex = allFeeds.indexOf(
|
||||||
|
starterPackInitialFeed ?? rawSelectedFeed,
|
||||||
|
)
|
||||||
const selectedIndex = Math.max(0, maybeFoundIndex)
|
const selectedIndex = Math.max(0, maybeFoundIndex)
|
||||||
const selectedFeed = allFeeds[selectedIndex]
|
const selectedFeed = allFeeds[selectedIndex]
|
||||||
const requestNotificationsPermission = useRequestNotificationsPermission()
|
const requestNotificationsPermission = useRequestNotificationsPermission()
|
||||||
const currentStarterPack = useCurrentStarterPack()
|
|
||||||
const setCurrentStarterPack = useSetCurrentStarterPack()
|
|
||||||
|
|
||||||
useSetTitle(pinnedFeedInfos[selectedIndex]?.displayName)
|
useSetTitle(pinnedFeedInfos[selectedIndex]?.displayName)
|
||||||
useOTAUpdates()
|
useOTAUpdates()
|
||||||
@@ -115,20 +128,6 @@ function HomeScreenReady({
|
|||||||
const lastPagerReportedIndexRef = React.useRef(selectedIndex)
|
const lastPagerReportedIndexRef = React.useRef(selectedIndex)
|
||||||
React.useLayoutEffect(() => {
|
React.useLayoutEffect(() => {
|
||||||
let initialIndex = selectedIndex
|
let initialIndex = selectedIndex
|
||||||
if (currentStarterPack?.initialFeed) {
|
|
||||||
if (currentStarterPack.initialFeed === 'following') {
|
|
||||||
initialIndex = allFeeds.findIndex(f => f === 'following')
|
|
||||||
} else {
|
|
||||||
initialIndex = allFeeds.findIndex(
|
|
||||||
f => f === `feedgen|${currentStarterPack.initialFeed}`,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (initialIndex === -1) {
|
|
||||||
initialIndex = 0
|
|
||||||
}
|
|
||||||
setCurrentStarterPack(undefined)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Since the pager is not a controlled component, adjust it imperatively
|
// Since the pager is not a controlled component, adjust it imperatively
|
||||||
// if the selected index gets out of sync with what it last reported.
|
// 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.
|
// This is supposed to only happen on the web when you use the right nav.
|
||||||
|
|||||||
Reference in New Issue
Block a user