From 2175534e8fd75cf08cc1776bdc1d8e2260e18f05 Mon Sep 17 00:00:00 2001 From: swve Date: Wed, 26 Feb 2025 11:50:05 +0100 Subject: [PATCH] feat: Improve QuizBlockComponent UI and interaction with responsive design and enhanced user experience --- .../Extensions/Quiz/QuizBlockComponent.tsx | 96 ++++++++++++------- 1 file changed, 63 insertions(+), 33 deletions(-) diff --git a/apps/web/components/Objects/Editor/Extensions/Quiz/QuizBlockComponent.tsx b/apps/web/components/Objects/Editor/Extensions/Quiz/QuizBlockComponent.tsx index a9c44b2d..a7905ba4 100644 --- a/apps/web/components/Objects/Editor/Extensions/Quiz/QuizBlockComponent.tsx +++ b/apps/web/components/Objects/Editor/Extensions/Quiz/QuizBlockComponent.tsx @@ -50,6 +50,7 @@ function QuizBlockComponent(props: any) { const refreshUserSubmission = () => { setUserAnswers([]) setSubmitted(false) + setSubmissionMessage('') } const handleUserSubmission = () => { @@ -124,7 +125,7 @@ function QuizBlockComponent(props: any) { correct: false, } - // check if there is already more thqn 5 answers + // check if there is already more than 5 answers const question: any = questions.find( (question: Question) => question.question_id === question_id ) @@ -206,11 +207,11 @@ function QuizBlockComponent(props: any) { return (
-
- {submitted && submissionMessage == 'All answers are correct!' && ( + {/* Header section */} +
+ {submitted && submissionMessage === 'All answers are correct!' && (
-
+ + {/* Submission message */} + {submitted && ( +
+ {submissionMessage} +
+ )} + +
+ + {/* Action buttons */} {isEditable ? (
+ {/* Questions section */} {questions.map((question: Question) => ( -
+
@@ -269,10 +286,10 @@ function QuizBlockComponent(props: any) { e.target.value ) } - className="text-slate-800 bg-[#00008b00] border-2 border-gray-200 rounded-md border-dotted text-md font-bold w-full" + className="text-slate-800 bg-[#00008b00] border-2 border-gray-200 rounded-md border-dotted text-md font-bold w-full p-2" > ) : ( -

+

{question.question}

)} @@ -280,25 +297,27 @@ function QuizBlockComponent(props: any) { {isEditable && (
deleteQuestion(question.question_id)} - className="w-[20px] flex-none flex items-center h-[20px] rounded-lg bg-slate-200 hover:bg-slate-300 text-sm transition-all ease-linear cursor-pointer" + className="w-[24px] flex-none flex items-center h-[24px] rounded-lg bg-slate-200 hover:bg-slate-300 text-sm transition-all ease-linear cursor-pointer" > - +
)}
-
+ + {/* Answers section - changed to vertical layout for better responsiveness */} +
{question.answers.map((answer: Answer) => (
userAnswer.question_id === question.question_id && userAnswer.answer_id === answer.answer_id && - !isEditable - ) ? 'outline-slate-300' : '', + !isEditable && !submitted + ) ? 'outline-blue-400' : '', submitted && answer.correct ? 'outline-lime-300 text-lime' : '', submitted && !answer.correct && @@ -314,10 +333,16 @@ function QuizBlockComponent(props: any) { >
+ userAnswer.question_id === question.question_id && + userAnswer.answer_id === answer.answer_id && + !isEditable && !submitted + ) ? 'bg-blue-400 text-white outline-none' : '', submitted && answer.correct ? 'bg-lime-300 text-lime-800 outline-none' : '', @@ -332,7 +357,7 @@ function QuizBlockComponent(props: any) { : '' )} > -

+

{getAnswerID( question.answers.indexOf(answer), question.question_id @@ -350,33 +375,37 @@ function QuizBlockComponent(props: any) { ) } placeholder="Answer" - className="w-full mx-2 px-3 pr-6 text-neutral-600 bg-[#00008b00] border-2 border-gray-200 rounded-md border-dotted text-sm font-bold" + className="w-full mx-2 px-3 pr-6 text-neutral-600 bg-[#00008b00] border-2 border-gray-200 rounded-md border-dotted text-sm font-bold py-1.5" > ) : ( -

+

{answer.answer}

)} {isEditable && (
+ onClick={(e) => { + e.stopPropagation(); markAnswerCorrect( question.question_id, answer.answer_id - ) - } - className="w-[20px] flex-none flex items-center h-[20px] rounded-lg bg-lime-300 hover:bg-lime-400 transition-all ease-linear text-sm cursor-pointer " + ); + }} + className="w-[24px] flex-none flex items-center h-[24px] rounded-lg bg-lime-300 hover:bg-lime-400 transition-all ease-linear text-sm cursor-pointer" + title={answer.correct ? "Mark as incorrect" : "Mark as correct"} > - +
- deleteAnswer(question.question_id, answer.answer_id) - } - className="w-[20px] flex-none flex items-center h-[20px] rounded-lg bg-slate-200 hover:bg-slate-300 text-sm transition-all ease-linear cursor-pointer" + onClick={(e) => { + e.stopPropagation(); + deleteAnswer(question.question_id, answer.answer_id); + }} + className="w-[24px] flex-none flex items-center h-[24px] rounded-lg bg-slate-200 hover:bg-slate-300 text-sm transition-all ease-linear cursor-pointer" + title="Delete answer" > - +
)} @@ -385,9 +414,10 @@ function QuizBlockComponent(props: any) { {isEditable && (
addAnswer(question.question_id)} - className="outline outline-3 w-[30px] flex-none flex items-center h-[30px] outline-white hover:bg-opacity-100 hover:shadow-md rounded-lg bg-white text-sm hover:scale-105 active:scale-110 duration-150 cursor-pointer ease-linear" + className="outline outline-2 w-full flex-none flex items-center h-[36px] outline-white hover:bg-opacity-100 hover:shadow-md rounded-lg bg-white text-sm hover:scale-[1.01] active:scale-[1.02] duration-150 cursor-pointer ease-linear justify-center" > - + + Add Answer
)}