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
+61
View File
@@ -0,0 +1,61 @@
import {useMemo} from 'react'
import {useAppConfig} from '#/state/appConfig'
import {useSession} from '#/state/session'
import {useAnalytics} from '#/analytics'
export const DEFAULT_ALLOWED_DOMAINS = [
'twitch.tv',
'stream.place',
'bluecast.app',
// TODO remove need for subdomains
'www.twitch.tv',
'www.bluecast.app',
]
export type LiveNowConfig = {
canGoLive: boolean
currentAccountAllowedHosts: Set<string>
defaultAllowedHosts: Set<string>
allowedHostsExceptionsByDid: Map<string, Set<string>>
}
export function useLiveNowConfig(): LiveNowConfig {
const ax = useAnalytics()
const {liveNow} = useAppConfig()
const {currentAccount} = useSession()
return useMemo(() => {
const disabled = ax.features.enabled(ax.features.LiveNowBetaDisable)
if (!currentAccount?.did || disabled) {
return {
canGoLive: false,
currentAccountAllowedHosts: new Set(),
defaultAllowedHosts: new Set(),
allowedHostsExceptionsByDid: new Map(),
}
}
const defaultAllowedHosts = new Set(
DEFAULT_ALLOWED_DOMAINS.concat(liveNow.allow),
)
const allowedHostsExceptionsByDid = new Map<string, Set<string>>()
for (const ex of liveNow.exceptions) {
allowedHostsExceptionsByDid.set(
ex.did,
new Set(DEFAULT_ALLOWED_DOMAINS.concat(ex.allow)),
)
}
return {
canGoLive: true,
currentAccountAllowedHosts:
allowedHostsExceptionsByDid.get(currentAccount.did) ??
defaultAllowedHosts,
defaultAllowedHosts,
allowedHostsExceptionsByDid,
}
}, [ax, liveNow, currentAccount])
}