Phase 5 complete

This commit is contained in:
Joey Yakimowich-Payne 2026-01-13 16:38:25 -07:00
commit 93ea01525e
No known key found for this signature in database
GPG key ID: 6BFE655FA5ABD1E1
7 changed files with 433 additions and 37 deletions

View file

@ -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
};
};