diff options
Diffstat (limited to 'src/state/service-config.tsx')
-rw-r--r-- | src/state/service-config.tsx | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/state/service-config.tsx b/src/state/service-config.tsx index 94be5b445..242022b60 100644 --- a/src/state/service-config.tsx +++ b/src/state/service-config.tsx @@ -21,6 +21,8 @@ TrendingContext.displayName = 'TrendingContext' const LiveNowContext = createContext<LiveNowContext | null>(null) LiveNowContext.displayName = 'LiveNowContext' +const CheckEmailConfirmedContext = createContext<boolean | null>(null) + export function Provider({children}: {children: React.ReactNode}) { const langPrefs = useLanguagePrefs() const {data: config, isLoading: isInitialLoad} = useServiceConfigQuery() @@ -61,10 +63,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> ) @@ -78,7 +86,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 @@ -88,3 +96,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 === null) { + throw new Error( + 'useCheckEmailConfirmed must be used within a ServiceConfigManager', + ) + } + return ctx +} |