Decompose, add docblocks

This commit is contained in:
Eric Bailey
2025-07-15 17:13:13 -05:00
parent 97a056fbeb
commit f9449d23fa
3 changed files with 26 additions and 17 deletions
@@ -38,11 +38,11 @@ function Inner({style}: ViewStyleProp & {}) {
const {gtPhone} = useBreakpoints() const {gtPhone} = useBreakpoints()
const copy = useAgeAssuranceCopy() const copy = useAgeAssuranceCopy()
const {assurance} = useAgeAssurance() const {status, lastInitiatedAt} = useAgeAssurance()
const isBlocked = assurance.status === 'blocked' const isBlocked = status === 'blocked'
const hasInitiated = !!assurance.lastInitiatedAt const hasInitiated = !!lastInitiatedAt
const timeAgo = assurance.lastInitiatedAt const timeAgo = lastInitiatedAt
? getTimeAgo(assurance.lastInitiatedAt, new Date()) ? getTimeAgo(lastInitiatedAt, new Date())
: null : null
return ( return (
@@ -96,10 +96,10 @@ function Inner({style}: ViewStyleProp & {}) {
a.align_center, a.align_center,
gtPhone ? [a.flex_row, a.gap_xl] : [a.gap_md], gtPhone ? [a.flex_row, a.gap_xl] : [a.gap_md],
]}> ]}>
{assurance.lastInitiatedAt ? ( {hasInitiated ? (
<Text <Text
style={[a.text_sm, a.italic, t.atoms.text_contrast_medium]} style={[a.text_sm, a.italic, t.atoms.text_contrast_medium]}
title={i18n.date(assurance.lastInitiatedAt, { title={i18n.date(lastInitiatedAt, {
dateStyle: 'medium', dateStyle: 'medium',
timeStyle: 'medium', timeStyle: 'medium',
})}> })}>
@@ -12,7 +12,7 @@ import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times'
export function AgeAssuranceDismissableNotice({style}: ViewStyleProp & {}) { export function AgeAssuranceDismissableNotice({style}: ViewStyleProp & {}) {
const {_} = useLingui() const {_} = useLingui()
const {isReady, isDeclaredUnderage, isAgeRestricted, assurance} = const {isReady, isDeclaredUnderage, isAgeRestricted, lastInitiatedAt} =
useAgeAssurance() useAgeAssurance()
const {nux} = useNux(Nux.AgeAssuranceDismissableNotice) const {nux} = useNux(Nux.AgeAssuranceDismissableNotice)
const copy = useAgeAssuranceCopy() const copy = useAgeAssuranceCopy()
@@ -22,7 +22,7 @@ export function AgeAssuranceDismissableNotice({style}: ViewStyleProp & {}) {
if (!isReady) return null if (!isReady) return null
if (isDeclaredUnderage) return null if (isDeclaredUnderage) return null
if (!isAgeRestricted) return null if (!isAgeRestricted) return null
if (assurance.lastInitiatedAt) return null if (lastInitiatedAt) return null
if (hidden) return null if (hidden) return null
if (nux && nux.completed) return null if (nux && nux.completed) return null
+17 -8
View File
@@ -7,12 +7,21 @@ import {usePreferencesQuery} from '#/state/queries/preferences'
const logger = Logger.create(Logger.Context.AgeAssurance) const logger = Logger.create(Logger.Context.AgeAssurance)
type AgeAssurance = { type AgeAssurance = ReturnType<typeof useAgeAssuranceContext> & {
isReady: boolean /**
declaredAge: number | undefined * Indicates the user is age restricted based on the requirements of their
isDeclaredUnderage: boolean * region, and their server-provided age assurance status. Does not factor in
* the user's declared age.
*/
isAgeRestricted: boolean isAgeRestricted: boolean
assurance: ReturnType<typeof useAgeAssuranceContext> /**
* The age the user has declared in their preferences, if any.
*/
declaredAge: number | undefined
/**
* Indicates whether the user has declared an age under 18.
*/
isDeclaredUnderage: boolean
} }
/** /**
@@ -32,11 +41,11 @@ export function useAgeAssurance(): AgeAssurance {
const isDeclaredUnderage = (declaredAge || 0) < 18 const isDeclaredUnderage = (declaredAge || 0) < 18
const state: AgeAssurance = { const state: AgeAssurance = {
isReady, isReady,
status: ctx.status,
lastInitiatedAt: ctx.lastInitiatedAt,
isAgeRestricted,
declaredAge, declaredAge,
isDeclaredUnderage, isDeclaredUnderage,
isAgeRestricted,
assurance: ctx,
} }
logger.debug(`state`, state) logger.debug(`state`, state)
return state return state