move onboarding to screens

This commit is contained in:
Ansh Nanda 2023-08-28 13:37:44 -07:00
parent 84e065667a
commit edfd326069
11 changed files with 149 additions and 107 deletions

View file

@ -1,66 +0,0 @@
import React from 'react'
import {StyleSheet, View} from 'react-native'
import {usePalette} from 'lib/hooks/usePalette'
import {Welcome} from './Welcome'
import {useStores} from 'state/index'
import {track} from 'lib/analytics/analytics'
enum OnboardingStep {
WELCOME = 'WELCOME',
// SELECT_INTERESTS = 'SELECT_INTERESTS',
COMPLETE = 'COMPLETE',
}
type OnboardingState = {
currentStep: OnboardingStep
}
type Action = {type: 'NEXT_STEP'}
const initialState: OnboardingState = {
currentStep: OnboardingStep.WELCOME,
}
const reducer = (state: OnboardingState, action: Action): OnboardingState => {
switch (action.type) {
case 'NEXT_STEP':
switch (state.currentStep) {
case OnboardingStep.WELCOME:
track('Onboarding:Begin')
return {...state, currentStep: OnboardingStep.COMPLETE}
case OnboardingStep.COMPLETE:
track('Onboarding:Complete')
return state
default:
return state
}
default:
return state
}
}
export const Onboarding = () => {
const pal = usePalette('default')
const rootStore = useStores()
const [state, dispatch] = React.useReducer(reducer, initialState)
const next = React.useCallback(
() => dispatch({type: 'NEXT_STEP'}),
[dispatch],
)
React.useEffect(() => {
if (state.currentStep === OnboardingStep.COMPLETE) {
// navigate to home
rootStore.shell.closeModal()
}
}, [state.currentStep, rootStore.shell])
return (
<View style={[pal.view, styles.container]}>
{state.currentStep === OnboardingStep.WELCOME && <Welcome next={next} />}
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingHorizontal: 20,
},
})

View file

@ -0,0 +1,55 @@
import React from 'react'
import {StyleSheet, View} from 'react-native'
import {Text} from 'view/com/util/text/Text'
import {usePalette} from 'lib/hooks/usePalette'
import {Button} from 'view/com/util/forms/Button'
import {NativeStackScreenProps} from '@react-navigation/native-stack'
import {HomeTabNavigatorParams} from 'lib/routes/types'
import {useStores} from 'state/index'
import {observer} from 'mobx-react-lite'
type Props = NativeStackScreenProps<HomeTabNavigatorParams, 'RecommendedFeeds'>
export const RecommendedFeeds = observer(({navigation}: Props) => {
const pal = usePalette('default')
const store = useStores()
const next = () => {
const nextScreenName = store.onboarding.nextScreenName()
console.log('nextScreenName', store.onboarding.nextScreenName())
if (nextScreenName) {
navigation.navigate(nextScreenName)
}
}
return (
<View style={[styles.container]}>
<View testID="recommendedFeedsScreen">
<Text type="lg-bold" style={[pal.text]}>
Check out some recommended feeds. Click + to add them to your list of
pinned feeds.
</Text>
</View>
<Button
onPress={next}
label="Continue"
testID="continueBtn"
labelStyle={styles.buttonText}
/>
</View>
)
})
const styles = StyleSheet.create({
container: {
flex: 1,
marginVertical: 60,
marginHorizontal: 16,
justifyContent: 'space-between',
},
buttonText: {
textAlign: 'center',
fontSize: 18,
marginVertical: 4,
},
})

View file

@ -5,9 +5,23 @@ import {s} from 'lib/styles'
import {usePalette} from 'lib/hooks/usePalette'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {Button} from 'view/com/util/forms/Button'
import {NativeStackScreenProps} from '@react-navigation/native-stack'
import {HomeTabNavigatorParams} from 'lib/routes/types'
import {useStores} from 'state/index'
import {observer} from 'mobx-react-lite'
export const Welcome = ({next}: {next: () => void}) => {
type Props = NativeStackScreenProps<HomeTabNavigatorParams, 'Welcome'>
export const Welcome = observer(({navigation}: Props) => {
const pal = usePalette('default')
const store = useStores()
const next = () => {
const nextScreenName = store.onboarding.nextScreenName()
if (nextScreenName) {
navigation.navigate(nextScreenName)
}
}
return (
<View style={[styles.container]}>
<View testID="welcomeScreen">
@ -60,12 +74,13 @@ export const Welcome = ({next}: {next: () => void}) => {
/>
</View>
)
}
})
const styles = StyleSheet.create({
container: {
flex: 1,
marginVertical: 60,
marginHorizontal: 16,
justifyContent: 'space-between',
},
title: {