Cleanup
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user