Add tests and edit works
This commit is contained in:
parent
bfbba7b5ab
commit
bc4b0e2df7
12 changed files with 2415 additions and 20 deletions
45
App.tsx
45
App.tsx
|
|
@ -1,4 +1,4 @@
|
|||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { useAuth } from 'react-oidc-context';
|
||||
import { useGame } from './hooks/useGame';
|
||||
import { useQuizLibrary } from './hooks/useQuizLibrary';
|
||||
|
|
@ -11,6 +11,7 @@ import { QuizCreator } from './components/QuizCreator';
|
|||
import { RevealScreen } from './components/RevealScreen';
|
||||
import { SaveQuizPrompt } from './components/SaveQuizPrompt';
|
||||
import { QuizEditor } from './components/QuizEditor';
|
||||
import { SaveOptionsModal } from './components/SaveOptionsModal';
|
||||
import type { Quiz } from './types';
|
||||
|
||||
const seededRandom = (seed: number) => {
|
||||
|
|
@ -40,7 +41,9 @@ const FloatingShapes = React.memo(() => {
|
|||
|
||||
function App() {
|
||||
const auth = useAuth();
|
||||
const { saveQuiz } = useQuizLibrary();
|
||||
const { saveQuiz, updateQuiz, saving } = useQuizLibrary();
|
||||
const [showSaveOptions, setShowSaveOptions] = useState(false);
|
||||
const [pendingEditedQuiz, setPendingEditedQuiz] = useState<Quiz | null>(null);
|
||||
const {
|
||||
role,
|
||||
gameState,
|
||||
|
|
@ -85,12 +88,33 @@ function App() {
|
|||
const handleEditorSave = async (editedQuiz: Quiz) => {
|
||||
updateQuizFromEditor(editedQuiz);
|
||||
if (auth.isAuthenticated) {
|
||||
const source = pendingQuizToSave?.topic ? 'ai_generated' : 'manual';
|
||||
const topic = pendingQuizToSave?.topic || undefined;
|
||||
await saveQuiz(editedQuiz, source, topic);
|
||||
if (sourceQuizId) {
|
||||
// Quiz was loaded from library - show options modal
|
||||
setPendingEditedQuiz(editedQuiz);
|
||||
setShowSaveOptions(true);
|
||||
} else {
|
||||
// New quiz (AI-generated or manual) - save as new
|
||||
const source = pendingQuizToSave?.topic ? 'ai_generated' : 'manual';
|
||||
const topic = pendingQuizToSave?.topic || undefined;
|
||||
await saveQuiz(editedQuiz, source, topic);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleOverwriteQuiz = async () => {
|
||||
if (!pendingEditedQuiz || !sourceQuizId) return;
|
||||
await updateQuiz(sourceQuizId, pendingEditedQuiz);
|
||||
setShowSaveOptions(false);
|
||||
setPendingEditedQuiz(null);
|
||||
};
|
||||
|
||||
const handleSaveAsNew = async () => {
|
||||
if (!pendingEditedQuiz) return;
|
||||
await saveQuiz(pendingEditedQuiz, 'manual');
|
||||
setShowSaveOptions(false);
|
||||
setPendingEditedQuiz(null);
|
||||
};
|
||||
|
||||
const currentQ = quiz?.questions[currentQuestionIndex];
|
||||
|
||||
// Logic to find correct option, handling both Host (has isCorrect flag) and Client (masked, needs shape)
|
||||
|
|
@ -204,6 +228,17 @@ function App() {
|
|||
/>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<SaveOptionsModal
|
||||
isOpen={showSaveOptions}
|
||||
onClose={() => {
|
||||
setShowSaveOptions(false);
|
||||
setPendingEditedQuiz(null);
|
||||
}}
|
||||
onOverwrite={handleOverwriteQuiz}
|
||||
onSaveNew={handleSaveAsNew}
|
||||
isSaving={saving}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue