Big refactor
This commit is contained in:
@@ -34,6 +34,7 @@ module.exports = {
|
|||||||
'P',
|
'P',
|
||||||
'Admonition',
|
'Admonition',
|
||||||
'Admonition.Admonition',
|
'Admonition.Admonition',
|
||||||
|
'AgeAssuranceAdmonition',
|
||||||
'Span',
|
'Span',
|
||||||
],
|
],
|
||||||
impliedTextProps: [],
|
impliedTextProps: [],
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export function AgeAssuranceAccountCard({style}: ViewStyleProp & {}) {
|
|||||||
const {isLoaded, assurance, declaredAge} = useAgeInfo()
|
const {isLoaded, assurance, declaredAge} = useAgeInfo()
|
||||||
|
|
||||||
if (!isLoaded) return null
|
if (!isLoaded) return null
|
||||||
if (declaredAge < 18) return null
|
if (declaredAge && declaredAge < 18) return null
|
||||||
if (!assurance.isAgeRestricted) return null
|
if (!assurance.isAgeRestricted) return null
|
||||||
|
|
||||||
return <Inner style={style} />
|
return <Inner style={style} />
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
import {View} from 'react-native'
|
||||||
|
import {msg, Trans} from '@lingui/macro'
|
||||||
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
|
import {atoms as a, select, useTheme, type ViewStyleProp} from '#/alf'
|
||||||
|
import {useDialogControl} from '#/components/ageAssurance/AgeAssuranceInitDialog'
|
||||||
|
import {useAgeInfo} from '#/components/ageAssurance/useAgeInfo'
|
||||||
|
import type * as Dialog from '#/components/Dialog'
|
||||||
|
import {ShieldCheck_Stroke2_Corner0_Rounded as Shield} from '#/components/icons/Shield'
|
||||||
|
import {InlineLinkText} from '#/components/Link'
|
||||||
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
|
export function AgeAssuranceAdmonition({
|
||||||
|
children,
|
||||||
|
style,
|
||||||
|
}: ViewStyleProp & {children: React.ReactNode}) {
|
||||||
|
const control = useDialogControl()
|
||||||
|
const {isLoaded, isUnderage, assurance} = useAgeInfo()
|
||||||
|
|
||||||
|
if (!isLoaded) return null
|
||||||
|
if (isUnderage) return null
|
||||||
|
if (!assurance.isAgeRestricted) return null
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Inner style={style} control={control}>
|
||||||
|
{children}
|
||||||
|
</Inner>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Inner({
|
||||||
|
children,
|
||||||
|
style,
|
||||||
|
}: ViewStyleProp & {
|
||||||
|
children: React.ReactNode
|
||||||
|
control: Dialog.DialogControlProps
|
||||||
|
}) {
|
||||||
|
const t = useTheme()
|
||||||
|
const {_} = useLingui()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<View style={style}>
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
a.p_md,
|
||||||
|
a.rounded_md,
|
||||||
|
a.border,
|
||||||
|
a.flex_row,
|
||||||
|
a.align_start,
|
||||||
|
a.gap_sm,
|
||||||
|
{
|
||||||
|
backgroundColor: select(t.name, {
|
||||||
|
light: t.palette.primary_25,
|
||||||
|
dark: t.palette.primary_25,
|
||||||
|
dim: t.palette.primary_25,
|
||||||
|
}),
|
||||||
|
borderColor: select(t.name, {
|
||||||
|
light: t.palette.primary_100,
|
||||||
|
dark: t.palette.primary_100,
|
||||||
|
dim: t.palette.primary_100,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
]}>
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
a.align_center,
|
||||||
|
a.justify_center,
|
||||||
|
a.rounded_full,
|
||||||
|
{
|
||||||
|
width: 32,
|
||||||
|
height: 32,
|
||||||
|
backgroundColor: select(t.name, {
|
||||||
|
light: t.palette.primary_100,
|
||||||
|
dark: t.palette.primary_100,
|
||||||
|
dim: t.palette.primary_100,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
]}>
|
||||||
|
<Shield size="md" />
|
||||||
|
</View>
|
||||||
|
<View style={[a.flex_1, a.gap_xs]}>
|
||||||
|
<Text style={[a.text_sm, a.leading_snug]}>{children} </Text>
|
||||||
|
<Text style={[a.text_sm, a.leading_snug, a.font_bold]}>
|
||||||
|
<Trans>
|
||||||
|
Learn more in your{' '}
|
||||||
|
<InlineLinkText
|
||||||
|
label={_(msg`Go to account settings`)}
|
||||||
|
to={'/settings/account'}
|
||||||
|
style={[a.text_sm, a.leading_snug, a.font_bold]}>
|
||||||
|
account settings.
|
||||||
|
</InlineLinkText>
|
||||||
|
</Trans>
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import {View} from 'react-native'
|
||||||
|
import {msg} from '@lingui/macro'
|
||||||
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
|
import {Nux, useNux, useSaveNux} from '#/state/queries/nuxs'
|
||||||
|
import {atoms as a, type ViewStyleProp} from '#/alf'
|
||||||
|
import {AgeAssuranceAdmonition} from '#/components/ageAssurance/AgeAssuranceAdmonition'
|
||||||
|
import {useAgeAssuranceCopy} from '#/components/ageAssurance/useAgeAssuranceCopy'
|
||||||
|
import {useAgeInfo} from '#/components/ageAssurance/useAgeInfo'
|
||||||
|
import {Button, ButtonIcon} from '#/components/Button'
|
||||||
|
import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times'
|
||||||
|
|
||||||
|
export function AgeAssuranceDismissableNotice({style}: ViewStyleProp & {}) {
|
||||||
|
const {_} = useLingui()
|
||||||
|
const {isLoaded, isUnderage, assurance} = useAgeInfo()
|
||||||
|
const {nux} = useNux(Nux.AgeAssurancePrompt)
|
||||||
|
const copy = useAgeAssuranceCopy()
|
||||||
|
const {mutate: save, variables} = useSaveNux()
|
||||||
|
const hidden = !!variables
|
||||||
|
|
||||||
|
if (!isLoaded) return null
|
||||||
|
if (isUnderage) return null
|
||||||
|
if (!assurance.isAgeRestricted) return null
|
||||||
|
if (assurance.lastInitiatedAt) return null
|
||||||
|
if (hidden) return null
|
||||||
|
if (nux && nux.completed) return null
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={style}>
|
||||||
|
<View style={[a.relative]}>
|
||||||
|
<AgeAssuranceAdmonition>{copy.notice}</AgeAssuranceAdmonition>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
label={_(msg`Don't show again`)}
|
||||||
|
size="tiny"
|
||||||
|
variant="solid"
|
||||||
|
color="secondary_inverted"
|
||||||
|
shape="round"
|
||||||
|
onPress={() =>
|
||||||
|
save({
|
||||||
|
id: Nux.AgeAssurancePrompt,
|
||||||
|
completed: true,
|
||||||
|
data: undefined,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
style={[
|
||||||
|
a.absolute,
|
||||||
|
{
|
||||||
|
top: 12,
|
||||||
|
right: 12,
|
||||||
|
},
|
||||||
|
]}>
|
||||||
|
<ButtonIcon icon={X} />
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
import {View} from 'react-native'
|
|
||||||
import {msg, Trans} from '@lingui/macro'
|
|
||||||
import {useLingui} from '@lingui/react'
|
|
||||||
|
|
||||||
import {useAgeAssuranceContext} from '#/state/age-assurance'
|
|
||||||
import {Nux, useNux, useSaveNux} from '#/state/queries/nuxs'
|
|
||||||
import {atoms as a, select, useTheme, type ViewStyleProp} from '#/alf'
|
|
||||||
import {AgeAssuranceBadge} from '#/components/ageAssurance/AgeAssuranceBadge'
|
|
||||||
import {
|
|
||||||
AgeAssuranceInitDialog,
|
|
||||||
useDialogControl,
|
|
||||||
} from '#/components/ageAssurance/AgeAssuranceInitDialog'
|
|
||||||
import {IsAgeRestricted} from '#/components/ageAssurance/IsAgeRestricted'
|
|
||||||
import {useAgeAssuranceCopy} from '#/components/ageAssurance/useAgeAssuranceCopy'
|
|
||||||
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
|
||||||
import type * as Dialog from '#/components/Dialog'
|
|
||||||
import {Divider} from '#/components/Divider'
|
|
||||||
import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times'
|
|
||||||
import {Text} from '#/components/Typography'
|
|
||||||
|
|
||||||
export function AgeAssurancePrompt({style}: ViewStyleProp & {}) {
|
|
||||||
const control = useDialogControl()
|
|
||||||
const {hasInitiated} = useAgeAssuranceContext()
|
|
||||||
const {nux} = useNux(Nux.AgeAssurancePrompt)
|
|
||||||
|
|
||||||
if (nux && nux.completed) return null
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<IsAgeRestricted.True>
|
|
||||||
{!hasInitiated && <Inner style={style} control={control} />}
|
|
||||||
<AgeAssuranceInitDialog control={control} />
|
|
||||||
</IsAgeRestricted.True>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function Inner({
|
|
||||||
style,
|
|
||||||
control,
|
|
||||||
}: ViewStyleProp & {control: Dialog.DialogControlProps}) {
|
|
||||||
const t = useTheme()
|
|
||||||
const {_} = useLingui()
|
|
||||||
const copy = useAgeAssuranceCopy()
|
|
||||||
const {mutate: save} = useSaveNux()
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<View style={style}>
|
|
||||||
<View
|
|
||||||
style={[
|
|
||||||
a.p_lg,
|
|
||||||
a.rounded_md,
|
|
||||||
a.border,
|
|
||||||
{
|
|
||||||
backgroundColor: select(t.name, {
|
|
||||||
light: t.palette.primary_25,
|
|
||||||
dark: t.palette.primary_25,
|
|
||||||
dim: t.palette.primary_25,
|
|
||||||
}),
|
|
||||||
borderColor: select(t.name, {
|
|
||||||
light: t.palette.primary_100,
|
|
||||||
dark: t.palette.primary_100,
|
|
||||||
dim: t.palette.primary_100,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
]}>
|
|
||||||
<View style={[a.align_start, a.pb_md]}>
|
|
||||||
<AgeAssuranceBadge />
|
|
||||||
</View>
|
|
||||||
<Text style={[a.text_md, a.leading_snug]}>{copy.notice}</Text>
|
|
||||||
|
|
||||||
<Divider
|
|
||||||
style={[
|
|
||||||
a.mt_lg,
|
|
||||||
{
|
|
||||||
borderColor: select(t.name, {
|
|
||||||
light: t.palette.primary_100,
|
|
||||||
dark: t.palette.primary_100,
|
|
||||||
dim: t.palette.primary_100,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<View
|
|
||||||
style={[
|
|
||||||
a.flex_row,
|
|
||||||
a.justify_between,
|
|
||||||
a.align_center,
|
|
||||||
a.pt_md,
|
|
||||||
a.gap_lg,
|
|
||||||
]}>
|
|
||||||
<Text
|
|
||||||
style={[
|
|
||||||
a.leading_snug,
|
|
||||||
a.flex_1,
|
|
||||||
{
|
|
||||||
color: select(t.name, {
|
|
||||||
light: t.palette.primary_800,
|
|
||||||
dark: t.palette.primary_800,
|
|
||||||
dim: t.palette.primary_800,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
]}>
|
|
||||||
{copy.noticeSub}
|
|
||||||
</Text>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
label={_(msg`Verify now`)}
|
|
||||||
size="small"
|
|
||||||
variant="solid"
|
|
||||||
color="primary"
|
|
||||||
onPress={() => control.open()}>
|
|
||||||
<ButtonText>
|
|
||||||
<Trans>Verify now</Trans>
|
|
||||||
</ButtonText>
|
|
||||||
</Button>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
label={_(msg`Don't show again`)}
|
|
||||||
size="tiny"
|
|
||||||
variant="solid"
|
|
||||||
color="secondary_inverted"
|
|
||||||
shape="round"
|
|
||||||
onPress={() =>
|
|
||||||
save({
|
|
||||||
id: Nux.AgeAssurancePrompt,
|
|
||||||
completed: true,
|
|
||||||
data: undefined,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
style={[
|
|
||||||
a.absolute,
|
|
||||||
{
|
|
||||||
top: 12,
|
|
||||||
right: 12,
|
|
||||||
},
|
|
||||||
]}>
|
|
||||||
<ButtonIcon icon={X} />
|
|
||||||
</Button>
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,40 +1,34 @@
|
|||||||
import {useMemo} from 'react'
|
|
||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import {atoms as a, select, useTheme} from '#/alf'
|
import {atoms as a} from '#/alf'
|
||||||
import {Admonition} from '#/components/Admonition'
|
import {Admonition} from '#/components/Admonition'
|
||||||
import {AgeAssuranceBadge} from '#/components/ageAssurance/AgeAssuranceBadge'
|
import {AgeAssuranceBadge} from '#/components/ageAssurance/AgeAssuranceBadge'
|
||||||
import {
|
|
||||||
AgeAssuranceInitDialog,
|
|
||||||
useDialogControl,
|
|
||||||
} from '#/components/ageAssurance/AgeAssuranceInitDialog'
|
|
||||||
import {IsAgeRestricted} from '#/components/ageAssurance/IsAgeRestricted'
|
|
||||||
import {useAgeAssuranceCopy} from '#/components/ageAssurance/useAgeAssuranceCopy'
|
import {useAgeAssuranceCopy} from '#/components/ageAssurance/useAgeAssuranceCopy'
|
||||||
import {Button, ButtonText} from '#/components/Button'
|
import {useAgeInfo} from '#/components/ageAssurance/useAgeInfo'
|
||||||
import {Divider} from '#/components/Divider'
|
import {ButtonIcon, ButtonText} from '#/components/Button'
|
||||||
|
import {ChevronRight_Stroke2_Corner0_Rounded as ChevronRight} from '#/components/icons/Chevron'
|
||||||
import * as Layout from '#/components/Layout'
|
import * as Layout from '#/components/Layout'
|
||||||
|
import {Link} from '#/components/Link'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
export function AgeRestrictedScreen({
|
export function AgeRestrictedScreen({
|
||||||
children,
|
children,
|
||||||
fallback,
|
|
||||||
screenTitle,
|
screenTitle,
|
||||||
infoText,
|
infoText,
|
||||||
}: {
|
}: {
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
fallback?: React.ReactNode
|
|
||||||
screenTitle?: string
|
screenTitle?: string
|
||||||
infoText?: string
|
infoText?: string
|
||||||
}) {
|
}) {
|
||||||
const t = useTheme()
|
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const copy = useAgeAssuranceCopy()
|
const copy = useAgeAssuranceCopy()
|
||||||
const control = useDialogControl()
|
const {isLoaded, assurance} = useAgeInfo()
|
||||||
const screenFallback = useMemo(() => {
|
|
||||||
|
if (assurance.isExempt) return children
|
||||||
|
if (!isLoaded) {
|
||||||
return (
|
return (
|
||||||
fallback || (
|
|
||||||
<Layout.Screen>
|
<Layout.Screen>
|
||||||
<Layout.Header.Outer>
|
<Layout.Header.Outer>
|
||||||
<Layout.Header.Content>
|
<Layout.Header.Content>
|
||||||
@@ -45,12 +39,10 @@ export function AgeRestrictedScreen({
|
|||||||
<Layout.Content />
|
<Layout.Content />
|
||||||
</Layout.Screen>
|
</Layout.Screen>
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}, [fallback])
|
if (!assurance.isAgeRestricted) return children
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
|
||||||
<IsAgeRestricted.True fallback={screenFallback}>
|
|
||||||
<Layout.Screen>
|
<Layout.Screen>
|
||||||
<Layout.Header.Outer>
|
<Layout.Header.Outer>
|
||||||
<Layout.Header.BackButton />
|
<Layout.Header.BackButton />
|
||||||
@@ -62,86 +54,41 @@ export function AgeRestrictedScreen({
|
|||||||
<Layout.Header.Slot />
|
<Layout.Header.Slot />
|
||||||
</Layout.Header.Outer>
|
</Layout.Header.Outer>
|
||||||
<Layout.Content>
|
<Layout.Content>
|
||||||
<View style={[a.p_lg, a.gap_lg]}>
|
<View style={[a.p_lg]}>
|
||||||
<View
|
<View style={[a.align_start, a.pb_lg]}>
|
||||||
style={[
|
|
||||||
a.p_lg,
|
|
||||||
a.rounded_md,
|
|
||||||
a.border,
|
|
||||||
{
|
|
||||||
backgroundColor: select(t.name, {
|
|
||||||
light: t.palette.primary_25,
|
|
||||||
dark: t.palette.primary_25,
|
|
||||||
dim: t.palette.primary_25,
|
|
||||||
}),
|
|
||||||
borderColor: select(t.name, {
|
|
||||||
light: t.palette.primary_100,
|
|
||||||
dark: t.palette.primary_100,
|
|
||||||
dim: t.palette.primary_100,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
]}>
|
|
||||||
<AgeAssuranceInitDialog control={control} />
|
|
||||||
|
|
||||||
<View style={[a.align_start, a.pb_md]}>
|
|
||||||
<AgeAssuranceBadge />
|
<AgeAssuranceBadge />
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<Text style={[a.text_md, a.leading_snug, a.pb_sm]}>
|
<View style={[a.gap_sm, a.pb_lg]}>
|
||||||
<Trans>{copy.notice}</Trans>
|
<Text style={[a.text_xl, a.leading_snug, a.font_heavy]}>
|
||||||
</Text>
|
|
||||||
|
|
||||||
<Text style={[a.text_md, a.leading_snug]}>
|
|
||||||
<Trans>
|
<Trans>
|
||||||
You must complete age verification to access this screen.
|
You must verify your age in order to access this screen.
|
||||||
</Trans>
|
</Trans>
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<Divider style={[a.mt_lg]} />
|
<Text style={[a.text_md, a.leading_snug]}>
|
||||||
|
<Trans>{copy.notice}</Trans>
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[a.flex_row, a.justify_between, a.align_center, a.pb_xl]}>
|
||||||
a.flex_row,
|
<Link
|
||||||
a.justify_between,
|
label={_(msg`Go to account settings`)}
|
||||||
a.align_center,
|
to="/settings/account"
|
||||||
a.pt_md,
|
|
||||||
a.gap_lg,
|
|
||||||
]}>
|
|
||||||
<Text
|
|
||||||
style={[
|
|
||||||
{
|
|
||||||
color: select(t.name, {
|
|
||||||
light: t.palette.primary_800,
|
|
||||||
dark: t.palette.primary_800,
|
|
||||||
dim: t.palette.primary_800,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
]}>
|
|
||||||
{copy.noticeSub}
|
|
||||||
</Text>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
label={_(msg`Verify now`)}
|
|
||||||
size="small"
|
size="small"
|
||||||
variant="solid"
|
variant="solid"
|
||||||
color="primary"
|
color="primary">
|
||||||
onPress={() => control.open()}>
|
|
||||||
<ButtonText>
|
<ButtonText>
|
||||||
<Trans>Verify now</Trans>
|
<Trans>Go to account settings</Trans>
|
||||||
</ButtonText>
|
</ButtonText>
|
||||||
</Button>
|
<ButtonIcon icon={ChevronRight} position="right" />
|
||||||
</View>
|
</Link>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{infoText && <Admonition type="info">{infoText}</Admonition>}
|
{infoText && <Admonition type="tip">{infoText}</Admonition>}
|
||||||
</View>
|
</View>
|
||||||
</Layout.Content>
|
</Layout.Content>
|
||||||
</Layout.Screen>
|
</Layout.Screen>
|
||||||
</IsAgeRestricted.True>
|
|
||||||
|
|
||||||
<IsAgeRestricted.False fallback={screenFallback}>
|
|
||||||
{children}
|
|
||||||
</IsAgeRestricted.False>
|
|
||||||
</>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
import {useAgeAssuranceContext} from '#/state/age-assurance'
|
|
||||||
|
|
||||||
export function True({
|
|
||||||
children,
|
|
||||||
fallback,
|
|
||||||
}: {
|
|
||||||
children: React.ReactNode
|
|
||||||
fallback?: React.ReactNode
|
|
||||||
}) {
|
|
||||||
const {isLoaded, isAgeRestricted, isExempt} = useAgeAssuranceContext()
|
|
||||||
/**
|
|
||||||
* For the true case, if the user is exempt, return nothing
|
|
||||||
*/
|
|
||||||
if (isExempt) return null
|
|
||||||
|
|
||||||
const isDefinitelyAgeRestricted = isLoaded && isAgeRestricted
|
|
||||||
const notSureYet = isAgeRestricted
|
|
||||||
|
|
||||||
return isDefinitelyAgeRestricted
|
|
||||||
? children
|
|
||||||
: notSureYet
|
|
||||||
? fallback || null
|
|
||||||
: null
|
|
||||||
}
|
|
||||||
|
|
||||||
export function False({
|
|
||||||
children,
|
|
||||||
fallback,
|
|
||||||
}: {
|
|
||||||
children: React.ReactNode
|
|
||||||
fallback?: React.ReactNode
|
|
||||||
}) {
|
|
||||||
const {isLoaded, isAgeRestricted, isExempt} = useAgeAssuranceContext()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For the false case, if the user is exempt, return children
|
|
||||||
*/
|
|
||||||
if (isExempt) return children
|
|
||||||
|
|
||||||
const isDefinitelyNotAgeRestricted = isLoaded && !isAgeRestricted
|
|
||||||
const notSureYet = !isAgeRestricted
|
|
||||||
|
|
||||||
return isDefinitelyNotAgeRestricted
|
|
||||||
? children
|
|
||||||
: notSureYet
|
|
||||||
? fallback || null
|
|
||||||
: null
|
|
||||||
}
|
|
||||||
|
|
||||||
export const IsAgeRestricted = {
|
|
||||||
True,
|
|
||||||
False,
|
|
||||||
}
|
|
||||||
@@ -7,12 +7,13 @@ export function useAgeInfo() {
|
|||||||
const ctx = useAgeAssuranceContext()
|
const ctx = useAgeAssuranceContext()
|
||||||
const {isFetched: preferencesLoaded, data: preferences} =
|
const {isFetched: preferencesLoaded, data: preferences} =
|
||||||
usePreferencesQuery()
|
usePreferencesQuery()
|
||||||
const declaredAge = useMemo(() => preferences?.userAge || -1, [preferences])
|
const declaredAge = useMemo(() => preferences?.userAge, [preferences])
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
return {
|
return {
|
||||||
isLoaded: ctx.isLoaded && preferencesLoaded,
|
isLoaded: ctx.isLoaded && preferencesLoaded,
|
||||||
declaredAge,
|
declaredAge,
|
||||||
|
isUnderage: ctx.isAgeRestricted && (declaredAge || 0) < 18,
|
||||||
assurance: ctx,
|
assurance: ctx,
|
||||||
}
|
}
|
||||||
}, [ctx, preferencesLoaded, declaredAge])
|
}, [ctx, preferencesLoaded, declaredAge])
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ import {isNonConfigurableModerationAuthority} from '#/state/session/additional-m
|
|||||||
import {useSetMinimalShellMode} from '#/state/shell'
|
import {useSetMinimalShellMode} from '#/state/shell'
|
||||||
import {ViewHeader} from '#/view/com/util/ViewHeader'
|
import {ViewHeader} from '#/view/com/util/ViewHeader'
|
||||||
import {atoms as a, useBreakpoints, useTheme, type ViewStyleProp} from '#/alf'
|
import {atoms as a, useBreakpoints, useTheme, type ViewStyleProp} from '#/alf'
|
||||||
import {AgeAssurancePrompt} from '#/components/ageAssurance/AgeAssurancePrompt'
|
import {AgeAssuranceAdmonition} from '#/components/ageAssurance/AgeAssuranceAdmonition'
|
||||||
|
import {useAgeInfo} from '#/components/ageAssurance/useAgeInfo'
|
||||||
import {Button, ButtonText} from '#/components/Button'
|
import {Button, ButtonText} from '#/components/Button'
|
||||||
import * as Dialog from '#/components/Dialog'
|
import * as Dialog from '#/components/Dialog'
|
||||||
import {BirthDateSettingsDialog} from '#/components/dialogs/BirthDateSettings'
|
import {BirthDateSettingsDialog} from '#/components/dialogs/BirthDateSettings'
|
||||||
@@ -86,8 +87,9 @@ export function ModerationScreen(
|
|||||||
error: preferencesError,
|
error: preferencesError,
|
||||||
data: preferences,
|
data: preferences,
|
||||||
} = usePreferencesQuery()
|
} = usePreferencesQuery()
|
||||||
|
const {isLoaded: isAgeInfoLoaded} = useAgeInfo()
|
||||||
|
|
||||||
const isLoading = isPreferencesLoading
|
const isLoading = isPreferencesLoading || !isAgeInfoLoaded
|
||||||
const error = preferencesError
|
const error = preferencesError
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -160,6 +162,7 @@ export function ModerationScreenInner({
|
|||||||
error: labelersError,
|
error: labelersError,
|
||||||
} = useMyLabelersQuery()
|
} = useMyLabelersQuery()
|
||||||
const {isAgeRestricted} = useAgeAssuranceContext()
|
const {isAgeRestricted} = useAgeAssuranceContext()
|
||||||
|
const {declaredAge, isUnderage, assurance: ageAssurance} = useAgeInfo()
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
@@ -173,8 +176,6 @@ export function ModerationScreenInner({
|
|||||||
(optimisticAdultContent && optimisticAdultContent.enabled) ||
|
(optimisticAdultContent && optimisticAdultContent.enabled) ||
|
||||||
(!optimisticAdultContent && preferences.moderationPrefs.adultContentEnabled)
|
(!optimisticAdultContent && preferences.moderationPrefs.adultContentEnabled)
|
||||||
)
|
)
|
||||||
const ageNotSet = !preferences.userAge
|
|
||||||
const isUnderage = (preferences.userAge || 0) < 18
|
|
||||||
|
|
||||||
const onToggleAdultContentEnabled = useCallback(
|
const onToggleAdultContentEnabled = useCallback(
|
||||||
async (selected: boolean) => {
|
async (selected: boolean) => {
|
||||||
@@ -309,10 +310,15 @@ export function ModerationScreenInner({
|
|||||||
<Trans>Content filters</Trans>
|
<Trans>Content filters</Trans>
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<AgeAssurancePrompt style={[a.pb_md]} />
|
<AgeAssuranceAdmonition style={[a.pb_md]}>
|
||||||
|
<Trans>
|
||||||
|
You must complete age verification in order to access the settings
|
||||||
|
below.
|
||||||
|
</Trans>
|
||||||
|
</AgeAssuranceAdmonition>
|
||||||
|
|
||||||
<View style={[a.gap_md]}>
|
<View style={[a.gap_md]}>
|
||||||
{ageNotSet && (
|
{declaredAge === undefined && ageAssurance.isAgeRestricted && (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
label={_(msg`Confirm your birthdate`)}
|
label={_(msg`Confirm your birthdate`)}
|
||||||
@@ -341,7 +347,7 @@ export function ModerationScreenInner({
|
|||||||
a.overflow_hidden,
|
a.overflow_hidden,
|
||||||
t.atoms.bg_contrast_25,
|
t.atoms.bg_contrast_25,
|
||||||
]}>
|
]}>
|
||||||
{!ageNotSet && !isUnderage && (
|
{!isUnderage && (
|
||||||
<>
|
<>
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
@@ -394,9 +400,8 @@ export function ModerationScreenInner({
|
|||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
<Divider />
|
<Divider />
|
||||||
</>
|
|
||||||
)}
|
{adultContentEnabled && (
|
||||||
{!isUnderage && adultContentEnabled && (
|
|
||||||
<>
|
<>
|
||||||
<GlobalLabelPreference labelDefinition={LABELS.porn} />
|
<GlobalLabelPreference labelDefinition={LABELS.porn} />
|
||||||
<Divider />
|
<Divider />
|
||||||
@@ -408,6 +413,8 @@ export function ModerationScreenInner({
|
|||||||
<Divider />
|
<Divider />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<GlobalLabelPreference
|
<GlobalLabelPreference
|
||||||
disabled={isAgeRestricted}
|
disabled={isAgeRestricted}
|
||||||
labelDefinition={LABELS.nudity}
|
labelDefinition={LABELS.nudity}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import * as Toast from '#/view/com/util/Toast'
|
|||||||
import {UserAvatar} from '#/view/com/util/UserAvatar'
|
import {UserAvatar} from '#/view/com/util/UserAvatar'
|
||||||
import * as SettingsList from '#/screens/Settings/components/SettingsList'
|
import * as SettingsList from '#/screens/Settings/components/SettingsList'
|
||||||
import {atoms as a, platform, tokens, useBreakpoints, useTheme} from '#/alf'
|
import {atoms as a, platform, tokens, useBreakpoints, useTheme} from '#/alf'
|
||||||
import {AgeAssurancePrompt} from '#/components/ageAssurance/AgeAssurancePrompt'
|
import {AgeAssuranceDismissableNotice} from '#/components/ageAssurance/AgeAssuranceDismissableNotice'
|
||||||
import {AvatarStackWithFetch} from '#/components/AvatarStack'
|
import {AvatarStackWithFetch} from '#/components/AvatarStack'
|
||||||
import {useDialogControl} from '#/components/Dialog'
|
import {useDialogControl} from '#/components/Dialog'
|
||||||
import {SwitchAccountDialog} from '#/components/dialogs/SwitchAccount'
|
import {SwitchAccountDialog} from '#/components/dialogs/SwitchAccount'
|
||||||
@@ -97,7 +97,7 @@ export function SettingsScreen({}: Props) {
|
|||||||
</Layout.Header.Outer>
|
</Layout.Header.Outer>
|
||||||
<Layout.Content>
|
<Layout.Content>
|
||||||
<SettingsList.Container>
|
<SettingsList.Container>
|
||||||
<AgeAssurancePrompt style={[a.px_lg, a.pt_xs, a.pb_xl]} />
|
<AgeAssuranceDismissableNotice style={[a.px_lg, a.pt_xs, a.pb_xl]} />
|
||||||
|
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export function Provider({children}: {children: React.ReactNode}) {
|
|||||||
// (() => ({
|
// (() => ({
|
||||||
// data: {
|
// data: {
|
||||||
// lastInitiatedAt: new Date().toISOString(),
|
// lastInitiatedAt: new Date().toISOString(),
|
||||||
// status: 'blocked',
|
// status: 'pending',
|
||||||
// } as AppBskyUnspeccedDefs.AgeAssuranceState,
|
// } as AppBskyUnspeccedDefs.AgeAssuranceState,
|
||||||
// }))(),
|
// }))(),
|
||||||
// )
|
// )
|
||||||
|
|||||||
Reference in New Issue
Block a user