Update package, rm langs
This commit is contained in:
@@ -5,8 +5,7 @@ import {useAgent} from '#/state/session'
|
||||
|
||||
type ServiceConfig = {
|
||||
checkEmailConfirmed: boolean
|
||||
trendingTopicsEnabled: boolean
|
||||
trendingTopicsLangs: string[]
|
||||
topicsEnabled: boolean
|
||||
}
|
||||
|
||||
export function useServiceConfigQuery() {
|
||||
@@ -20,14 +19,12 @@ export function useServiceConfigQuery() {
|
||||
const {data} = await agent.api.app.bsky.unspecced.getConfig()
|
||||
return {
|
||||
checkEmailConfirmed: Boolean(data.checkEmailConfirmed),
|
||||
trendingTopicsEnabled: Boolean(data.trendingTopicsEnabled),
|
||||
trendingTopicsLangs: (data.trendingTopicsLangs ?? []) as string[],
|
||||
topicsEnabled: Boolean(data.topicsEnabled),
|
||||
}
|
||||
} catch (e) {
|
||||
return {
|
||||
checkEmailConfirmed: false,
|
||||
trendingTopicsEnabled: false,
|
||||
trendingTopicsLangs: [],
|
||||
topicsEnabled: false,
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import React from 'react'
|
||||
|
||||
import {useLanguagePrefs} from '#/state/preferences/languages'
|
||||
import {useServiceConfigQuery} from '#/state/queries/service-config'
|
||||
import {device} from '#/storage'
|
||||
|
||||
@@ -13,7 +12,6 @@ const Context = React.createContext<Context>({
|
||||
})
|
||||
|
||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const langPrefs = useLanguagePrefs()
|
||||
// refetches at most every minute
|
||||
const {data: config, isLoading: isInitialLoad} = useServiceConfigQuery()
|
||||
const ctx = React.useMemo<Context>(() => {
|
||||
@@ -22,15 +20,11 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
if (isInitialLoad) {
|
||||
return {enabled: Boolean(cachedEnabled)}
|
||||
}
|
||||
const serviceEnabled = Boolean(config?.trendingTopicsEnabled)
|
||||
const languageIsSupported = langPrefs.contentLanguages.some(lang => {
|
||||
return (config?.trendingTopicsLangs ?? []).includes(lang)
|
||||
})
|
||||
const enabled = serviceEnabled && languageIsSupported
|
||||
const enabled = Boolean(config?.topicsEnabled)
|
||||
// update cache
|
||||
device.set(['trendingBetaEnabled'], enabled)
|
||||
return {enabled}
|
||||
}, [isInitialLoad, config, langPrefs])
|
||||
}, [isInitialLoad, config])
|
||||
return <Context.Provider value={ctx}>{children}</Context.Provider>
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user