All files / web/src/contexts GameThemeContext.tsx

100% Statements 39/39
100% Branches 5/5
100% Functions 2/2
100% Lines 39/39

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 401x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 13x 13x 5x 13x 13x 13x 13x 13x 13x 13x 13x 1x 1x 17x 17x 4x 4x 13x 13x  
'use client'
 
import { createContext, type ReactNode, useContext, useEffect, useState } from 'react'
 
export interface GameTheme {
  gameName: string
  backgroundColor: string
}
 
interface GameThemeContextType {
  theme: GameTheme | null
  setTheme: (theme: GameTheme | null) => void
  isHydrated: boolean
}
 
const GameThemeContext = createContext<GameThemeContextType | undefined>(undefined)
 
export function GameThemeProvider({ children }: { children: ReactNode }) {
  const [theme, setTheme] = useState<GameTheme | null>(null)
  const [isHydrated, setIsHydrated] = useState(false)
 
  useEffect(() => {
    setIsHydrated(true)
  }, [])
 
  return (
    <GameThemeContext.Provider value={{ theme, setTheme, isHydrated }}>
      {children}
    </GameThemeContext.Provider>
  )
}
 
export function useGameTheme() {
  const context = useContext(GameThemeContext)
  if (context === undefined) {
    throw new Error('useGameTheme must be used within a GameThemeProvider')
  }
  return context
}