/** * Douyin launch: default BMI; homeVariant=hub jumps to portal hub. * Subscribe remote config so admin A/B applies without leaving the page. */ import { useEffect, useState } from 'react' import Taro, { useDidShow } from '@tarojs/taro' import { getCachedRemoteConfig, loadRemoteConfig, subscribeRemoteConfig, } from '@/services/remoteConfig' import { resolveTtHomeVariantFromConfig, type NomadroRemoteConfig, } from '@/data/remoteConfig.defaults' import { useNomadroTheme } from '@/utils/h5Theme' import BmiHome from './BmiHome' const HUB_PATH = '/pages/hub/index' export default function IndexPage() { const [config, setConfig] = useState(() => getCachedRemoteConfig()) const [ready, setReady] = useState(false) const theme = useNomadroTheme() function applyConfig(next: NomadroRemoteConfig): boolean { setConfig(next) if (resolveTtHomeVariantFromConfig(next) === 'hub') { Taro.reLaunch({ url: HUB_PATH }) return false } setReady(true) return true } async function syncVariant(force = false) { const r = await loadRemoteConfig(force) return applyConfig(r.config) } useEffect(() => { let cancelled = false const unsub = subscribeRemoteConfig((r) => { if (cancelled) return applyConfig(r.config) }) syncVariant(true).then((ok) => { if (cancelled || !ok) return }) if (resolveTtHomeVariantFromConfig(getCachedRemoteConfig()) !== 'hub') { setReady(true) } return () => { cancelled = true unsub() } }, []) useDidShow(() => { void syncVariant(true) }) if (!ready) return null return }