54faa7e176
* Update login page to use service query * Update modal to use session instead of store * Move image sizes cache off store * Update settings to no longer use store * Update link-meta fetch to use agent instead of rootstore * Remove deprecated resolveName() * Delete deprecated link-metas cache * Delete deprecated posts cache * Delete all remaining mobx models, including the root store * Strip out unused mobx observer wrappers
80 lines
2.2 KiB
TypeScript
80 lines
2.2 KiB
TypeScript
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'
|
|
|
|
export const withAuthRequired = <P extends object>(
|
|
Component: React.ComponentType<P>,
|
|
): React.FC<P> =>
|
|
function AuthRequired(props: P) {
|
|
const {isInitialLoad, hasSession} = useSession()
|
|
const onboardingState = useOnboardingState()
|
|
if (isInitialLoad) {
|
|
return <Loading />
|
|
}
|
|
if (!hasSession) {
|
|
return <LoggedOut />
|
|
}
|
|
if (onboardingState.isActive) {
|
|
return <Onboarding />
|
|
}
|
|
return <Component {...props} />
|
|
}
|
|
|
|
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 (
|
|
<CenteredView style={[styles.loading, pal.view]}>
|
|
<ActivityIndicator size="large" />
|
|
<Text type="2xl" style={[styles.loadingText, pal.textLight]}>
|
|
{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...'}
|
|
</Text>
|
|
{isTakingTooLong ? (
|
|
<TouchableOpacity
|
|
onPress={() => {
|
|
Linking.openURL(STATUS_PAGE_URL)
|
|
}}
|
|
accessibilityRole="button">
|
|
<Text type="2xl" style={[styles.loadingText, pal.link]}>
|
|
Check Bluesky status page
|
|
</Text>
|
|
</TouchableOpacity>
|
|
) : null}
|
|
</CenteredView>
|
|
)
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
loading: {
|
|
height: '100%',
|
|
alignContent: 'center',
|
|
justifyContent: 'center',
|
|
paddingBottom: 100,
|
|
},
|
|
loadingText: {
|
|
paddingVertical: 20,
|
|
paddingHorizontal: 20,
|
|
textAlign: 'center',
|
|
},
|
|
})
|