-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Review2024 components: remove Review2024LevelFive and Review…
…2024QuizQuestions, introduce Review2024QuizWrapper for improved quiz handling and styling
- Loading branch information
1 parent
e964ea6
commit 93a24b7
Showing
8 changed files
with
117 additions
and
156 deletions.
There are no files selected for viewing
62 changes: 0 additions & 62 deletions
62
frontend/components/review-2024/Review2024LevelFive/index.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 0 additions & 74 deletions
74
frontend/components/review-2024/Review2024QuizQuestions/index.tsx
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
frontend/components/review-2024/Review2024QuizQuestions/styles.module.css
This file was deleted.
Oops, something went wrong.
97 changes: 97 additions & 0 deletions
97
frontend/components/review-2024/Review2024QuizWrapper/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
'use client'; | ||
|
||
/* * */ | ||
|
||
import { Grid } from '@/components/layout/Grid'; | ||
import { Section } from '@/components/layout/Section'; | ||
import { Surface } from '@/components/layout/Surface'; | ||
import { allQuizData, type Review2024QuizAnswerSchema } from '@/components/review-2024/_data/quiz'; | ||
import { Review2024QuizPoints } from '@/components/review-2024/Review2024QuizPoints'; | ||
import { useTranslations } from 'next-intl'; | ||
import { useState } from 'react'; | ||
|
||
import { Review2024QuizFinalResult } from '../Review2024QuizFinalResult'; | ||
import { Review2024QuizQuestion } from '../Review2024QuizQuestion'; | ||
import styles from './styles.module.css'; | ||
|
||
/* * */ | ||
|
||
interface Props { | ||
points: number | ||
progress: number | ||
setPoints: (value: number) => void | ||
setProgress: (value: number) => void | ||
} | ||
|
||
/* * */ | ||
|
||
export function Review2024QuizWrapper({ points, progress, setPoints, setProgress }: Props) { | ||
// | ||
|
||
// | ||
// A. Setup variables | ||
|
||
const t = useTranslations('review-2024.Review2024QuizWrapper'); | ||
|
||
const [answerStatus, setAnswerStatus] = useState<'correct' | 'wrong' | null>(null); | ||
|
||
// | ||
// B. Handle actions | ||
|
||
const handleClickAnswerOption = (answerData: Review2024QuizAnswerSchema) => { | ||
if (answerStatus === null) { | ||
if (answerData.is_correct) { | ||
setAnswerStatus('correct'); | ||
setPoints(points + 542); | ||
} | ||
else { | ||
setAnswerStatus('wrong'); | ||
} | ||
} | ||
}; | ||
|
||
const handleAdvanceQuestion = () => { | ||
setAnswerStatus(null); | ||
setProgress(progress + 1); | ||
}; | ||
|
||
// | ||
// C. Render components | ||
|
||
if (progress >= allQuizData.length) { | ||
return ( | ||
<div className={styles.container}> | ||
<Review2024QuizFinalResult points={points} /> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<Surface forceOverflow> | ||
<Grid columns="ab"> | ||
|
||
<Section withPadding="desktop" withGap> | ||
<div className={styles.headingWrapper}> | ||
<h2 className={styles.heading}>{t('digital.heading')}</h2> | ||
<h5 className={styles.subheading}>{t('digital.subheading')}</h5> | ||
</div> | ||
<Review2024QuizPoints points={points} /> | ||
</Section> | ||
|
||
<Section withPadding="desktop" withGap> | ||
<div className={styles.container}> | ||
<Review2024QuizQuestion | ||
answerStatus={answerStatus} | ||
onAnswer={handleClickAnswerOption} | ||
onClickNext={handleAdvanceQuestion} | ||
quizData={allQuizData[progress]} | ||
/> | ||
</div> | ||
</Section> | ||
|
||
</Grid> | ||
</Surface> | ||
); | ||
|
||
// | ||
} |
16 changes: 16 additions & 0 deletions
16
...024/Review2024LevelFive/styles.module.css → ...4/Review2024QuizWrapper/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters