Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300import {useEffect, useReducer, useState} from 'react'import {AppState, type AppStateStatus, Platform, View} from 'react-native'import ReactNativeDeviceAttest from 'react-native-device-attest'import Animated, {FadeIn, LayoutAnimationConfig} from 'react-native-reanimated'import {AppBskyGraphStarterpack} from '@atproto/api'import {msg} from '@lingui/core/macro'import {useLingui} from '@lingui/react'import {Trans} from '@lingui/react/macro'
import {useBrand} from '#/lib/community/BrandContext'import {FEEDBACK_FORM_URL} from '#/lib/constants'import {logger} from '#/logger'import {useServiceQuery} from '#/state/queries/service'import {useStarterPackQuery} from '#/state/queries/starter-packs'import {useActiveStarterPack} from '#/state/shell/landing'import {LoggedOutLayout} from '#/view/com/util/layouts/LoggedOutLayout'import { initialState, reducer, SignupContext, SignupStep, useSubmitSignup,} from '#/screens/Signup/state'import {StepCaptcha} from '#/screens/Signup/StepCaptcha'import {StepCommunity} from '#/screens/Signup/StepCommunity'import {StepHandle} from '#/screens/Signup/StepHandle'import {StepInfo} from '#/screens/Signup/StepInfo'import {atoms as a, native, useBreakpoints, useTheme} from '#/alf'import {AppLanguageDropdown} from '#/components/AppLanguageDropdown'import {Divider} from '#/components/Divider'import {LinearGradientBackground} from '#/components/LinearGradientBackground'import {InlineLinkText} from '#/components/Link'import {ScreenTransition} from '#/components/ScreenTransition'import {Text} from '#/components/Typography'import {useAnalytics} from '#/analytics'import {GCP_PROJECT_ID, IS_ANDROID} from '#/env'import * as bsky from '#/types/bsky'
export function Signup({ onPressBack, onPressSignIn,}: { onPressBack: () => void onPressSignIn?: (handle: string) => void}) { const ax = useAnalytics() const {_} = useLingui() const brand = useBrand() const t = useTheme() const [state, dispatch] = useReducer(reducer, { ...initialState, analytics: ax, }) const {gtMobile} = useBreakpoints() const submit = useSubmitSignup()
useEffect(() => { dispatch({ type: 'setAnalytics', value: ax, }) }, [ax])
// Point signup at the brand-configured PDS instead of the hardcoded default. // On web the community is fixed by the hostname (there is no picker step), so // also stamp its slug up front the way the picker would on native. useEffect(() => { if (brand.services.pds.url) { if (Platform.OS === 'web') { dispatch({ type: 'setCommunity', slug: brand.metadata.slug, serviceUrl: brand.services.pds.url, }) } else { dispatch({type: 'setServiceUrl', value: brand.services.pds.url}) } } }, [brand.services.pds.url, brand.metadata.slug])
const activeStarterPack = useActiveStarterPack() const { data: starterPack, isFetching: isFetchingStarterPack, isError: isErrorStarterPack, } = useStarterPackQuery({ uri: activeStarterPack?.uri, })
const [isFetchedAtMount] = useState(starterPack != null) const showStarterPackCard = activeStarterPack?.uri && !isFetchingStarterPack && starterPack
const { data: serviceInfo, isFetching, isError, refetch, } = useServiceQuery(state.serviceUrl)
useEffect(() => { if (isFetching) { dispatch({type: 'setIsLoading', value: true}) } else if (!isFetching) { dispatch({type: 'setIsLoading', value: false}) } }, [isFetching])
useEffect(() => { if (isError) { dispatch({ type: 'setServiceDescription', value: undefined, availableHandles: brand.services.pds.availableHandles, }) dispatch({ type: 'setError', value: _( msg`Unable to contact your service. Please check your Internet connection.`, ), }) } else if (serviceInfo) { dispatch({ type: 'setServiceDescription', value: serviceInfo, availableHandles: brand.services.pds.availableHandles, }) dispatch({type: 'setError', value: ''}) } }, [_, serviceInfo, isError, brand.services.pds.availableHandles])
useEffect(() => { if (state.pendingSubmit) { if (!state.pendingSubmit.mutableProcessed) { state.pendingSubmit.mutableProcessed = true submit(state, dispatch) } } }, [state, dispatch, submit])
// Track app backgrounding during signup useEffect(() => { const subscription = AppState.addEventListener( 'change', (nextAppState: AppStateStatus) => { if (nextAppState === 'background') { dispatch({type: 'incrementBackgroundCount'}) } }, )
return () => subscription.remove() }, [])
// On Android, warmup the Play Integrity API on the signup screen so it is ready by the time we get to the gate screen. useEffect(() => { if (!IS_ANDROID) { return } ReactNativeDeviceAttest.warmupIntegrity(GCP_PROJECT_ID).catch(err => logger.error(err), ) }, [])
// Web skips the community-picker step, so shift the displayed step numbering // down by one to keep the count starting at "Step 1". const isWeb = Platform.OS === 'web' const stepOffset = isWeb ? 1 : 0 const totalSteps = state.serviceDescription && !state.serviceDescription.phoneVerificationRequired ? 3 : 4 const displayStep = state.activeStep + 1 - stepOffset const displayTotal = totalSteps - stepOffset
return ( <Animated.View exiting={native(FadeIn.duration(90))} style={a.flex_1}> <SignupContext.Provider value={{state, dispatch}}> <LoggedOutLayout leadin="" title={_(msg`Create Account`)} description={brand.messages.welcomeMessage} scrollable> <View testID="createAccount" style={a.flex_1}> {showStarterPackCard && bsky.dangerousIsType<AppBskyGraphStarterpack.Record>( starterPack.record, AppBskyGraphStarterpack.isRecord, ) ? ( <Animated.View entering={!isFetchedAtMount ? FadeIn : undefined}> <LinearGradientBackground style={[a.mx_lg, a.p_lg, a.gap_sm, a.rounded_sm]}> <Text style={[a.font_semi_bold, a.text_xl, {color: 'white'}]}> {starterPack.record.name} </Text> <Text style={[{color: 'white'}]}> {starterPack.feeds?.length ? ( <Trans> You'll follow the suggested users and feeds once you finish creating your account! </Trans> ) : ( <Trans> You'll follow the suggested users once you finish creating your account! </Trans> )} </Text> </LinearGradientBackground> </Animated.View> ) : null} <LayoutAnimationConfig skipEntering> <ScreenTransition key={state.activeStep} direction={state.screenTransitionDirection}> <View style={[ a.flex_1, a.px_xl, a.pt_2xl, !gtMobile && {paddingBottom: 100}, ]}> <View style={[a.gap_sm, a.pb_3xl]}> <Text style={[a.font_semi_bold, t.atoms.text_contrast_medium]}> <Trans> Step {displayStep} of {displayTotal} </Trans> </Text> <Text style={[a.text_3xl, a.font_semi_bold]}> {state.activeStep === SignupStep.COMMUNITY ? ( <Trans>Choose your community</Trans> ) : state.activeStep === SignupStep.INFO ? ( <Trans>Your account</Trans> ) : state.activeStep === SignupStep.HANDLE ? ( <Trans>Choose your username</Trans> ) : ( <Trans>Complete the challenge</Trans> )} </Text> </View>
{state.activeStep === SignupStep.COMMUNITY ? ( <StepCommunity onPressBack={onPressBack} /> ) : state.activeStep === SignupStep.INFO ? ( <StepInfo onPressBack={ // On web INFO is the first step, so back exits signup; // on native it returns to the community picker. isWeb ? onPressBack : () => dispatch({type: 'prev'}) } isLoadingStarterPack={ isFetchingStarterPack && !isErrorStarterPack } isServerError={isError} refetchServer={refetch} /> ) : state.activeStep === SignupStep.HANDLE ? ( <StepHandle onPressSignIn={onPressSignIn} /> ) : ( <StepCaptcha /> )}
<Divider />
<View style={[ a.w_full, a.py_lg, a.flex_row, a.gap_md, a.align_center, ]}> <AppLanguageDropdown /> <Text style={[ a.flex_1, t.atoms.text_contrast_medium, !gtMobile && a.text_md, ]}> <Trans>Having trouble?</Trans>{' '} <InlineLinkText label={_(msg`Contact support`)} to={FEEDBACK_FORM_URL({email: state.email})} style={[!gtMobile && a.text_md]}> <Trans>Contact support</Trans> </InlineLinkText> </Text> </View> </View> </ScreenTransition> </LayoutAnimationConfig> </View> </LoggedOutLayout> </SignupContext.Provider> </Animated.View> )}