import React from 'react' import { ActivityIndicator, Linking, StyleSheet, TouchableOpacity, } from 'react-native' import {CenteredView} from '../util/Views' import {LoggedOut} from './LoggedOut' import {Onboarding} from './Onboarding' import {Text} from '../util/text/Text' import {usePalette} from 'lib/hooks/usePalette' import {STATUS_PAGE_URL} from 'lib/constants' import {useOnboardingState} from '#/state/shell' import {useSession} from '#/state/session' import { useLoggedOutView, useLoggedOutViewControls, } from '#/state/shell/logged-out' import {IS_PROD} from '#/env' export const withAuthRequired =

( Component: React.ComponentType

, options: { isPublic?: boolean // TODO(pwi) need to enable in TF somehow } = {}, ): React.FC

=> function AuthRequired(props: P) { const {isInitialLoad, hasSession} = useSession() const onboardingState = useOnboardingState() const {showLoggedOut} = useLoggedOutView() const {setShowLoggedOut} = useLoggedOutViewControls() if (isInitialLoad) { return } if (!hasSession) { if (showLoggedOut) { return setShowLoggedOut(false)} /> } else if (!options?.isPublic || IS_PROD) { return } } if (onboardingState.isActive) { return } return } function Loading() { const pal = usePalette('default') const [isTakingTooLong, setIsTakingTooLong] = React.useState(false) React.useEffect(() => { const t = setTimeout(() => setIsTakingTooLong(true), 15e3) // 15 seconds return () => clearTimeout(t) }, [setIsTakingTooLong]) return ( {isTakingTooLong ? "This is taking too long. There may be a problem with your internet or with the service, but we're going to try a couple more times..." : 'Connecting...'} {isTakingTooLong ? ( { Linking.openURL(STATUS_PAGE_URL) }} accessibilityRole="button"> Check Bluesky status page ) : null} ) } const styles = StyleSheet.create({ loading: { height: '100%', alignContent: 'center', justifyContent: 'center', paddingBottom: 100, }, loadingText: { paddingVertical: 20, paddingHorizontal: 20, textAlign: 'center', }, })