1+ import { Replay } from "@mui/icons-material" ;
12import CloseIcon from "@mui/icons-material/Close" ;
23import {
34 Box ,
5+ Button ,
46 Dialog ,
57 IconButton ,
68 Stack ,
79 Typography ,
810 useTheme ,
911} from "@mui/material" ;
12+ import { useRef , useState } from "react" ;
1013import {
1114 Activity ,
1215 isMatchingActivity ,
@@ -16,9 +19,12 @@ import {
1619 isTextInputActivity ,
1720} from "../../../types/CourseTypes" ;
1821import MatchingViewer from "../../course_viewing/matching/MatchingViewer" ;
22+ import WrongAnswerModal from "../../course_viewing/modals/WrongAnswerModal" ;
1923import MultipleChoiceViewer from "../../course_viewing/multiple-choice/MultipleChoiceViewer" ;
2024import TableViewer from "../../course_viewing/table/TableViewer" ;
21- import TextInputViewer from "../../course_viewing/text-input/TextInputViewer" ;
25+ import TextInputViewer , {
26+ ActivityViewerHandle ,
27+ } from "../../course_viewing/text-input/TextInputViewer" ;
2228
2329const PreviewLearnerModal = ( {
2430 activity,
@@ -30,6 +36,9 @@ const PreviewLearnerModal = ({
3036 handleClose : ( ) => void ;
3137} ) => {
3238 const theme = useTheme ( ) ;
39+ const activityPreviewRef = useRef < ActivityViewerHandle > ( null ) ;
40+ const [ isCompleted , setIsCompleted ] = useState ( false ) ;
41+ const [ showWrongAnswerModal , setShowWrongAnswerModal ] = useState ( false ) ;
3342 return (
3443 < Dialog
3544 open = { open }
@@ -58,45 +67,86 @@ const PreviewLearnerModal = ({
5867 } }
5968 >
6069 < Typography variant = "labelMedium" > Preview (Learner View)</ Typography >
61- < IconButton onClick = { handleClose } >
62- < CloseIcon />
63- </ IconButton >
70+ < Stack direction = "row" alignItems = "center" gap = "8px" >
71+ < Button
72+ onClick = { ( ) => {
73+ if ( isCompleted ) {
74+ setIsCompleted ( false ) ;
75+ } else {
76+ activityPreviewRef . current ?. checkAnswer ( ) ;
77+ }
78+ } }
79+ sx = { {
80+ height : "48px" ,
81+ width : "fit-content" ,
82+ paddingX : "16px" ,
83+ paddingY : "10px" ,
84+ gap : "8px" ,
85+ border : "1px solid" ,
86+ borderColor : theme . palette . Neutral [ 500 ] ,
87+ borderRadius : "4px" ,
88+ backgroundColor : theme . palette . Learner . Dark . Default ,
89+ color : "white" ,
90+ } }
91+ >
92+ < Typography variant = "labelLarge" >
93+ { isCompleted ? (
94+ < >
95+ < Replay /> Reset
96+ </ >
97+ ) : (
98+ "Check Answer"
99+ ) }
100+ </ Typography >
101+ </ Button >
102+ < IconButton onClick = { handleClose } >
103+ < CloseIcon />
104+ </ IconButton >
105+ </ Stack >
64106 </ Stack >
65107 < Box sx = { { padding : "20px" } } >
66108 { ( isMultipleChoiceActivity ( activity ) ||
67109 isMultiSelectActivity ( activity ) ) && (
68110 < MultipleChoiceViewer
69111 activity = { activity }
70- onWrongAnswer = { ( ) => { } }
71- onCorrectAnswer = { ( ) => { } }
72- isCompleted = { false }
112+ onWrongAnswer = { ( ) => setShowWrongAnswerModal ( true ) }
113+ onCorrectAnswer = { ( ) => setIsCompleted ( true ) }
114+ isCompleted = { isCompleted }
115+ ref = { activityPreviewRef }
73116 />
74117 ) }
75118 { isTableActivity ( activity ) && (
76119 < TableViewer
77120 activity = { activity }
78- onWrongAnswer = { ( ) => { } }
79- onCorrectAnswer = { ( ) => { } }
80- isCompleted = { false }
121+ onWrongAnswer = { ( ) => setShowWrongAnswerModal ( true ) }
122+ onCorrectAnswer = { ( ) => setIsCompleted ( true ) }
123+ isCompleted = { isCompleted }
124+ ref = { activityPreviewRef }
81125 />
82126 ) }
83127 { isMatchingActivity ( activity ) && (
84128 < MatchingViewer
85129 activity = { activity }
86- onWrongAnswer = { ( ) => { } }
87- onCorrectAnswer = { ( ) => { } }
88- isCompleted = { false }
130+ onWrongAnswer = { ( ) => setShowWrongAnswerModal ( true ) }
131+ onCorrectAnswer = { ( ) => setIsCompleted ( true ) }
132+ isCompleted = { isCompleted }
133+ ref = { activityPreviewRef }
89134 />
90135 ) }
91136 { isTextInputActivity ( activity ) && (
92137 < TextInputViewer
93138 activity = { activity }
94- onWrongAnswer = { ( ) => { } }
95- onCorrectAnswer = { ( ) => { } }
96- isCompleted = { false }
139+ onWrongAnswer = { ( ) => setShowWrongAnswerModal ( true ) }
140+ onCorrectAnswer = { ( ) => setIsCompleted ( true ) }
141+ isCompleted = { isCompleted }
142+ ref = { activityPreviewRef }
97143 />
98144 ) }
99145 </ Box >
146+ < WrongAnswerModal
147+ open = { showWrongAnswerModal }
148+ onClose = { ( ) => setShowWrongAnswerModal ( false ) }
149+ />
100150 </ Dialog >
101151 ) ;
102152} ;
0 commit comments