import React from 'react' import {View} from 'react-native' import {useSafeAreaInsets} from 'react-native-safe-area-context' import {useLingui} from '@lingui/react' import {msg, Trans} from '@lingui/macro' import {useOnboardingDispatch} from '#/state/shell' import {getAgent, isSessionDeactivated, useSessionApi} from '#/state/session' import {logger} from '#/logger' import {pluralize} from '#/lib/strings/helpers' import {atoms as a, useTheme, useBreakpoints} from '#/alf' import {Button, ButtonIcon, ButtonText} from '#/components/Button' import {Text, P} from '#/components/Typography' import {isWeb} from '#/platform/detection' import {ScrollView} from '#/view/com/util/Views' import {Loader} from '#/components/Loader' import {Logo} from '#/view/icons/Logo' const COL_WIDTH = 400 export function Deactivated() { const {_} = useLingui() const t = useTheme() const insets = useSafeAreaInsets() const {gtMobile} = useBreakpoints() const onboardingDispatch = useOnboardingDispatch() const {logout} = useSessionApi() const [isProcessing, setProcessing] = React.useState(false) const [estimatedTime, setEstimatedTime] = React.useState( undefined, ) const [placeInQueue, setPlaceInQueue] = React.useState( undefined, ) const checkStatus = React.useCallback(async () => { setProcessing(true) try { const res = await getAgent().com.atproto.temp.checkSignupQueue() if (res.data.activated) { // ready to go, exchange the access token for a usable one and kick off onboarding await getAgent().refreshSession() if (!isSessionDeactivated(getAgent().session?.accessJwt)) { onboardingDispatch({type: 'start'}) } } else { // not ready, update UI setEstimatedTime(msToString(res.data.estimatedTimeMs)) if (typeof res.data.placeInQueue !== 'undefined') { setPlaceInQueue(Math.max(res.data.placeInQueue, 1)) } } } catch (e: any) { logger.error('Failed to check signup queue', {err: e.toString()}) } finally { setProcessing(false) } }, [setProcessing, setEstimatedTime, setPlaceInQueue, onboardingDispatch]) React.useEffect(() => { checkStatus() const interval = setInterval(checkStatus, 60e3) return () => clearInterval(interval) }, [checkStatus]) const checkBtn = ( ) return ( You're in line

There's been a rush of new users to Bluesky! We'll activate your account as soon as we can.

{typeof placeInQueue === 'number' && ( {placeInQueue} )}

{typeof placeInQueue === 'number' ? ( left to go. ) : ( You are in line. )}{' '} {estimatedTime ? ( We estimate {estimatedTime} until your account is ready. ) : ( We will let you know when your account is ready. )}

{isWeb && gtMobile && ( {checkBtn} )}
{(!isWeb || !gtMobile) && ( {checkBtn} )}
) } function msToString(ms: number | undefined): string | undefined { if (ms && ms > 0) { const estimatedTimeMins = Math.ceil(ms / 60e3) if (estimatedTimeMins > 59) { const estimatedTimeHrs = Math.round(estimatedTimeMins / 60) if (estimatedTimeHrs > 6) { // dont even bother return undefined } // hours return `${estimatedTimeHrs} ${pluralize(estimatedTimeHrs, 'hour')}` } // minutes return `${estimatedTimeMins} ${pluralize(estimatedTimeMins, 'minute')}` } return undefined }