-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#304]
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
packages/frontend/src/contexts/QuizCoachContext/QuizCoachProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ReactNode, useCallback, useMemo, useState } from "react"; | ||
|
||
import { QuizCoachActionContext, QuizCoachContext } from "./quizCoachContext"; | ||
|
||
interface QuizCoachProviderProps { | ||
children: ReactNode; | ||
} | ||
|
||
export function QuizCoachProvider({ children }: QuizCoachProviderProps) { | ||
const [run, setRun] = useState(false); | ||
|
||
const handleEnd = useCallback(() => { | ||
setRun(false); | ||
}, []); | ||
|
||
const handleStart = useCallback(() => { | ||
setRun(true); | ||
}, []); | ||
|
||
const quizCoachActionContextValue = useMemo( | ||
() => ({ handleEnd, handleStart }), | ||
[handleEnd, handleStart], | ||
); | ||
|
||
return ( | ||
<QuizCoachContext.Provider value={run}> | ||
<QuizCoachActionContext.Provider value={quizCoachActionContextValue}> | ||
{children} | ||
</QuizCoachActionContext.Provider> | ||
</QuizCoachContext.Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { | ||
useQuizCoachContext, | ||
useQuizCoachActionContext, | ||
} from "./quizCoachContext"; | ||
export { QuizCoachProvider } from "./QuizCoachProvider"; |
19 changes: 19 additions & 0 deletions
19
packages/frontend/src/contexts/QuizCoachContext/quizCoachContext.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { createContext, useContext } from "react"; | ||
|
||
type QuizCoachActionContextType = { | ||
handleEnd: () => void; | ||
handleStart: () => void; | ||
}; | ||
|
||
export const QuizCoachContext = createContext(false); | ||
export const QuizCoachActionContext = createContext<QuizCoachActionContextType>( | ||
{} as QuizCoachActionContextType, | ||
); | ||
|
||
export function useQuizCoachContext() { | ||
return useContext(QuizCoachContext); | ||
} | ||
|
||
export function useQuizCoachActionContext() { | ||
return useContext(QuizCoachActionContext); | ||
} |