make-tutorial-provider.tsx 875 B

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