Rename useAgeAssurance
This commit is contained in:
@@ -3,7 +3,7 @@ import {msg, Trans} from '@lingui/macro'
|
|||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import {useGetTimeAgo} from '#/lib/hooks/useTimeAgo'
|
import {useGetTimeAgo} from '#/lib/hooks/useTimeAgo'
|
||||||
import {useAgeInfo} from '#/state/ageAssurance/useAgeInfo'
|
import {useAgeAssurance} from '#/state/ageAssurance/useAgeAssurance'
|
||||||
import {atoms as a, useBreakpoints, useTheme, type ViewStyleProp} from '#/alf'
|
import {atoms as a, useBreakpoints, useTheme, type ViewStyleProp} from '#/alf'
|
||||||
import {Admonition} from '#/components/Admonition'
|
import {Admonition} from '#/components/Admonition'
|
||||||
import {AgeAssuranceAppealDialog} from '#/components/ageAssurance/AgeAssuranceAppealDialog'
|
import {AgeAssuranceAppealDialog} from '#/components/ageAssurance/AgeAssuranceAppealDialog'
|
||||||
@@ -20,7 +20,7 @@ import {createStaticClick, InlineLinkText} from '#/components/Link'
|
|||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
export function AgeAssuranceAccountCard({style}: ViewStyleProp & {}) {
|
export function AgeAssuranceAccountCard({style}: ViewStyleProp & {}) {
|
||||||
const {isReady, isAgeRestricted, isUnderage} = useAgeInfo()
|
const {isReady, isAgeRestricted, isUnderage} = useAgeAssurance()
|
||||||
|
|
||||||
if (!isReady) return null
|
if (!isReady) return null
|
||||||
if (isUnderage) return null
|
if (isUnderage) return null
|
||||||
@@ -38,7 +38,7 @@ function Inner({style}: ViewStyleProp & {}) {
|
|||||||
const {gtPhone} = useBreakpoints()
|
const {gtPhone} = useBreakpoints()
|
||||||
|
|
||||||
const copy = useAgeAssuranceCopy()
|
const copy = useAgeAssuranceCopy()
|
||||||
const {assurance} = useAgeInfo()
|
const {assurance} = useAgeAssurance()
|
||||||
const isBlocked = assurance.status === 'blocked'
|
const isBlocked = assurance.status === 'blocked'
|
||||||
const hasInitiated = !!assurance.lastInitiatedAt
|
const hasInitiated = !!assurance.lastInitiatedAt
|
||||||
const timeAgo = assurance.lastInitiatedAt
|
const timeAgo = assurance.lastInitiatedAt
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ 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 {useAgeInfo} from '#/state/ageAssurance/useAgeInfo'
|
import {useAgeAssurance} from '#/state/ageAssurance/useAgeAssurance'
|
||||||
import {atoms as a, select, useTheme, type ViewStyleProp} from '#/alf'
|
import {atoms as a, select, useTheme, type ViewStyleProp} from '#/alf'
|
||||||
import {useDialogControl} from '#/components/ageAssurance/AgeAssuranceInitDialog'
|
import {useDialogControl} from '#/components/ageAssurance/AgeAssuranceInitDialog'
|
||||||
import type * as Dialog from '#/components/Dialog'
|
import type * as Dialog from '#/components/Dialog'
|
||||||
@@ -15,7 +15,7 @@ export function AgeAssuranceAdmonition({
|
|||||||
style,
|
style,
|
||||||
}: ViewStyleProp & {children: React.ReactNode}) {
|
}: ViewStyleProp & {children: React.ReactNode}) {
|
||||||
const control = useDialogControl()
|
const control = useDialogControl()
|
||||||
const {isReady, isUnderage, isAgeRestricted} = useAgeInfo()
|
const {isReady, isUnderage, isAgeRestricted} = useAgeAssurance()
|
||||||
|
|
||||||
if (!isReady) return null
|
if (!isReady) return null
|
||||||
if (isUnderage) return null
|
if (isUnderage) return null
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {View} from 'react-native'
|
|||||||
import {msg} from '@lingui/macro'
|
import {msg} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import {useAgeInfo} from '#/state/ageAssurance/useAgeInfo'
|
import {useAgeAssurance} from '#/state/ageAssurance/useAgeAssurance'
|
||||||
import {Nux, useNux, useSaveNux} from '#/state/queries/nuxs'
|
import {Nux, useNux, useSaveNux} from '#/state/queries/nuxs'
|
||||||
import {atoms as a, type ViewStyleProp} from '#/alf'
|
import {atoms as a, type ViewStyleProp} from '#/alf'
|
||||||
import {AgeAssuranceAdmonition} from '#/components/ageAssurance/AgeAssuranceAdmonition'
|
import {AgeAssuranceAdmonition} from '#/components/ageAssurance/AgeAssuranceAdmonition'
|
||||||
@@ -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, isUnderage, isAgeRestricted, assurance} = useAgeInfo()
|
const {isReady, isUnderage, isAgeRestricted, assurance} = useAgeAssurance()
|
||||||
const {nux} = useNux(Nux.AgeAssuranceDismissableNotice)
|
const {nux} = useNux(Nux.AgeAssuranceDismissableNotice)
|
||||||
const copy = useAgeAssuranceCopy()
|
const copy = useAgeAssuranceCopy()
|
||||||
const {mutate: save, variables} = useSaveNux()
|
const {mutate: save, variables} = useSaveNux()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ 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 {useAgeInfo} from '#/state/ageAssurance/useAgeInfo'
|
import {useAgeAssurance} from '#/state/ageAssurance/useAgeAssurance'
|
||||||
import {atoms as a} 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'
|
||||||
@@ -24,7 +24,7 @@ export function AgeRestrictedScreen({
|
|||||||
}) {
|
}) {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const copy = useAgeAssuranceCopy()
|
const copy = useAgeAssuranceCopy()
|
||||||
const {isReady, isAgeRestricted} = useAgeInfo()
|
const {isReady, isAgeRestricted} = useAgeAssurance()
|
||||||
|
|
||||||
if (!isReady) {
|
if (!isReady) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
} from '#/lib/routes/types'
|
} from '#/lib/routes/types'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {isIOS} from '#/platform/detection'
|
import {isIOS} from '#/platform/detection'
|
||||||
import {useAgeInfo} from '#/state/ageAssurance/useAgeInfo'
|
import {useAgeAssurance} from '#/state/ageAssurance/useAgeAssurance'
|
||||||
import {
|
import {
|
||||||
useMyLabelersQuery,
|
useMyLabelersQuery,
|
||||||
usePreferencesQuery,
|
usePreferencesQuery,
|
||||||
@@ -86,7 +86,7 @@ export function ModerationScreen(
|
|||||||
error: preferencesError,
|
error: preferencesError,
|
||||||
data: preferences,
|
data: preferences,
|
||||||
} = usePreferencesQuery()
|
} = usePreferencesQuery()
|
||||||
const {isReady: isAgeInfoReady} = useAgeInfo()
|
const {isReady: isAgeInfoReady} = useAgeAssurance()
|
||||||
|
|
||||||
const isLoading = isPreferencesLoading || !isAgeInfoReady
|
const isLoading = isPreferencesLoading || !isAgeInfoReady
|
||||||
const error = preferencesError
|
const error = preferencesError
|
||||||
@@ -160,7 +160,7 @@ export function ModerationScreenInner({
|
|||||||
data: labelers,
|
data: labelers,
|
||||||
error: labelersError,
|
error: labelersError,
|
||||||
} = useMyLabelersQuery()
|
} = useMyLabelersQuery()
|
||||||
const {declaredAge, isUnderage, isAgeRestricted} = useAgeInfo()
|
const {declaredAge, isUnderage, isAgeRestricted} = useAgeAssurance()
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {usePreferencesQuery} from '#/state/queries/preferences'
|
|||||||
|
|
||||||
const logger = Logger.create(Logger.Context.AgeAssurance)
|
const logger = Logger.create(Logger.Context.AgeAssurance)
|
||||||
|
|
||||||
type AgeInfo = {
|
type AgeAssurance = {
|
||||||
isReady: boolean
|
isReady: boolean
|
||||||
declaredAge: number | undefined
|
declaredAge: number | undefined
|
||||||
isUnderage: boolean
|
isUnderage: boolean
|
||||||
@@ -20,7 +20,7 @@ type AgeInfo = {
|
|||||||
* declared age. Use this instead of {@link useAgeAssuranceContext} to get a
|
* declared age. Use this instead of {@link useAgeAssuranceContext} to get a
|
||||||
* more user-friendly interface.
|
* more user-friendly interface.
|
||||||
*/
|
*/
|
||||||
export function useAgeInfo(): AgeInfo {
|
export function useAgeAssurance(): AgeAssurance {
|
||||||
const ctx = useAgeAssuranceContext()
|
const ctx = useAgeAssuranceContext()
|
||||||
const {isAgeRestricted} = useIsAgeRestricted()
|
const {isAgeRestricted} = useIsAgeRestricted()
|
||||||
const {isFetched: preferencesLoaded, data: preferences} =
|
const {isFetched: preferencesLoaded, data: preferences} =
|
||||||
@@ -30,7 +30,7 @@ export function useAgeInfo(): AgeInfo {
|
|||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
const isReady = ctx.isReady && preferencesLoaded
|
const isReady = ctx.isReady && preferencesLoaded
|
||||||
const isUnderage = (declaredAge || 0) < 18
|
const isUnderage = (declaredAge || 0) < 18
|
||||||
const info: AgeInfo = {
|
const state: AgeAssurance = {
|
||||||
isReady,
|
isReady,
|
||||||
declaredAge,
|
declaredAge,
|
||||||
isUnderage,
|
isUnderage,
|
||||||
@@ -38,7 +38,7 @@ export function useAgeInfo(): AgeInfo {
|
|||||||
|
|
||||||
assurance: ctx,
|
assurance: ctx,
|
||||||
}
|
}
|
||||||
logger.debug(`useAgeInfo`, info)
|
logger.debug(`state`, state)
|
||||||
return info
|
return state
|
||||||
}, [ctx, preferencesLoaded, declaredAge, isAgeRestricted])
|
}, [ctx, preferencesLoaded, declaredAge, isAgeRestricted])
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user