Phase 5 complete
This commit is contained in:
parent
342ff60b70
commit
93ea01525e
7 changed files with 433 additions and 37 deletions
|
|
@ -21,6 +21,7 @@ export const useGame = () => {
|
|||
const [currentStreak, setCurrentStreak] = useState(0);
|
||||
const [currentPlayerId, setCurrentPlayerId] = useState<string | null>(null);
|
||||
const [currentPlayerName, setCurrentPlayerName] = useState<string | null>(null);
|
||||
const [pendingQuizToSave, setPendingQuizToSave] = useState<{ quiz: Quiz; topic: string } | null>(null);
|
||||
|
||||
const timerRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||
const peerRef = useRef<Peer | null>(null);
|
||||
|
|
@ -48,6 +49,7 @@ export const useGame = () => {
|
|||
setError(null);
|
||||
setRole('HOST');
|
||||
const generatedQuiz = await generateQuiz(topic);
|
||||
setPendingQuizToSave({ quiz: generatedQuiz, topic });
|
||||
initializeHostGame(generatedQuiz);
|
||||
} catch (e) {
|
||||
setError("Failed to generate quiz.");
|
||||
|
|
@ -55,12 +57,19 @@ export const useGame = () => {
|
|||
}
|
||||
};
|
||||
|
||||
const dismissSavePrompt = () => {
|
||||
setPendingQuizToSave(null);
|
||||
};
|
||||
|
||||
const startManualCreation = () => {
|
||||
setRole('HOST');
|
||||
setGameState('CREATING');
|
||||
};
|
||||
|
||||
const finalizeManualQuiz = (manualQuiz: Quiz) => {
|
||||
const finalizeManualQuiz = (manualQuiz: Quiz, saveToLibrary: boolean = false) => {
|
||||
if (saveToLibrary) {
|
||||
setPendingQuizToSave({ quiz: manualQuiz, topic: '' });
|
||||
}
|
||||
initializeHostGame(manualQuiz);
|
||||
};
|
||||
|
||||
|
|
@ -383,6 +392,7 @@ export const useGame = () => {
|
|||
|
||||
return {
|
||||
role, gameState, quiz, players, currentQuestionIndex, timeLeft, error, gamePin, hasAnswered, lastPointsEarned, currentCorrectShape, selectedOption, currentPlayerScore, currentStreak, currentPlayerId,
|
||||
pendingQuizToSave, dismissSavePrompt,
|
||||
startQuizGen, startManualCreation, finalizeManualQuiz, loadSavedQuiz, joinGame, startGame: startHostGame, handleAnswer, nextQuestion
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue