@@ -4,12 +4,7 @@ import { sendMessageToDevvit } from '../utils';
44import { useDevvitListener } from './useDevvitListener' ;
55import { logger } from '../utils/logger' ;
66import { useMocks } from './useMocks' ;
7-
8- type WordSubmissionStateContext = {
9- isSubmitting : boolean ;
10- setIsSubmitting : ( isSubmitting : boolean ) => void ;
11- } ;
12- const WordSubmissionContext = createContext < WordSubmissionStateContext | null > ( null ) ;
7+ import { useWordSubmission } from './useWordSubmission' ;
138
149const GameContext = createContext < Partial < Game > > ( { } ) ;
1510const GameUpdaterContext = createContext < React . Dispatch <
@@ -19,7 +14,7 @@ const GameUpdaterContext = createContext<React.Dispatch<
1914export const GameContextProvider = ( { children } : { children : React . ReactNode } ) => {
2015 const mocks = useMocks ( ) ;
2116 const [ game , setGame ] = useState < Partial < Game > > ( mocks . getMock ( 'mocks' ) ?. game ?? { } ) ;
22- const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
17+ const { setIsSubmitting } = useWordSubmission ( ) ;
2318
2419 const initResponse = useDevvitListener ( 'GAME_INIT_RESPONSE' ) ;
2520 const submissionResponse = useDevvitListener ( 'WORD_SUBMITTED_RESPONSE' ) ;
@@ -47,7 +42,7 @@ export const GameContextProvider = ({ children }: { children: React.ReactNode })
4742 setGame ( submissionResponse ) ;
4843 setIsSubmitting ( false ) ;
4944 }
50- } , [ submissionResponse ] ) ;
45+ } , [ submissionResponse , setIsSubmitting ] ) ;
5146
5247 useEffect ( ( ) => {
5348 logger . log ( 'Hint response: ' , hintResponse ) ;
@@ -65,9 +60,7 @@ export const GameContextProvider = ({ children }: { children: React.ReactNode })
6560
6661 return (
6762 < GameUpdaterContext . Provider value = { setGame } >
68- < WordSubmissionContext . Provider value = { { isSubmitting, setIsSubmitting } } >
69- < GameContext . Provider value = { game } > { children } </ GameContext . Provider >
70- </ WordSubmissionContext . Provider >
63+ < GameContext . Provider value = { game } > { children } </ GameContext . Provider >
7164 </ GameUpdaterContext . Provider >
7265 ) ;
7366} ;
@@ -87,11 +80,3 @@ export const useSetGame = () => {
8780 }
8881 return setGame ;
8982} ;
90-
91- export const useWordSubmission = ( ) => {
92- const context = useContext ( WordSubmissionContext ) ;
93- if ( context === null ) {
94- throw new Error ( 'useWordSubmission must be used within a WordSubmissionProvider' ) ;
95- }
96- return context ;
97- } ;
0 commit comments