feat:init

This commit is contained in:
zhongyidian committed 2025-12-29 19:19:10 +08:00
1 parent 53d0eeac6b
commit ae0c050010
494 files changed
+17701 -2318

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
import { createContext, useContext, ReactNode } from "react";
interface VideoContextValue {
/** 视频是否正在播放 */
isVideoPlaying: boolean;
/** 内容是否可见 */
isContentVisible: boolean;
}
const VideoContext = createContext<VideoContextValue | undefined>(undefined);
export const VideoProvider = ({
children,
isVideoPlaying,
isContentVisible,
}: {
children: ReactNode;
isVideoPlaying: boolean;
isContentVisible: boolean;
}) => {
return (
<VideoContext.Provider value={{ isVideoPlaying, isContentVisible }}>
{children}
</VideoContext.Provider>
);
};
export const useVideoContext = () => {
const context = useContext(VideoContext);
if (context === undefined) {
throw new Error("useVideoContext must be used within a VideoProvider");
}
return context;
};
/**
* 安全地获取视频上下文,如果不在 VideoProvider 中则返回 null
*/
export const useVideoContextSafe = () => {
const context = useContext(VideoContext);
return context ?? null;
};