@@ -3,7 +3,8 @@ import { useParams, useNavigate } from 'react-router-dom';
33import AnswerResultModal from '../AnswerResultModal' ;
44import ReactMarkdown from 'react-markdown' ;
55import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter' ;
6- import vscDarkPlus from "react-syntax-highlighter/dist/esm/styles/prism/vsc-dark-plus" ;
6+ import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism' ;
7+ import { preloadSounds } from '../../utils/preloadSounds' ;
78
89interface Question {
910 snippet ?: string ;
@@ -22,20 +23,25 @@ const Questions: React.FC = () => {
2223 const [ userWasCorrect , setUserWasCorrect ] = useState ( false ) ;
2324 const [ audioUrl , setAudioUrl ] = useState ( '' ) ;
2425
26+ useEffect ( ( ) => {
27+ preloadSounds ( [
28+ '/audio/Dan_correct/Dan-correct-1.wav' ,
29+ '/audio/Dan_correct/Dan-correct-2.wav' ,
30+ '/audio/Dan_correct/Dan-correct-3.wav' ,
31+ '/audio/Dan_correct/correctStar.wav' ,
32+ '/audio/Dan_incorrect/Dan-incorrect-1.wav' ,
33+ '/audio/Dan_incorrect/Dan-incorrect-2.wav' ,
34+ '/audio/Dan_incorrect/Dan-incorrect-3.wav' ,
35+ '/audio/Dan_incorrect/Dan-incorrect-4.wav' ,
36+ '/audio/Dan_incorrect/firstincorrect.wav'
37+ ] ) ;
38+ } , [ ] ) ;
39+
2540 const minionMap : Record < string , string > = {
26- q1 : 'NullByte' ,
27- q2 : 'Dbug' ,
28- q3 : 'Typerrorasaurus' ,
29- q4 : 'PieThon' ,
30- q5 : 'Codezilla' ,
41+ q1 : 'NullByte' , q2 : 'Dbug' , q3 : 'Typerrorasaurus' , q4 : 'PieThon' , q5 : 'Codezilla' ,
3142 } ;
32-
3343 const difficultyMap : Record < string , string > = {
34- NullByte : 'easy' ,
35- Dbug : 'medium' ,
36- Typerrorasaurus : 'medium-hard' ,
37- PieThon : 'hard' ,
38- Codezilla : 'boss' ,
44+ NullByte : 'easy' , Dbug : 'medium' , Typerrorasaurus : 'medium-hard' , PieThon : 'hard' , Codezilla : 'boss' ,
3945 } ;
4046
4147 useEffect ( ( ) => {
@@ -67,15 +73,11 @@ const Questions: React.FC = () => {
6773 value : choice . replace ( / ^ [ A - D a - d ] \) \s * / , '' ) ,
6874 } ) ) ;
6975
70- const correctFromLetter =
71- raw . answer ?. length === 1
72- ? raw . choices [ raw . answer . charCodeAt ( 0 ) - 65 ] ?. replace ( / ^ [ A - D a - d ] \) \s * / , '' )
73- : raw . answer ;
76+ const correctFromLetter = raw . answer ?. length === 1
77+ ? raw . choices [ raw . answer . charCodeAt ( 0 ) - 65 ] ?. replace ( / ^ [ A - D a - d ] \) \s * / , '' )
78+ : raw . answer ;
7479
75- const correctFromIndex =
76- typeof raw . correctIndex === 'number'
77- ? raw . choices [ raw . correctIndex ]
78- : null ;
80+ const correctFromIndex = typeof raw . correctIndex === 'number' ? raw . choices [ raw . correctIndex ] : null ;
7981
8082 setQuestion ( {
8183 snippet : raw . snippet ,
@@ -89,24 +91,22 @@ const Questions: React.FC = () => {
8991 } ;
9092
9193 fetchQuestion ( ) ;
92- return ( ) => {
93- didCancel = true ;
94- } ;
94+ return ( ) => { didCancel = true ; } ;
9595 } , [ id ] ) ;
9696
9797 const getRandomAudio = ( isCorrect : boolean ) : string => {
9898 const correctClips = [
9999 '/audio/Dan_correct/Dan-correct-1.wav' ,
100100 '/audio/Dan_correct/Dan-correct-2.wav' ,
101101 '/audio/Dan_correct/Dan-correct-3.wav' ,
102- '/audio/Dan_correct/correctStar .wav' ,
102+ '/audio/Dan_correct/Dan-correct-4 .wav'
103103 ] ;
104104 const incorrectClips = [
105105 '/audio/Dan_incorrect/Dan-incorrect-1.wav' ,
106106 '/audio/Dan_incorrect/Dan-incorrect-2.wav' ,
107107 '/audio/Dan_incorrect/Dan-incorrect-3.wav' ,
108108 '/audio/Dan_incorrect/Dan-incorrect-4.wav' ,
109- '/audio/Dan_incorrect/firstincorrect .wav' ,
109+ '/audio/Dan_incorrect/Dan-incorrect-5 .wav'
110110 ] ;
111111 const pool = isCorrect ? correctClips : incorrectClips ;
112112 return pool [ Math . floor ( Math . random ( ) * pool . length ) ] ;
@@ -125,48 +125,46 @@ const Questions: React.FC = () => {
125125 const handleBack = ( ) => navigate ( '/map' ) ;
126126
127127 return (
128- < div className = "question-screen max-h-screen overflow-y-auto p-6 max-w-xl mx-auto text-center" >
129- < h1 className = "text-xl font-semibold mb-2" >
130- Question { id ?. replace ( 'q' , '' ) || '' }
131- </ h1 >
128+ < div className = "relative question-screen max-h-screen overflow-y-auto p-6 max-w-xl mx-auto text-center" >
129+ < h1 className = "text-xl font-semibold mb-2" > Question { id ?. replace ( 'q' , '' ) || '' } </ h1 >
132130
133131 { ! question ? (
134132 < p > Loading question...</ p >
135133 ) : (
136134 < >
137135 < div className = "mb-4 text-white text-base text-left whitespace-pre-wrap" >
138- { question . snippet ?. trim ( ) ? (
136+ { question . snippet ?. trim ( ) && (
139137 < SyntaxHighlighter
140138 language = "javascript"
141139 style = { vscDarkPlus }
142140 showLineNumbers
143141 customStyle = { {
144- border : '2px solid red' ,
145- borderRadius : '0.5rem' ,
146- marginBottom : '1rem' ,
147- maxHeight : '220px' ,
148- overflowY : 'auto' ,
149- paddingRight : '1rem' ,
150- fontSize : '0.75rem' ,
142+ border : '2px solid red' , borderRadius : '0.5rem' ,
143+ marginBottom : '1rem' , maxHeight : '220px' ,
144+ overflowY : 'auto' , paddingRight : '1rem' , fontSize : '0.75rem'
151145 } }
152146 >
153147 { question . snippet }
154148 </ SyntaxHighlighter >
155- ) : null }
149+ ) }
156150
157151 < ReactMarkdown
158152 components = { {
159- code ( { inline, children, ...props } : { inline ?: boolean ; children ?: React . ReactNode } ) {
153+ code ( { inline, className , children, ...props } : { inline ?: boolean ; className ?: string ; children ?: React . ReactNode } ) {
160154 return inline ? (
161- < code className = "bg-gray-700 px-1 rounded text-sm" { ...props } >
162- { children }
163- </ code >
155+ < code className = "bg-gray-700 px-1 rounded text-sm" { ...props } > { children } </ code >
164156 ) : (
165- < pre className = " bg-gray-800 p-4 rounded-md text-sm font-mono shadow-lg mb-4" >
157+ < pre className = { ` bg-gray-800 p-4 rounded-md text-sm font-mono shadow-lg ${ className ?? '' } ` } >
166158 < code { ...props } > { children } </ code >
167159 </ pre >
168160 ) ;
169161 } ,
162+ p ( { node, children, ...props } ) {
163+ if ( Array . isArray ( children ) && children . length === 1 && typeof children [ 0 ] === 'object' && ( children [ 0 ] as any ) . type === 'pre' ) {
164+ return < > { children } </ > ;
165+ }
166+ return < p { ...props } > { children } </ p > ;
167+ } ,
170168 } }
171169 >
172170 { question . question }
@@ -209,9 +207,6 @@ const Questions: React.FC = () => {
209207 isOpen = { showResult }
210208 onClose = { ( ) => setShowResult ( false ) }
211209 isCorrect = { userWasCorrect }
212- drDanQuote = {
213- userWasCorrect ? "You're getting it, junior dev!" : "Nope — that ain't it!"
214- }
215210 audioUrl = { audioUrl }
216211 />
217212 </ div >
0 commit comments