nomadro/apps/miniprogram/h5/src/components/MiniModuleGate.tsx
eric 3e5b7c2098 Monorepo super-optimize: src layout, workspace scripts, docs.
Collapse portal under src/, unify pnpm workspace/scripts, thin VIP topic re-exports, drop orphan vip scaffolds and one-shot scripts, ignore xhs/release, document root commands.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 00:34:04 +08:00

41 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { useEffect, useState, type ReactNode } from 'react'
import { View, Text } from '@tarojs/components'
import {
getCachedRemoteConfig,
isModuleEnabled,
loadRemoteConfig,
} from '@/services/remoteConfig'
import type { NomadroRemoteConfig } from '@/data/remoteConfig.defaults'
type ModuleKey = keyof NomadroRemoteConfig['modules']
/** 小程序页级模块闸门:对齐门户 ModuleGate(首屏放行,无技术文案) */
export function MiniModuleGate({
moduleKey,
children,
}: {
moduleKey: ModuleKey
children: ReactNode
}) {
const [enabled, setEnabled] = useState(true)
useEffect(() => {
const cached = getCachedRemoteConfig()
setEnabled(isModuleEnabled(cached, moduleKey))
loadRemoteConfig().then((r) => {
setEnabled(isModuleEnabled(r.config, moduleKey))
})
}, [moduleKey])
if (!enabled) {
return (
<View className="sub">
<Text className="h">暂时无法打开</Text>
<Text className="p">该内容暂未开放,稍后再来看看吧。</Text>
</View>
)
}
return <>{children}</>
}