Files
jiang13-bbs/frontend/components/MotionProvider.tsx
freefire 2b27703e6c feat(settings): 站点界面动画总开关与子开关
管理后台可关全站动画,并细调代码折叠、平滑滚动、装饰入场;统一 lib/motion,尊重系统减少动态效果。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-16 06:59:26 +08:00

53 lines
1.4 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.
"use client";
import { useEffect, type ReactNode } from "react";
import {
applyMotionSiteConfig,
getMotionSiteConfig,
motionConfigFromSettings,
type MotionSiteConfig,
} from "@/lib/motion";
import { realtime, RT_SETTINGS_CHANGED, type RtSettingsData } from "@/lib/realtime";
/**
* 根布局注入:SSR 初值写入 motion 模块 + html class;settings:changed 热更新。
*/
export default function MotionProvider({
initial,
children,
}: {
initial: MotionSiteConfig;
children: ReactNode;
}) {
useEffect(() => {
applyMotionSiteConfig(motionConfigFromSettings(initial));
}, [initial]);
useEffect(() => {
return realtime.on<RtSettingsData>(RT_SETTINGS_CHANGED, (data) => {
if (!data) return;
const cur = getMotionSiteConfig();
applyMotionSiteConfig(
motionConfigFromSettings({
ui_animations:
typeof data.ui_animations === "boolean"
? data.ui_animations
: cur.ui_animations,
anim_code_fold:
typeof data.anim_code_fold === "boolean"
? data.anim_code_fold
: cur.anim_code_fold,
anim_smooth_scroll:
typeof data.anim_smooth_scroll === "boolean"
? data.anim_smooth_scroll
: cur.anim_smooth_scroll,
anim_chrome:
typeof data.anim_chrome === "boolean" ? data.anim_chrome : cur.anim_chrome,
})
);
});
}, []);
return children;
}