Slightly better screen gater
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import {useMemo} from 'react'
|
||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
import {Trans} from '@lingui/macro'
|
import {Trans} from '@lingui/macro'
|
||||||
|
|
||||||
@@ -6,11 +7,27 @@ import {IsAgeRestricted} from '#/components/ageAssurance/IsAgeRestricted'
|
|||||||
import * as Layout from '#/components/Layout'
|
import * as Layout from '#/components/Layout'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
export function AgeRestrictedScreen({children}: {children: React.ReactNode}) {
|
export function AgeRestrictedScreen({
|
||||||
|
children,
|
||||||
|
fallback,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode
|
||||||
|
fallback?: React.ReactNode
|
||||||
|
}) {
|
||||||
|
const screenFallback = useMemo(() => {
|
||||||
|
return (
|
||||||
|
fallback || (
|
||||||
|
<Layout.Screen>
|
||||||
|
<Layout.Content />
|
||||||
|
</Layout.Screen>
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}, [fallback])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<IsAgeRestricted.True>
|
<IsAgeRestricted.True fallback={screenFallback}>
|
||||||
<Layout.Screen testID="messagesSettingsScreen">
|
<Layout.Screen>
|
||||||
<Layout.Header.Outer>
|
<Layout.Header.Outer>
|
||||||
<Layout.Header.BackButton />
|
<Layout.Header.BackButton />
|
||||||
<Layout.Header.Content>
|
<Layout.Header.Content>
|
||||||
@@ -30,7 +47,9 @@ export function AgeRestrictedScreen({children}: {children: React.ReactNode}) {
|
|||||||
</Layout.Screen>
|
</Layout.Screen>
|
||||||
</IsAgeRestricted.True>
|
</IsAgeRestricted.True>
|
||||||
|
|
||||||
<IsAgeRestricted.False>{children}</IsAgeRestricted.False>
|
<IsAgeRestricted.False fallback={screenFallback}>
|
||||||
|
{children}
|
||||||
|
</IsAgeRestricted.False>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,37 @@
|
|||||||
import {useAgeAssuranceContext} from '#/state/ageAssurance'
|
import {useAgeAssuranceContext} from '#/state/ageAssurance'
|
||||||
|
|
||||||
export function True({children}: {children: React.ReactNode}) {
|
export function True({
|
||||||
|
children,
|
||||||
|
fallback,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode
|
||||||
|
fallback?: React.ReactNode
|
||||||
|
}) {
|
||||||
const {isLoaded, isAgeRestricted} = useAgeAssuranceContext()
|
const {isLoaded, isAgeRestricted} = useAgeAssuranceContext()
|
||||||
return isLoaded && isAgeRestricted ? children : null
|
const isDefinitelyAgeRestricted = isLoaded && isAgeRestricted
|
||||||
|
const notSureYet = isAgeRestricted
|
||||||
|
return isDefinitelyAgeRestricted
|
||||||
|
? children
|
||||||
|
: notSureYet
|
||||||
|
? fallback || null
|
||||||
|
: null
|
||||||
}
|
}
|
||||||
|
|
||||||
export function False({children}: {children: React.ReactNode}) {
|
export function False({
|
||||||
|
children,
|
||||||
|
fallback,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode
|
||||||
|
fallback?: React.ReactNode
|
||||||
|
}) {
|
||||||
const {isLoaded, isAgeRestricted} = useAgeAssuranceContext()
|
const {isLoaded, isAgeRestricted} = useAgeAssuranceContext()
|
||||||
return isLoaded && !isAgeRestricted ? children : null
|
const isDefinitelyNotAgeRestricted = isLoaded && !isAgeRestricted
|
||||||
|
const notSureYet = !isAgeRestricted
|
||||||
|
return isDefinitelyNotAgeRestricted
|
||||||
|
? children
|
||||||
|
: notSureYet
|
||||||
|
? fallback || null
|
||||||
|
: null
|
||||||
}
|
}
|
||||||
|
|
||||||
export const IsAgeRestricted = {
|
export const IsAgeRestricted = {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export function Provider({children}: {children: React.ReactNode}) {
|
|||||||
(() => ({
|
(() => ({
|
||||||
data: {
|
data: {
|
||||||
lastInitiatedAt: new Date().toISOString(),
|
lastInitiatedAt: new Date().toISOString(),
|
||||||
status: 'assured',
|
status: 'unknown',
|
||||||
} as TempAgeAssuranceState,
|
} as TempAgeAssuranceState,
|
||||||
}))(),
|
}))(),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user