- 在 .gitignore 中添加 public/audio/* 以忽略音频文件。 - 更新 bun.lock,添加 eslint-config-prettier 和 eslint-plugin-prettier 依赖,确保 ESLint 与 Prettier 的兼容性。 - 修改 eslint.config.ts,整合 Prettier 规则,优化代码风格一致性。 - 在 package.json 中添加 lint:fix 和 format 脚本,简化代码格式化和修复流程。 - 更新 tailwind.config.ts 和其他组件文件,统一代码风格,提升可读性。
43 lines
1011 B
TypeScript
43 lines
1011 B
TypeScript
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
|
|
}
|