Add ability to edit AI generated content

This commit is contained in:
Joey Yakimowich-Payne 2026-01-13 23:37:08 -07:00
commit bfbba7b5ab
No known key found for this signature in database
GPG key ID: 6BFE655FA5ABD1E1
15 changed files with 1089 additions and 10 deletions

View file

@ -24,6 +24,7 @@ export const useGame = () => {
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 [sourceQuizId, setSourceQuizId] = useState<string | null>(null);
const timerRef = useRef<ReturnType<typeof setInterval> | null>(null);
const peerRef = useRef<Peer | null>(null);
@ -85,7 +86,8 @@ export const useGame = () => {
const generatedQuiz = await generateQuiz(generateOptions);
const saveLabel = options.topic || options.files?.map(f => f.name).join(', ') || '';
setPendingQuizToSave({ quiz: generatedQuiz, topic: saveLabel });
initializeHostGame(generatedQuiz);
setQuiz(generatedQuiz);
setGameState('EDITING');
} catch (e) {
const message = e instanceof Error ? e.message : "Failed to generate quiz.";
setError(message);
@ -109,8 +111,28 @@ export const useGame = () => {
initializeHostGame(manualQuiz);
};
const loadSavedQuiz = (savedQuiz: Quiz) => {
initializeHostGame(savedQuiz);
const loadSavedQuiz = (savedQuiz: Quiz, quizId?: string) => {
setRole('HOST');
setQuiz(savedQuiz);
setSourceQuizId(quizId || null);
setGameState('EDITING');
};
const updateQuizFromEditor = (updatedQuiz: Quiz) => {
setQuiz(updatedQuiz);
setPendingQuizToSave(prev => prev ? { ...prev, quiz: updatedQuiz } : { quiz: updatedQuiz, topic: '' });
};
const startGameFromEditor = (finalQuiz: Quiz) => {
setQuiz(finalQuiz);
initializeHostGame(finalQuiz);
};
const backFromEditor = () => {
setQuiz(null);
setPendingQuizToSave(null);
setSourceQuizId(null);
setGameState('LANDING');
};
// We use a ref to hold the current handleHostData function
@ -441,7 +463,8 @@ 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, showScoreboard
pendingQuizToSave, dismissSavePrompt, sourceQuizId,
startQuizGen, startManualCreation, finalizeManualQuiz, loadSavedQuiz, joinGame, startGame: startHostGame, handleAnswer, nextQuestion, showScoreboard,
updateQuizFromEditor, startGameFromEditor, backFromEditor
};
};