1
- import React , { useState } from "react" ;
2
- import Messages from "../../utils/messages" ;
3
- import { sendToFrontendWrapped } from "../../commands/showPanel" ;
1
+ import React from "react" ;
2
+ import markdownToHtml from "../../utils/markdown" ;
4
3
5
4
export interface McqData {
6
5
assessmentName : string ;
@@ -11,60 +10,67 @@ export interface McqData {
11
10
12
11
interface McqPanelProps {
13
12
data : McqData ;
14
- onAnswer : ( choiceIndex : number ) => void ;
15
13
}
16
14
17
- const McqPanel : React . FC < McqPanelProps > = ( { data, onAnswer } ) => {
18
- const [ selected , setSelected ] = useState < number | null > ( null ) ;
15
+ const panelStyle : React . CSSProperties = {
16
+ padding : "2rem" ,
17
+ backgroundColor : "#1e293b" ,
18
+ borderRadius : "0.5rem" ,
19
+ height : "100vh" ,
20
+ width : "100vw" ,
21
+ boxSizing : "border-box" ,
22
+ display : "flex" ,
23
+ alignItems : "center" ,
24
+ justifyContent : "center" ,
25
+ } ;
19
26
20
- return (
21
- < div style = { { padding : "1rem" } } >
22
- < ul style = { { listStyle : "none" , paddingLeft : 0 } } >
23
- { data . choices . map ( ( c , idx ) => (
24
- < li key = { idx } style = { { marginBottom : "0.5rem" } } >
25
- < label style = { { cursor : "pointer" } } >
26
- < input
27
- type = "radio"
28
- name = "mcq-choice"
29
- value = { idx }
30
- data-choice = { idx }
31
- data-ws = { data . workspaceLocation ?? "assessment" }
32
- data-assessment = { data . assessmentName }
33
- data-qid = { data . questionId }
34
- checked = { selected === idx }
35
- onChange = { ( ) => {
36
- setSelected ( idx ) ;
37
- onAnswer ( idx ) ;
38
- } }
39
- style = { { marginRight : "0.5rem" } }
40
- />
41
- { c }
42
- </ label >
43
- </ li >
44
- ) ) }
45
- </ ul >
46
- </ div >
47
- ) ;
27
+ const listStyle : React . CSSProperties = {
28
+ listStyle : "none" ,
29
+ paddingLeft : 0 ,
30
+ width : "100%" ,
31
+ maxWidth : "600px" ,
32
+ display : "flex" ,
33
+ flexDirection : "column" ,
34
+ alignItems : "center" ,
35
+ gap : "2rem" ,
48
36
} ;
49
37
50
- export default McqPanel ;
38
+ const labelBaseStyle : React . CSSProperties = {
39
+ display : "block" ,
40
+ width : "100%" ,
41
+ padding : "1.25rem" ,
42
+ backgroundColor : "transparent" ,
43
+ borderRadius : "0.375rem" ,
44
+ cursor : "pointer" ,
45
+ color : "white" ,
46
+ fontSize : "1.25rem" ,
47
+ textAlign : "center" ,
48
+ transition : "background-color 0.3s ease" ,
49
+ border : "1px solid transparent" ,
50
+ } ;
51
51
52
- export const McqPanelWithLogging : React . FC < { data : McqData } > = ( { data } ) => (
53
- < McqPanel
54
- data = { data }
55
- onAnswer = { ( choiceIndex ) => {
56
- const wsLoc = data . workspaceLocation ?? "assessment" ;
57
- console . log (
58
- `MCQ Answer: ${ data . assessmentName } , Question ID: ${ data . questionId } , Choice Index: ${ choiceIndex } ` ,
59
- ) ;
60
- sendToFrontendWrapped (
61
- Messages . McqAnswer (
62
- wsLoc ,
63
- data . assessmentName ,
64
- data . questionId ,
65
- choiceIndex ,
66
- ) ,
67
- ) ;
68
- } }
69
- />
52
+ const McqPanel : React . FC < McqPanelProps > = ( { data } ) => (
53
+ < div style = { panelStyle } >
54
+ < ul style = { listStyle } >
55
+ { data . choices . map ( ( c , idx ) => (
56
+ < li key = { idx } style = { { width : "100%" } } >
57
+ < label style = { labelBaseStyle } >
58
+ < input
59
+ type = "radio"
60
+ name = "mcq-choice"
61
+ value = { idx }
62
+ data-choice = { idx }
63
+ data-ws = { data . workspaceLocation ?? "assessment" }
64
+ data-assessment = { data . assessmentName }
65
+ data-qid = { data . questionId }
66
+ style = { { display : "none" } }
67
+ />
68
+ < span dangerouslySetInnerHTML = { { __html : markdownToHtml ( c ) } } />
69
+ </ label >
70
+ </ li >
71
+ ) ) }
72
+ </ ul >
73
+ </ div >
70
74
) ;
75
+
76
+ export default McqPanel ;
0 commit comments