Bluesky app fork with some witchin' additions 馃挮
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 77 lines 2.1 kB view raw
1import {createContext, useContext, useMemo} from 'react' 2 3import {useLanguagePrefs} from '#/state/preferences/languages' 4import {useServiceConfigQuery} from '#/state/queries/service-config' 5import {device} from '#/storage' 6 7type TrendingContext = { 8 enabled: boolean 9} 10 11const TrendingContext = createContext<TrendingContext>({ 12 enabled: false, 13}) 14TrendingContext.displayName = 'TrendingContext' 15 16const CheckEmailConfirmedContext = createContext<boolean | null>(null) 17 18export function Provider({children}: {children: React.ReactNode}) { 19 const langPrefs = useLanguagePrefs() 20 const {data: config, isLoading: isInitialLoad} = useServiceConfigQuery() 21 const trending = useMemo<TrendingContext>(() => { 22 if (__DEV__) { 23 return {enabled: true} 24 } 25 26 /* 27 * Only English during beta period 28 */ 29 if ( 30 !!langPrefs.contentLanguages.length && 31 !langPrefs.contentLanguages.includes('en') 32 ) { 33 return {enabled: false} 34 } 35 36 /* 37 * While loading, use cached value 38 */ 39 const cachedEnabled = device.get(['trendingBetaEnabled']) 40 if (isInitialLoad) { 41 return {enabled: Boolean(cachedEnabled)} 42 } 43 44 const enabled = Boolean(config?.topicsEnabled) 45 46 // update cache 47 device.set(['trendingBetaEnabled'], enabled) 48 49 return {enabled} 50 }, [isInitialLoad, config, langPrefs.contentLanguages]) 51 52 // probably true, so default to true when loading 53 // if the call fails, the query will set it to false for us 54 const checkEmailConfirmed = config?.checkEmailConfirmed ?? true 55 56 return ( 57 <TrendingContext.Provider value={trending}> 58 <CheckEmailConfirmedContext.Provider value={checkEmailConfirmed}> 59 {children} 60 </CheckEmailConfirmedContext.Provider> 61 </TrendingContext.Provider> 62 ) 63} 64 65export function useTrendingConfig() { 66 return useContext(TrendingContext) 67} 68 69export function useCheckEmailConfirmed() { 70 const ctx = useContext(CheckEmailConfirmedContext) 71 if (ctx === null) { 72 throw new Error( 73 'useCheckEmailConfirmed must be used within a ServiceConfigManager', 74 ) 75 } 76 return ctx 77}