From 06da1959b01badec0d5ac36daadaaa738206831d Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Mon, 11 Aug 2025 14:28:20 +0300 Subject: [PATCH] remove query call, pass from context --- src/lib/hooks/useEmail.ts | 5 ++--- src/state/service-config.tsx | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/lib/hooks/useEmail.ts b/src/lib/hooks/useEmail.ts index f215d0b5cb..37573c386d 100644 --- a/src/lib/hooks/useEmail.ts +++ b/src/lib/hooks/useEmail.ts @@ -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 = diff --git a/src/state/service-config.tsx b/src/state/service-config.tsx index 37d5685bd4..628a219269 100644 --- a/src/state/service-config.tsx +++ b/src/state/service-config.tsx @@ -19,6 +19,8 @@ const TrendingContext = createContext({ const LiveNowContext = createContext(null) +const CheckEmailConfirmedContext = createContext(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(() => 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 ( - {children} + + {children} + ) @@ -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 +}