diff --git a/src/App.web.tsx b/src/App.web.tsx index b8a493b5ee..5c4dc4e637 100644 --- a/src/App.web.tsx +++ b/src/App.web.tsx @@ -39,7 +39,6 @@ import {ToastContainer} from 'view/com/util/Toast.web' import {Shell} from 'view/shell/index' import {ThemeProvider as Alf} from '#/alf' import {useColorModeTheme} from '#/alf/util/useColorModeTheme' -import {useStarterPackEntry} from '#/components/hooks/useStarterPackEntry' import {Provider as PortalProvider} from '#/components/Portal' import {BackgroundNotificationPreferencesProvider} from '../modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider' import I18nProvider from './locale/i18nProvider' @@ -52,7 +51,6 @@ function InnerApp() { const theme = useColorModeTheme() const {_} = useLingui() useIntentHandler() - useStarterPackEntry() // init useEffect(() => { diff --git a/src/components/hooks/useStarterPackEntry.ts b/src/components/hooks/useStarterPackEntry.ts deleted file mode 100644 index 5dfb476eea..0000000000 --- a/src/components/hooks/useStarterPackEntry.ts +++ /dev/null @@ -1,15 +0,0 @@ -import React from 'react' - -import {useSetStarterPack} from 'state/preferences/starter-pack' - -export function useStarterPackEntry() { - const setStarterPack = useSetStarterPack() - - React.useEffect(() => { - const url = new URL(window.location.href) - const pathParts = url.pathname.split('/') - if (pathParts[0] === 'start' && pathParts.length === 2) { - setStarterPack(pathParts[1]) - } - }, [setStarterPack]) -} diff --git a/src/screens/Onboarding/StepFinished.tsx b/src/screens/Onboarding/StepFinished.tsx index c75dd4fa74..d48bf87d13 100644 --- a/src/screens/Onboarding/StepFinished.tsx +++ b/src/screens/Onboarding/StepFinished.tsx @@ -1,5 +1,6 @@ import React from 'react' import {View} from 'react-native' +import {AppBskyGraphDefs, AtUri} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useQueryClient} from '@tanstack/react-query' @@ -14,6 +15,10 @@ import {useAgent} from '#/state/session' import {useOnboardingDispatch} from '#/state/shell' import {uploadBlob} from 'lib/api' import {useRequestNotificationsPermission} from 'lib/notifications/notifications' +import { + useSetUsedStarterPack, + useUsedStarterPack, +} from 'state/preferences/starter-pack' import { DescriptionText, OnboardingControls, @@ -41,15 +46,49 @@ export function StepFinished() { const queryClient = useQueryClient() const agent = useAgent() const requestNotificationsPermission = useRequestNotificationsPermission() + const usedStarterPack = useUsedStarterPack() + const setUsedStarterPack = useSetUsedStarterPack() const finishOnboarding = React.useCallback(async () => { setSaving(true) - - const {interestsStepResults, profileStepResults} = state - const {selectedInterests} = interestsStepResults try { + let starterPack: AppBskyGraphDefs.StarterPackView | undefined + let listItems: AppBskyGraphDefs.ListItemView[] | undefined + if (usedStarterPack) { + const spRes = await agent.app.bsky.graph.getStarterPack({ + starterPack: usedStarterPack.uri, + }) + starterPack = spRes.data.starterPack + + if (starterPack.list) { + const listRes = await agent.app.bsky.graph.getList({ + list: starterPack.list.uri, + limit: 51, + }) + listItems = listRes.data.items + } + } + + const {interestsStepResults, profileStepResults} = state + const {selectedInterests} = interestsStepResults + await Promise.all([ - bulkWriteFollows(agent, [BSKY_APP_ACCOUNT_DID]), + bulkWriteFollows(agent, [ + BSKY_APP_ACCOUNT_DID, + ...(listItems?.map(i => i.subject.did) ?? []), + ]), + (async () => { + if (starterPack?.feeds?.length) { + await agent.addSavedFeeds( + starterPack.feeds.map(f => ({ + type: 'feed', + value: f.uri, + pinned: true, + id: new AtUri(f.uri).rkey, + })), + ) + } + })(), (async () => { await agent.setInterestsPref({tags: selectedInterests}) })(), @@ -63,9 +102,20 @@ export function StepFinished() { if (res.data.blob) { existing.avatar = res.data.blob } + + existing.createdAt = new Date().toISOString() + + if (starterPack) { + existing.joinedViaStarterPack = { + uri: starterPack.uri, + cid: starterPack.cid, + } + } + return existing }) } + logEvent('onboarding:finished:avatarResult', { avatarResult: profileStepResults.isCreatedAvatar ? 'created' @@ -96,6 +146,7 @@ export function StepFinished() { }) setSaving(false) + setUsedStarterPack(undefined) dispatch({type: 'finish'}) onboardDispatch({type: 'finish'}) track('OnboardingV2:StepFinished:End') @@ -105,10 +156,12 @@ export function StepFinished() { state, queryClient, agent, + setUsedStarterPack, dispatch, onboardDispatch, track, requestNotificationsPermission, + usedStarterPack, ]) React.useEffect(() => { diff --git a/src/screens/StarterPack/Landing/index.tsx b/src/screens/StarterPack/Landing/index.tsx index 25744a1e3f..52202b3ba4 100644 --- a/src/screens/StarterPack/Landing/index.tsx +++ b/src/screens/StarterPack/Landing/index.tsx @@ -8,10 +8,13 @@ import { } from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {NativeStackScreenProps} from '@react-navigation/native-stack' +import {useNavigation} from '@react-navigation/native' -import {CommonNavigatorParams} from 'lib/routes/types' +import {NavigationProp} from 'lib/routes/types' +import {useSetUsedStarterPack} from 'state/preferences/starter-pack' +import {useSession} from 'state/session' import {useSetMinimalShellMode} from 'state/shell' +import {useLoggedOutViewControls} from 'state/shell/logged-out' import {FeedSourceCard} from 'view/com/feeds/FeedSourceCard' import {UserAvatar} from 'view/com/util/UserAvatar' import {CenteredView} from 'view/com/util/Views' @@ -116,10 +119,10 @@ const mockSP = { ], } -export function LandingScreen({ - navigation, -}: NativeStackScreenProps) { +export function LandingScreen({}) { // const {name, rkey} = route.params + const navigation = useNavigation() + const {currentAccount} = useSession() const setMinimalShellMode = useSetMinimalShellMode() // const { @@ -134,11 +137,16 @@ export function LandingScreen({ // } = useStarterPackQuery({did, rkey}) React.useEffect(() => { + if (currentAccount) { + navigation.navigate('Home') + return + } + setMinimalShellMode(true) return () => { setMinimalShellMode(false) } - }, [navigation, setMinimalShellMode]) + }, [currentAccount, navigation, setMinimalShellMode]) // if (!did || !starterPack) { // return ( @@ -160,6 +168,8 @@ function LandingScreenInner({ const {record, creator, listItemsSample, feeds, joinedWeekCount} = starterPack const {_} = useLingui() const t = useTheme() + const {requestSwitchToAccount} = useLoggedOutViewControls() + const setUsedStarterPack = useSetUsedStarterPack() const gradient = t.name === 'light' @@ -205,7 +215,13 @@ function LandingScreenInner({ )}