This commit is contained in:
Eric Bailey
2026-02-16 10:21:16 -06:00
parent 4e89ffc790
commit 85ca5ccf22
2 changed files with 7 additions and 21 deletions
+4 -6
View File
@@ -27,7 +27,7 @@ export const DEFAULT_APP_CONFIG_RESPONSE: AppConfigResponse = {
},
}
let fetchAppConfigPromise: Promise<Response>
let fetchAppConfigPromise: Promise<AppConfigResponse>
async function fetchAppConfig(): Promise<AppConfigResponse | null> {
try {
@@ -37,15 +37,13 @@ async function fetchAppConfig(): Promise<AppConfigResponse | null> {
async () => {
const r = await fetch(`${APP_CONFIG_URL}/config`)
if (!r.ok) throw new Error(await r.text())
return r
const data = await r.json()
return data
},
1e3,
)
}
const res = await fetchAppConfigPromise
if (!res.ok) return null
const data = await res.json()
return data
return await fetchAppConfigPromise
} catch {
return null
}
+3 -15
View File
@@ -8,19 +8,11 @@ type TrendingContext = {
enabled: boolean
}
type LiveNowContext = {
did: string
domains: string[]
}[]
const TrendingContext = createContext<TrendingContext>({
enabled: false,
})
TrendingContext.displayName = 'TrendingContext'
const LiveNowContext = createContext<LiveNowContext>([])
LiveNowContext.displayName = 'LiveNowContext'
const CheckEmailConfirmedContext = createContext<boolean | null>(null)
export function Provider({children}: {children: React.ReactNode}) {
@@ -57,19 +49,15 @@ export function Provider({children}: {children: React.ReactNode}) {
return {enabled}
}, [isInitialLoad, config, langPrefs.contentLanguages])
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}>
<CheckEmailConfirmedContext.Provider value={checkEmailConfirmed}>
{children}
</CheckEmailConfirmedContext.Provider>
</LiveNowContext.Provider>
<CheckEmailConfirmedContext.Provider value={checkEmailConfirmed}>
{children}
</CheckEmailConfirmedContext.Provider>
</TrendingContext.Provider>
)
}