From fa004bc8df271cc20be21be82a417fb4b349caed Mon Sep 17 00:00:00 2001 From: Hailey Date: Sun, 16 Jun 2024 23:05:04 -0700 Subject: [PATCH] better handling --- src/screens/Onboarding/StepFinished.tsx | 41 +++++++++++++++---------- src/view/screens/Home.tsx | 11 +++---- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/screens/Onboarding/StepFinished.tsx b/src/screens/Onboarding/StepFinished.tsx index b925f97a69..e9d26a4c67 100644 --- a/src/screens/Onboarding/StepFinished.tsx +++ b/src/screens/Onboarding/StepFinished.tsx @@ -83,14 +83,26 @@ export function StepFinished() { (async () => { // Interests need to get saved first, then we can write the feeds to prefs await agent.setInterestsPref({tags: selectedInterests}) - if (starterPack?.feeds?.length) { - await agent.addSavedFeeds( - starterPack.feeds.map(f => ({ - type: 'feed', - value: f.uri, - pinned: true, - })), - ) + if (starterPack) { + if (starterPack.feeds?.length) { + await agent.addSavedFeeds( + starterPack.feeds.map(f => ({ + type: 'feed', + value: f.uri, + pinned: true, + })), + ) + setCurrentStarterPack({ + uri: '', + initialFeed: starterPack.feeds?.[0].uri, + }) + } else { + setCurrentStarterPack({ + uri: '', + initialFeed: 'following', + }) + } + addUsedStarterPack(makeStarterPackLink(starterPack)) } })(), (async () => { @@ -135,17 +147,12 @@ export function StepFinished() { })(), requestNotificationsPermission('AfterOnboarding'), ]) - - if (currentStarterPack && starterPack) { - setCurrentStarterPack({ - ...currentStarterPack, - initialFeed: starterPack?.feeds?.[0].uri ?? 'following', - }) - addUsedStarterPack(makeStarterPackLink(starterPack)) - } } catch (e: any) { logger.info(`onboarding: bulk save failed`) logger.error(e) + // If there was an error encountered, we need to just clear the starter pack so we don't break things for subsequent + // app restarts + setCurrentStarterPack(undefined) // don't alert the user, just let them into their account } @@ -177,8 +184,8 @@ export function StepFinished() { currentStarterPack, state, requestNotificationsPermission, - setCurrentStarterPack, addUsedStarterPack, + setCurrentStarterPack, ]) React.useEffect(() => { diff --git a/src/view/screens/Home.tsx b/src/view/screens/Home.tsx index 5447faed01..ef7e962d15 100644 --- a/src/view/screens/Home.tsx +++ b/src/view/screens/Home.tsx @@ -105,13 +105,10 @@ function HomeScreenReady({ 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 = 1 + } else if (allFeeds.length >= 3) { + initialIndex = 2 + } else if (initialIndex === -1) { initialIndex = 0 } setCurrentStarterPack(undefined)