nomadro/apps/miniprogram/tt/src/pages/index/index.tsx
eric 8c5eb388c1 Scrub BMI medical copy and live-refresh Douyin home A/B + portals.
Rename titles to BMI指数, soften audit-sensitive tips, and subscribe remote config so homepage variant and entrance toggles apply within a few seconds.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-04 19:17:21 +08:00

66 lines
1.7 KiB
TypeScript

/**
* 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<NomadroRemoteConfig>(() => 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 <BmiHome config={config} theme={theme} />
}