From 90fba17a1ee3313eea12c4437737b08a2714184c Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Wed, 14 Jan 2026 00:16:23 -0700 Subject: [PATCH] Add shuffle options --- components/QuizEditor.tsx | 81 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 3 deletions(-) diff --git a/components/QuizEditor.tsx b/components/QuizEditor.tsx index a5507d0..09b2d28 100644 --- a/components/QuizEditor.tsx +++ b/components/QuizEditor.tsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; -import { ArrowLeft, Save, Plus, Play, AlertTriangle } from 'lucide-react'; +import { ArrowLeft, Save, Plus, Play, AlertTriangle, Shuffle } from 'lucide-react'; import { DndContext, closestCenter, KeyboardSensor, PointerSensor, useSensor, useSensors, DragEndEvent } from '@dnd-kit/core'; import { arrayMove, SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy } from '@dnd-kit/sortable'; import { Quiz, Question } from '../types'; @@ -31,6 +31,8 @@ export const QuizEditor: React.FC = ({ const [editingQuestion, setEditingQuestion] = useState(null); const [showDeleteConfirm, setShowDeleteConfirm] = useState(null); const [titleEditing, setTitleEditing] = useState(false); + const [shuffleQuestions, setShuffleQuestions] = useState(false); + const [shuffleAnswers, setShuffleAnswers] = useState(false); useBodyScrollLock(!!showDeleteConfirm); @@ -112,6 +114,33 @@ export const QuizEditor: React.FC = ({ q.options.some(o => o.isCorrect) ); + const handleStartGame = () => { + let questions = [...quiz.questions]; + + if (shuffleQuestions) { + questions = questions.sort(() => Math.random() - 0.5); + } + + if (shuffleAnswers) { + const shapes = ['triangle', 'diamond', 'circle', 'square'] as const; + const colors = ['red', 'blue', 'yellow', 'green'] as const; + + questions = questions.map(q => { + const shuffledOptions = [...q.options].sort(() => Math.random() - 0.5); + return { + ...q, + options: shuffledOptions.map((opt, idx) => ({ + ...opt, + shape: shapes[idx % 4], + color: colors[idx % 4] + })) + }; + }); + } + + onStartGame({ ...quiz, questions }); + }; + return (
@@ -212,9 +241,55 @@ export const QuizEditor: React.FC = ({ )}
-
+
+
+ + + +
+