remove query call, pass from context
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {STALE} from '#/state/queries'
|
||||
import {useProfileQuery} from '#/state/queries/profile'
|
||||
import {useServiceConfigQuery} from '#/state/queries/service-config'
|
||||
import {useCheckEmailConfirmed} from '#/state/service-config'
|
||||
import {useSession} from '#/state/session'
|
||||
import {BSKY_SERVICE} from '../constants'
|
||||
import {getHostnameFromUrl} from '../strings/url-helpers'
|
||||
@@ -8,13 +8,12 @@ import {getHostnameFromUrl} from '../strings/url-helpers'
|
||||
export function useEmail() {
|
||||
const {currentAccount} = useSession()
|
||||
|
||||
const {data: serviceConfig} = useServiceConfigQuery()
|
||||
const {data: profile} = useProfileQuery({
|
||||
did: currentAccount?.did,
|
||||
staleTime: STALE.INFINITY,
|
||||
})
|
||||
|
||||
const checkEmailConfirmed = !!serviceConfig?.checkEmailConfirmed
|
||||
const checkEmailConfirmed = useCheckEmailConfirmed()
|
||||
|
||||
// Date set for 11 AM PST on the 18th of November
|
||||
const isNewEnough =
|
||||
|
||||
@@ -19,6 +19,8 @@ const TrendingContext = createContext<TrendingContext>({
|
||||
|
||||
const LiveNowContext = createContext<LiveNowContext | null>(null)
|
||||
|
||||
const CheckEmailConfirmedContext = createContext<boolean | null>(null)
|
||||
|
||||
export function Provider({children}: {children: React.ReactNode}) {
|
||||
const langPrefs = useLanguagePrefs()
|
||||
const {data: config, isLoading: isInitialLoad} = useServiceConfigQuery()
|
||||
@@ -59,10 +61,16 @@ export function Provider({children}: {children: React.ReactNode}) {
|
||||
|
||||
const liveNow = useMemo<LiveNowContext>(() => config?.liveNow ?? [], [config])
|
||||
|
||||
// probably true, so default to true when loading
|
||||
// if the call fails, the query will set it to false for us
|
||||
const checkEmailConfirmed = config?.checkEmailConfirmed ?? true
|
||||
|
||||
return (
|
||||
<TrendingContext.Provider value={trending}>
|
||||
<LiveNowContext.Provider value={liveNow}>
|
||||
{children}
|
||||
<CheckEmailConfirmedContext.Provider value={checkEmailConfirmed}>
|
||||
{children}
|
||||
</CheckEmailConfirmedContext.Provider>
|
||||
</LiveNowContext.Provider>
|
||||
</TrendingContext.Provider>
|
||||
)
|
||||
@@ -76,7 +84,7 @@ export function useLiveNowConfig() {
|
||||
const ctx = useContext(LiveNowContext)
|
||||
if (!ctx) {
|
||||
throw new Error(
|
||||
'useLiveNowConfig must be used within a LiveNowConfigProvider',
|
||||
'useLiveNowConfig must be used within a ServiceConfigManager',
|
||||
)
|
||||
}
|
||||
return ctx
|
||||
@@ -86,3 +94,13 @@ export function useCanGoLive(did?: string) {
|
||||
const config = useLiveNowConfig()
|
||||
return !!config.find(cfg => cfg.did === did)
|
||||
}
|
||||
|
||||
export function useCheckEmailConfirmed() {
|
||||
const ctx = useContext(CheckEmailConfirmedContext)
|
||||
if (!ctx) {
|
||||
throw new Error(
|
||||
'useCheckEmailConfirmed must be used within a ServiceConfigManager',
|
||||
)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user