mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-25 10:10:08 +02:00
[web] Ensure only one tutorial shows at once GitOrigin-RevId: 797c677a3d45635451485d79ed1c0705819ed5ad
36 lines
964 B
TypeScript
36 lines
964 B
TypeScript
import React, {
|
|
type FC,
|
|
type PropsWithChildren,
|
|
useCallback,
|
|
useRef,
|
|
useState,
|
|
} from 'react'
|
|
import { TutorialContext } from '@/shared/context/tutorial-context'
|
|
|
|
export const makeTutorialProvider = (opts?: {
|
|
inactiveTutorials: string[]
|
|
}) => {
|
|
const TutorialProvider: FC<PropsWithChildren> = ({ children }) => {
|
|
const [inactiveTutorials, setInactiveTutorials] = useState<string[]>(
|
|
opts?.inactiveTutorials ?? []
|
|
)
|
|
const currentPopupRef = useRef<string | null>(null)
|
|
const deactivateTutorial = useCallback((key: string) => {
|
|
setInactiveTutorials(prev => (prev.includes(key) ? prev : [...prev, key]))
|
|
}, [])
|
|
const value = {
|
|
deactivateTutorial,
|
|
inactiveTutorials,
|
|
currentPopup: null,
|
|
currentPopupRef,
|
|
setCurrentPopup: () => {},
|
|
}
|
|
return (
|
|
<TutorialContext.Provider value={value}>
|
|
{children}
|
|
</TutorialContext.Provider>
|
|
)
|
|
}
|
|
return TutorialProvider
|
|
}
|