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> {
|
async function fetchAppConfig(): Promise<AppConfigResponse | null> {
|
||||||
try {
|
try {
|
||||||
@@ -37,15 +37,13 @@ async function fetchAppConfig(): Promise<AppConfigResponse | null> {
|
|||||||
async () => {
|
async () => {
|
||||||
const r = await fetch(`${APP_CONFIG_URL}/config`)
|
const r = await fetch(`${APP_CONFIG_URL}/config`)
|
||||||
if (!r.ok) throw new Error(await r.text())
|
if (!r.ok) throw new Error(await r.text())
|
||||||
return r
|
const data = await r.json()
|
||||||
|
return data
|
||||||
},
|
},
|
||||||
1e3,
|
1e3,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
const res = await fetchAppConfigPromise
|
return await fetchAppConfigPromise
|
||||||
if (!res.ok) return null
|
|
||||||
const data = await res.json()
|
|
||||||
return data
|
|
||||||
} catch {
|
} catch {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,19 +8,11 @@ type TrendingContext = {
|
|||||||
enabled: boolean
|
enabled: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
type LiveNowContext = {
|
|
||||||
did: string
|
|
||||||
domains: string[]
|
|
||||||
}[]
|
|
||||||
|
|
||||||
const TrendingContext = createContext<TrendingContext>({
|
const TrendingContext = createContext<TrendingContext>({
|
||||||
enabled: false,
|
enabled: false,
|
||||||
})
|
})
|
||||||
TrendingContext.displayName = 'TrendingContext'
|
TrendingContext.displayName = 'TrendingContext'
|
||||||
|
|
||||||
const LiveNowContext = createContext<LiveNowContext>([])
|
|
||||||
LiveNowContext.displayName = 'LiveNowContext'
|
|
||||||
|
|
||||||
const CheckEmailConfirmedContext = createContext<boolean | null>(null)
|
const CheckEmailConfirmedContext = createContext<boolean | null>(null)
|
||||||
|
|
||||||
export function Provider({children}: {children: React.ReactNode}) {
|
export function Provider({children}: {children: React.ReactNode}) {
|
||||||
@@ -57,19 +49,15 @@ export function Provider({children}: {children: React.ReactNode}) {
|
|||||||
return {enabled}
|
return {enabled}
|
||||||
}, [isInitialLoad, config, langPrefs.contentLanguages])
|
}, [isInitialLoad, config, langPrefs.contentLanguages])
|
||||||
|
|
||||||
const liveNow = useMemo<LiveNowContext>(() => config?.liveNow ?? [], [config])
|
|
||||||
|
|
||||||
// probably true, so default to true when loading
|
// probably true, so default to true when loading
|
||||||
// if the call fails, the query will set it to false for us
|
// if the call fails, the query will set it to false for us
|
||||||
const checkEmailConfirmed = config?.checkEmailConfirmed ?? true
|
const checkEmailConfirmed = config?.checkEmailConfirmed ?? true
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TrendingContext.Provider value={trending}>
|
<TrendingContext.Provider value={trending}>
|
||||||
<LiveNowContext.Provider value={liveNow}>
|
<CheckEmailConfirmedContext.Provider value={checkEmailConfirmed}>
|
||||||
<CheckEmailConfirmedContext.Provider value={checkEmailConfirmed}>
|
{children}
|
||||||
{children}
|
</CheckEmailConfirmedContext.Provider>
|
||||||
</CheckEmailConfirmedContext.Provider>
|
|
||||||
</LiveNowContext.Provider>
|
|
||||||
</TrendingContext.Provider>
|
</TrendingContext.Provider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user