1- import { Button , Card , Text , Tooltip } from '@blueprintjs/core'
1+ import { Button , Card , Intent , Text } from '@blueprintjs/core'
22import * as React from 'react'
33
4+ import { showSuccessMessage , showWarningMessage } from '../../utils/notification'
45import { IMCQQuestion } from '../assessment/assessmentShape'
56
67export interface IMCQChooserProps {
@@ -23,26 +24,19 @@ class MCQChooser extends React.PureComponent<IMCQChooserProps, State> {
2324 const options = this . props . mcq . choices . map ( ( choice , i ) => (
2425 < Button
2526 key = { i }
26- className = "mcq-option col-xs-6 "
27+ className = "mcq-option col-xs-12 "
2728 active = { i === this . state . mcqOption }
29+ intent = { this . getButtonIntent ( i , this . state . mcqOption , this . props . mcq . solution ) }
2830 onClick = { this . onButtonClickFactory ( i ) }
31+ minimal = { true }
2932 >
30- < Tooltip content = { choice . hint } >
31- < Text className = "Text" > { choice . content } </ Text >
32- </ Tooltip >
33+ < Text className = "Text" > { choice . content } </ Text >
3334 </ Button >
3435 ) )
3536 return (
36- < div className = "MCQChooser" >
37- < Card className = "mcq-content-parent row center-xs" >
38- < div className = "col-xs-12" >
39- < div className = "mcq-task-parent row center-xs " >
40- < Card className = "mcq-task col-xs-12" elevation = { 2 } >
41- < Text className = "Text" > { this . props . mcq . content } </ Text >
42- </ Card >
43- </ div >
44- < div className = "row mcq-options-parent center-xs" > { options } </ div >
45- </ div >
37+ < div className = "MCQChooser row" >
38+ < Card className = "mcq-content-parent col-xs-12 middle-xs" >
39+ < div className = "row mcq-options-parent between-xs" > { options } </ div >
4640 </ Card >
4741 </ div >
4842 )
@@ -53,16 +47,49 @@ class MCQChooser extends React.PureComponent<IMCQChooserProps, State> {
5347 * and mcq submission with a given answer id.
5448 *
5549 * Post-condition: the local state will be updated to store the
56- * mcq option selected.
50+ * mcq option selected, and a notification will be displayed with
51+ * a hint, if the question is ungraded.
5752 *
5853 * @param i the id of the answer
5954 */
6055 private onButtonClickFactory = ( i : number ) => ( e : any ) => {
6156 this . props . handleMCQSubmit ( i )
57+ if ( this . props . mcq . solution && i === this . props . mcq . solution ) {
58+ showSuccessMessage ( this . props . mcq . choices [ i ] . hint ! , 4000 )
59+ } else if ( this . props . mcq . solution && i !== this . props . mcq . solution ) {
60+ showWarningMessage ( this . props . mcq . choices [ i ] . hint ! , 4000 )
61+ }
6262 this . setState ( {
6363 mcqOption : i
6464 } )
6565 }
66+
67+ /**
68+ * Handles the logic for what intent an MCQ option should show up as.
69+ * This is dependent on the presence of an actual solution (for ungraded assessments),
70+ * the current selection, and whether the selected option is active.
71+ *
72+ * @param currentOption the current button key, corresponding to a choice ID
73+ * @param chosenOption the mcq option that is chosen in the state, i.e what should show up as "selected"
74+ * @param solution the solution to the mcq, if any
75+ */
76+ private getButtonIntent = (
77+ currentOption : number ,
78+ chosenOption : number | null ,
79+ solution : number | null
80+ ) : Intent => {
81+ const active = currentOption === chosenOption
82+ const correctOptionSelected = active && solution && currentOption === solution
83+ if ( ! solution ) {
84+ return Intent . NONE
85+ } else if ( active && correctOptionSelected ) {
86+ return Intent . SUCCESS
87+ } else if ( active && ! correctOptionSelected ) {
88+ return Intent . DANGER
89+ } else {
90+ return Intent . NONE
91+ }
92+ }
6693}
6794
6895export default MCQChooser
0 commit comments