make-tutorial-provider.tsx 964 B

1234567891011121314151617181920212223242526272829303132333435
  1. import React, {
  2. type FC,
  3. type PropsWithChildren,
  4. useCallback,
  5. useRef,
  6. useState,
  7. } from 'react'
  8. import { TutorialContext } from '@/shared/context/tutorial-context'
  9. export const makeTutorialProvider = (opts?: {
  10. inactiveTutorials: string[]
  11. }) => {
  12. const TutorialProvider: FC<PropsWithChildren> = ({ children }) => {
  13. const [inactiveTutorials, setInactiveTutorials] = useState<string[]>(
  14. opts?.inactiveTutorials ?? []
  15. )
  16. const currentPopupRef = useRef<string | null>(null)
  17. const deactivateTutorial = useCallback((key: string) => {
  18. setInactiveTutorials(prev => (prev.includes(key) ? prev : [...prev, key]))
  19. }, [])
  20. const value = {
  21. deactivateTutorial,
  22. inactiveTutorials,
  23. currentPopup: null,
  24. currentPopupRef,
  25. setCurrentPopup: () => {},
  26. }
  27. return (
  28. <TutorialContext.Provider value={value}>
  29. {children}
  30. </TutorialContext.Provider>
  31. )
  32. }
  33. return TutorialProvider
  34. }