isLoaded -> isReady

This commit is contained in:
Eric Bailey
2025-07-15 17:04:30 -05:00
parent 13db34c590
commit 659e62ccc3
10 changed files with 24 additions and 21 deletions
@@ -20,9 +20,9 @@ import {createStaticClick, InlineLinkText} from '#/components/Link'
import {Text} from '#/components/Typography'
export function AgeAssuranceAccountCard({style}: ViewStyleProp & {}) {
const {isLoaded, isAgeRestricted, isUnderage} = useAgeInfo()
const {isReady, isAgeRestricted, isUnderage} = useAgeInfo()
if (!isLoaded) return null
if (!isReady) return null
if (isUnderage) return null
if (!isAgeRestricted) return null
@@ -15,9 +15,9 @@ export function AgeAssuranceAdmonition({
style,
}: ViewStyleProp & {children: React.ReactNode}) {
const control = useDialogControl()
const {isLoaded, isUnderage, isAgeRestricted} = useAgeInfo()
const {isReady, isUnderage, isAgeRestricted} = useAgeInfo()
if (!isLoaded) return null
if (!isReady) return null
if (isUnderage) return null
if (!isAgeRestricted) return null
@@ -12,13 +12,13 @@ import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times'
export function AgeAssuranceDismissableNotice({style}: ViewStyleProp & {}) {
const {_} = useLingui()
const {isLoaded, isUnderage, isAgeRestricted, assurance} = useAgeInfo()
const {isReady, isUnderage, isAgeRestricted, assurance} = useAgeInfo()
const {nux} = useNux(Nux.AgeAssuranceDismissableNotice)
const copy = useAgeAssuranceCopy()
const {mutate: save, variables} = useSaveNux()
const hidden = !!variables
if (!isLoaded) return null
if (!isReady) return null
if (isUnderage) return null
if (!isAgeRestricted) return null
if (assurance.lastInitiatedAt) return null
@@ -24,9 +24,9 @@ export function AgeRestrictedScreen({
}) {
const {_} = useLingui()
const copy = useAgeAssuranceCopy()
const {isLoaded, isAgeRestricted} = useAgeInfo()
const {isReady, isAgeRestricted} = useAgeInfo()
if (!isLoaded) {
if (!isReady) {
return (
<Layout.Screen>
<Layout.Header.Outer>
+2 -2
View File
@@ -86,9 +86,9 @@ export function ModerationScreen(
error: preferencesError,
data: preferences,
} = usePreferencesQuery()
const {isLoaded: isAgeInfoLoaded} = useAgeInfo()
const {isReady: isAgeInfoReady} = useAgeInfo()
const isLoading = isPreferencesLoading || !isAgeInfoLoaded
const isLoading = isPreferencesLoading || !isAgeInfoReady
const error = preferencesError
return (
+2 -2
View File
@@ -24,7 +24,7 @@ const DEFAULT_AGE_ASSURANCE_STATE: AppBskyUnspeccedDefs.AgeAssuranceState = {
}
const AgeAssuranceContext = createContext<AgeAssuranceContextType>({
status: 'unknown',
isLoaded: false,
isReady: false,
lastInitiatedAt: undefined,
})
const AgeAssuranceAPIContext = createContext<AgeAssuranceAPIContextType>({
@@ -99,7 +99,7 @@ export function Provider({children}: {children: React.ReactNode}) {
const ageAssuranceContext = useMemo<AgeAssuranceContextType>(() => {
const {status, lastInitiatedAt} = data || DEFAULT_AGE_ASSURANCE_STATE
const ctx: AgeAssuranceContextType = {
isLoaded: isFetched,
isReady: isFetched,
status,
lastInitiatedAt,
}
+4 -1
View File
@@ -2,7 +2,10 @@ import {type AppBskyUnspeccedDefs} from '@atproto/api'
import {type QueryObserverBaseResult} from '@tanstack/react-query'
export type AgeAssuranceContextType = {
isLoaded: boolean
/**
* Whether the age assurance state has been fetched from the server.
*/
isReady: boolean
/**
* The server-reported status of the user's age verification process.
*/
+3 -3
View File
@@ -8,7 +8,7 @@ import {usePreferencesQuery} from '#/state/queries/preferences'
const logger = Logger.create(Logger.Context.AgeAssurance)
type AgeInfo = {
isLoaded: boolean
isReady: boolean
declaredAge: number | undefined
isUnderage: boolean
isAgeRestricted: boolean
@@ -28,10 +28,10 @@ export function useAgeInfo(): AgeInfo {
const declaredAge = preferences?.userAge
return useMemo(() => {
const isLoaded = ctx.isLoaded && preferencesLoaded
const isReady = ctx.isReady && preferencesLoaded
const isUnderage = (declaredAge || 0) < 18
const info: AgeInfo = {
isLoaded,
isReady,
declaredAge,
isUnderage,
isAgeRestricted,
+3 -3
View File
@@ -5,7 +5,7 @@ import {useAgeAssuranceContext} from '#/state/ageAssurance'
import {useGeolocation} from '#/state/geolocation'
export function useIsAgeRestricted() {
const {isLoaded, status} = useAgeAssuranceContext()
const {isReady, status} = useAgeAssuranceContext()
const {geolocation} = useGeolocation()
const gate = useGate()
@@ -17,8 +17,8 @@ export function useIsAgeRestricted() {
}
}
return {
isReady: isLoaded,
isReady,
isAgeRestricted: status !== 'assured',
}
}, [isLoaded, status, geolocation, gate])
}, [isReady, status, geolocation, gate])
}
+2 -2
View File
@@ -139,12 +139,12 @@ export function usePostFeedQuery(
/**
* Load bearing: we need to await AA state or risk FOUC.
*/
const {isLoaded: isAALoaded} = useAgeAssuranceContext()
const {isReady: isAgeAssuranceReady} = useAgeAssuranceContext()
const enabled =
opts?.enabled !== false &&
Boolean(moderationOpts) &&
Boolean(preferences) &&
isAALoaded
isAgeAssuranceReady
const userInterests = aggregateUserInterests(preferences)
const followingPinnedIndex =
preferences?.savedFeeds?.findIndex(