@@ -10,7 +10,10 @@ import {
1010 CircularProgress ,
1111 Box ,
1212 LinearProgress ,
13+ Grid2 as Grid ,
14+ Alert ,
1315} from '@mui/material' ;
16+ import MainLayout from './QuizLayout' ;
1417
1518function QuizPage ( ) {
1619 const { state } = useLocation ( ) ;
@@ -124,9 +127,7 @@ function QuizPage() {
124127 const handleOptionChange = ( e ) => {
125128 const selectedOption = e . target . value ;
126129 const timeTaken =
127- quizData && quizData . EnableTimer
128- ? quizData . TimerSeconds - timeLeft
129- : 0 ;
130+ quizData && quizData . EnableTimer ? quizData . TimerSeconds - timeLeft : 0 ;
130131
131132 setAnswers ( ( prevAnswers ) => ( {
132133 ...prevAnswers ,
@@ -163,79 +164,125 @@ function QuizPage() {
163164 const isTimeUp = quizData . EnableTimer && timeLeft <= 0 ;
164165
165166 return (
166- < Container maxWidth = "md" >
167- < Typography variant = "h4" gutterBottom >
168- { quizData . Title }
169- </ Typography >
170- < Typography variant = "subtitle1" gutterBottom >
171- Question { currentQuestionIndex + 1 } of { quizData . Questions . length }
172- </ Typography >
173-
174- { quizData . EnableTimer && (
175- < Box sx = { { width : '100%' , marginBottom : 2 } } >
176- < LinearProgress
177- variant = "determinate"
178- value = { ( timeLeft / quizData . TimerSeconds ) * 100 }
179- sx = { { height : 10 , borderRadius : 5 } }
180- />
181- < Typography variant = "body2" color = "textSecondary" >
182- Time Left: { timeLeft } seconds
167+ < MainLayout >
168+ < Container maxWidth = "sm" className = "main-quiz-container" >
169+ < Typography variant = "h6" gutterBottom align = "left" width = { '100%' } >
170+ Question { currentQuestionIndex + 1 } / { quizData . Questions . length }
171+ </ Typography >
172+
173+ < Container maxWidth = { '100%' } className = "question-container" >
174+ < Typography variant = "h4" gutterBottom color = "#EAEAF0" align = "center" >
175+ { currentQuestion . QuestionText }
183176 </ Typography >
184- </ Box >
185- ) }
177+ </ Container >
186178
187- < Typography variant = "h6" gutterBottom >
188- { currentQuestion . QuestionText }
189- </ Typography >
190- < RadioGroup
191- name = { `question-${ currentQuestionIndex } ` }
192- value = { answers [ currentQuestionIndex ] ?. Answer || '' }
193- onChange = { handleOptionChange }
194- >
195- { currentQuestion . Options . map ( ( option , idx ) => (
196- < FormControlLabel
197- key = { idx }
198- value = { option }
199- control = { < Radio /> }
200- label = { option }
201- disabled = { isSubmitting || isTimeUp }
202- />
203- ) ) }
204- </ RadioGroup >
179+ { quizData . EnableTimer && (
180+ < Box sx = { { width : '100%' , textAlign : 'center' } } >
181+ < Grid container spacing = { 2 } >
182+ < Typography variant = "body2" color = "textSecondary" width = { '8%' } >
183+ Time:
184+ </ Typography >
185+ < LinearProgress
186+ variant = "determinate"
187+ color = "primary"
188+ value = { ( timeLeft / quizData . TimerSeconds ) * 100 }
189+ sx = { {
190+ height : 5 ,
191+ borderRadius : 5 ,
192+ width : '78%' ,
193+ marginTop : '8px' ,
194+ } }
195+ />
196+ < Typography variant = "body2" color = "textSecondary" width = { '8%' } >
197+ { timeLeft }
198+ </ Typography >
199+ </ Grid >
200+ </ Box >
201+ ) }
202+ < RadioGroup
203+ name = { `question-${ currentQuestionIndex } ` }
204+ value = { answers [ currentQuestionIndex ] ?. Answer || '' }
205+ onChange = { handleOptionChange }
206+ sx = { { width : '100%' } }
207+ >
208+ { currentQuestion . Options . map ( ( option , idx ) => (
209+ < FormControlLabel
210+ key = { idx }
211+ value = { option }
212+ control = { < Radio /> }
213+ label = { option }
214+ disabled = { isSubmitting || isTimeUp }
215+ sx = { {
216+ borderRadius : '4px' ,
217+ border : '1px solid #D9DADF' ,
218+ background : '#EAEAF0' ,
219+ width : '100%' ,
220+ margin : '4px' ,
221+ textAlign : 'left' ,
222+ } }
223+ />
224+ ) ) }
225+ </ RadioGroup >
205226
206- { currentQuestion . Trivia && (
207- < Typography variant = "body2" color = "textSecondary" sx = { { marginTop : 2 } } >
208- Trivia: { currentQuestion . Trivia }
209- </ Typography >
210- ) }
227+ { isSubmitting && (
228+ < Box sx = { { textAlign : 'center' , marginTop : 4 } } >
229+ < CircularProgress />
230+ < Typography variant = "h6" sx = { { marginTop : 2 } } >
231+ Submitting your answers...
232+ </ Typography >
233+ </ Box >
234+ ) }
211235
212- { isSubmitting && (
213- < Box sx = { { textAlign : 'center' , marginTop : 4 } } >
214- < CircularProgress />
215- < Typography variant = "h6" sx = { { marginTop : 2 } } >
216- Submitting your answers...
236+ { ! isSubmitting &&
237+ quizData &&
238+ currentQuestionIndex === quizData . Questions . length - 1 && (
239+ < Button
240+ variant = "contained"
241+ color = "primary"
242+ onClick = { handleSubmit }
243+ disabled = {
244+ Object . keys ( answers ) . length !== quizData . Questions . length ||
245+ isSubmitting ||
246+ isTimeUp
247+ }
248+ sx = { { marginTop : 4 } }
249+ >
250+ Submit Quiz
251+ </ Button >
252+ ) }
253+ </ Container >
254+ { currentQuestion . Trivia && (
255+ < Alert
256+ severity = "info"
257+ sx = { {
258+ marginTop : 4 ,
259+ textAlign : 'center' ,
260+ backgroundColor : '#E6EAFF' ,
261+ width : 320 ,
262+ marginLeft : 'auto' ,
263+ marginRight : 'auto' ,
264+ borderRadius : '4px' ,
265+ } }
266+ >
267+ < Typography
268+ variant = "h5"
269+ color = "textSecondary"
270+ align = "left"
271+ sx = { { marginTop : 2 } }
272+ >
273+ Hint
217274 </ Typography >
218- </ Box >
219- ) }
220-
221- { ! isSubmitting &&
222- quizData &&
223- currentQuestionIndex === quizData . Questions . length - 1 && (
224- < Button
225- variant = "contained"
226- color = "primary"
227- onClick = { handleSubmit }
228- disabled = {
229- Object . keys ( answers ) . length !== quizData . Questions . length ||
230- isSubmitting ||
231- isTimeUp
232- }
233- sx = { { marginTop : 4 } }
275+ < Typography
276+ variant = "body2"
277+ align = "left"
278+ color = "textSecondary"
279+ sx = { { marginTop : 2 } }
234280 >
235- Submit Quiz
236- </ Button >
237- ) }
238- </ Container >
281+ { currentQuestion . Trivia }
282+ </ Typography >
283+ </ Alert >
284+ ) }
285+ </ MainLayout >
239286 ) ;
240287}
241288
0 commit comments