@@ -4,13 +4,9 @@ import AnswerResultModal from '../AnswerResultModal';
44import ReactMarkdown from 'react-markdown' ;
55import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter' ;
66import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism' ;
7-
87import { preloadSounds } from '../../utils/preloadSounds' ;
9-
108import BackgroundMusic from '../BackgroundMusic' ;
119
12-
13-
1410interface Question {
1511 snippet ?: string ;
1612 question : string ;
@@ -19,7 +15,6 @@ interface Question {
1915}
2016
2117const Questions : React . FC = ( ) => {
22- const [ updateStats ] = useMutation ( UPDATE_STATS ) ;
2318 const { id } = useParams < { id : string } > ( ) ;
2419 const navigate = useNavigate ( ) ;
2520
@@ -30,8 +25,6 @@ const Questions: React.FC = () => {
3025 const [ audioUrl , setAudioUrl ] = useState ( '' ) ;
3126 const [ isReady , setIsReady ] = useState ( false ) ;
3227
33- const [ score , setScore ] = useState ( 0 ) ;
34-
3528 useEffect ( ( ) => {
3629 preloadSounds ( [
3730 '/audio/Dan_correct/Dan-correct-1.wav' ,
@@ -80,7 +73,7 @@ const Questions: React.FC = () => {
8073 if ( data . isFallback && data . question . correctIndex !== undefined ) {
8174 const fallback = data . question ;
8275 const labeledChoices = fallback . choices . map ( ( choice : string , index : number ) => {
83- const label = String . fromCharCode ( 65 + index ) ; // "A", "B", "C", ...
76+ const label = String . fromCharCode ( 65 + index ) ;
8477 return `${ label } ) ${ choice } ` ;
8578 } ) ;
8679 const correctLetter = String . fromCharCode ( 65 + fallback . correctIndex ) ;
@@ -136,16 +129,26 @@ const Questions: React.FC = () => {
136129 const correctChoice = question . choices [ correctIndex ] ?. slice ( 3 ) . trim ( ) ;
137130 const isCorrect = selectedAnswer === correctChoice ;
138131
139-
140132 setUserWasCorrect ( isCorrect ) ;
141133 setAudioUrl ( getRandomAudio ( isCorrect ) ) ;
142134 setShowResult ( true ) ;
135+
136+ const questionNumber = Number ( id ?. replace ( 'q' , '' ) ) ;
137+
138+ setTimeout ( ( ) => {
139+ if ( questionNumber === 5 ) {
140+ if ( isCorrect ) {
141+ navigate ( '/victory' ) ;
142+ } else {
143+ navigate ( '/gameover' ) ;
144+ }
145+ }
146+ } , 6000 ) ;
143147 } ;
144148
145149 const handleBack = ( ) => navigate ( '/map' ) ;
146150
147151 return (
148-
149152 < div
150153 className = "min-h-screen bg-cover bg-center bg-no-repeat"
151154 style = { { backgroundImage : 'url("/background/codezilla_bkgd.png")' } }
@@ -189,7 +192,6 @@ const Questions: React.FC = () => {
189192 </ pre >
190193 ) ;
191194 } ,
192-
193195 } }
194196 >
195197 { question . question }
@@ -198,7 +200,7 @@ const Questions: React.FC = () => {
198200
199201 < div className = "text-left flex flex-col items-start gap-2 text-white" >
200202 { question . choices . map ( ( choice , index ) => {
201- const value = choice . slice ( 3 ) . trim ( ) ; // remove "A) " etc.
203+ const value = choice . slice ( 3 ) . trim ( ) ;
202204 return (
203205 < label key = { index } className = "flex items-center gap-2 cursor-pointer" >
204206 < input
@@ -248,4 +250,4 @@ const Questions: React.FC = () => {
248250 ) ;
249251} ;
250252
251- export default Questions ;
253+ export default Questions ;
0 commit comments