Migrate to new useLiveNowConfig

This commit is contained in:
Eric Bailey
2026-02-13 11:00:33 -06:00
parent 240fd7bc92
commit 013c2924dc
7 changed files with 67 additions and 58 deletions
-52
View File
@@ -2,9 +2,6 @@ import {createContext, useContext, useMemo} from 'react'
import {useLanguagePrefs} from '#/state/preferences/languages'
import {useServiceConfigQuery} from '#/state/queries/service-config'
import {useSession} from '#/state/session'
import {useAnalytics} from '#/analytics'
import {IS_DEV} from '#/env'
import {device} from '#/storage'
type TrendingContext = {
@@ -81,55 +78,6 @@ export function useTrendingConfig() {
return useContext(TrendingContext)
}
const DEFAULT_LIVE_ALLOWED_DOMAINS = [
'twitch.tv',
'www.twitch.tv',
'stream.place',
'bluecast.app',
'www.bluecast.app',
]
export type LiveNowConfig = {
currentAccountAllowedHosts: Set<string>
defaultAllowedHosts: Set<string>
allowedHostsExceptionsByDid: Map<string, Set<string>>
}
export function useLiveNowConfig(): LiveNowConfig {
const ctx = useContext(LiveNowContext)
const canGoLive = useCanGoLive()
const {currentAccount} = useSession()
return useMemo(() => {
const defaultAllowedHosts = new Set(DEFAULT_LIVE_ALLOWED_DOMAINS)
const allowedHostsExceptionsByDid = new Map<string, Set<string>>()
for (const live of ctx) {
allowedHostsExceptionsByDid.set(
live.did,
new Set(DEFAULT_LIVE_ALLOWED_DOMAINS.concat(live.domains)),
)
}
if (!currentAccount?.did || !canGoLive)
return {
currentAccountAllowedHosts: new Set(),
defaultAllowedHosts,
allowedHostsExceptionsByDid,
}
const vip = ctx.find(live => live.did === currentAccount.did)
return {
currentAccountAllowedHosts: new Set(
DEFAULT_LIVE_ALLOWED_DOMAINS.concat(vip ? vip.domains : []),
),
defaultAllowedHosts,
allowedHostsExceptionsByDid,
}
}, [ctx, currentAccount, canGoLive])
}
export function useCanGoLive() {
const ax = useAnalytics()
const {hasSession} = useSession()
if (!hasSession) return false
return IS_DEV ? true : !ax.features.enabled(ax.features.LiveNowBetaDisable)
}
export function useCheckEmailConfirmed() {
const ctx = useContext(CheckEmailConfirmedContext)
if (ctx === null) {