Register push after aa state
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import {createContext, useContext, useMemo} from 'react'
|
import {createContext, useContext, useMemo} from 'react'
|
||||||
import {type AppBskyUnspeccedDefs} from '@atproto/api'
|
import {type AppBskyUnspeccedDefs} from '@atproto/api'
|
||||||
import {useQuery, useQueryClient} from '@tanstack/react-query'
|
import {useQuery} from '@tanstack/react-query'
|
||||||
|
|
||||||
|
import {useGetAndRegisterPushToken} from '#/lib/notifications/notifications'
|
||||||
// import {wait} from '#/lib/async/wait'
|
// import {wait} from '#/lib/async/wait'
|
||||||
import {isNetworkError} from '#/lib/strings/errors'
|
import {isNetworkError} from '#/lib/strings/errors'
|
||||||
import {Logger} from '#/logger'
|
import {Logger} from '#/logger'
|
||||||
@@ -10,7 +11,6 @@ import {
|
|||||||
type AgeAssuranceContextType,
|
type AgeAssuranceContextType,
|
||||||
} from '#/state/age-assurance/types'
|
} from '#/state/age-assurance/types'
|
||||||
import {useGeolocation} from '#/state/geolocation'
|
import {useGeolocation} from '#/state/geolocation'
|
||||||
import {preferencesQueryKey} from '#/state/queries/preferences'
|
|
||||||
import {useAgent} from '#/state/session'
|
import {useAgent} from '#/state/session'
|
||||||
|
|
||||||
const logger = Logger.create(Logger.Context.AgeAssurance)
|
const logger = Logger.create(Logger.Context.AgeAssurance)
|
||||||
@@ -34,9 +34,10 @@ const AgeAssuranceAPIContext = createContext<AgeAssuranceAPIContextType>({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export function Provider({children}: {children: React.ReactNode}) {
|
export function Provider({children}: {children: React.ReactNode}) {
|
||||||
const qc = useQueryClient()
|
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
const {geolocation} = useGeolocation()
|
const {geolocation} = useGeolocation()
|
||||||
|
const getAndRegisterPushToken = useGetAndRegisterPushToken()
|
||||||
|
const isAgeRestrictedGeo = !!geolocation?.isAgeRestrictedGeo
|
||||||
|
|
||||||
const {data, isFetched, refetch} = useQuery({
|
const {data, isFetched, refetch} = useQuery({
|
||||||
/**
|
/**
|
||||||
@@ -66,7 +67,14 @@ export function Provider({children}: {children: React.ReactNode}) {
|
|||||||
account: agent.session?.did,
|
account: agent.session?.did,
|
||||||
})
|
})
|
||||||
|
|
||||||
qc.invalidateQueries({queryKey: preferencesQueryKey})
|
// TODO pretty sure we don't need this
|
||||||
|
// qc.invalidateQueries({queryKey: preferencesQueryKey})
|
||||||
|
|
||||||
|
await getAndRegisterPushToken({
|
||||||
|
isAgeRestricted: Boolean(
|
||||||
|
isAgeRestrictedGeo && data.status !== 'assured',
|
||||||
|
),
|
||||||
|
})
|
||||||
|
|
||||||
return data
|
return data
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -80,7 +88,6 @@ export function Provider({children}: {children: React.ReactNode}) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const ageAssuranceContext = useMemo<AgeAssuranceContextType>(() => {
|
const ageAssuranceContext = useMemo<AgeAssuranceContextType>(() => {
|
||||||
const isAgeRestrictedGeo = !!geolocation?.isAgeRestrictedGeo
|
|
||||||
const {status, lastInitiatedAt} = data || DEFAULT_AGE_ASSURANCE_STATE
|
const {status, lastInitiatedAt} = data || DEFAULT_AGE_ASSURANCE_STATE
|
||||||
const ctx: AgeAssuranceContextType = {
|
const ctx: AgeAssuranceContextType = {
|
||||||
status,
|
status,
|
||||||
@@ -94,7 +101,7 @@ export function Provider({children}: {children: React.ReactNode}) {
|
|||||||
logger.debug(`context`, ctx)
|
logger.debug(`context`, ctx)
|
||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
}, [geolocation, isFetched, data])
|
}, [isAgeRestrictedGeo, isFetched, data])
|
||||||
|
|
||||||
const ageAssuranceAPIContext = useMemo<AgeAssuranceAPIContextType>(
|
const ageAssuranceAPIContext = useMemo<AgeAssuranceAPIContextType>(
|
||||||
() => ({
|
() => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user