|
@@ -3,6 +3,7 @@ import { useEffect, useRef, useState } from 'react'; |
|
|
import { Link } from 'react-router-dom'; |
|
|
import { Link } from 'react-router-dom'; |
|
|
import styles from './Options.module.scss'; |
|
|
import styles from './Options.module.scss'; |
|
|
import { OptionType } from '../../models/QuizDetails' |
|
|
import { OptionType } from '../../models/QuizDetails' |
|
|
|
|
|
import RadioButton from '../../components/RadioButton/RadioButton'; |
|
|
|
|
|
|
|
|
interface OwnProps { |
|
|
interface OwnProps { |
|
|
options: string[] | undefined; |
|
|
options: string[] | undefined; |
|
@@ -22,10 +23,11 @@ const Options: React.FC<OwnProps> = (props) => { |
|
|
const inputRef = useRef<HTMLTextAreaElement>(null); |
|
|
const inputRef = useRef<HTMLTextAreaElement>(null); |
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
setSelected(undefined); |
|
|
|
|
|
|
|
|
setSelected(""); |
|
|
setSelectedOptions([]); |
|
|
setSelectedOptions([]); |
|
|
setTextInput(""); |
|
|
setTextInput(""); |
|
|
}, [props.options]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, [props.questionNumber]); |
|
|
|
|
|
|
|
|
const selectChecked = (option: string) => { |
|
|
const selectChecked = (option: string) => { |
|
|
let newOption: string[] = []; |
|
|
let newOption: string[] = []; |
|
@@ -43,7 +45,8 @@ const Options: React.FC<OwnProps> = (props) => { |
|
|
setAnswers(answers + 1); |
|
|
setAnswers(answers + 1); |
|
|
} |
|
|
} |
|
|
} else if (props.type === "multiSelect") { |
|
|
} else if (props.type === "multiSelect") { |
|
|
if (props.answer.length === selectedOptions.length && props.answer.sort().join(',') === selectedOptions.sort().join(',')) { |
|
|
|
|
|
|
|
|
if (props.answer.length === selectedOptions.length && |
|
|
|
|
|
props.answer.sort().join(',') === selectedOptions.sort().join(',')) { |
|
|
|
|
|
|
|
|
setAnswers(answers + 1); |
|
|
setAnswers(answers + 1); |
|
|
} |
|
|
} |
|
@@ -55,21 +58,22 @@ const Options: React.FC<OwnProps> = (props) => { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const handleInput = () => { |
|
|
const handleInput = () => { |
|
|
setTextInput(inputRef.current?.value!) |
|
|
|
|
|
|
|
|
setTextInput(inputRef.current?.value!); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const setAnswer = () => { |
|
|
const setAnswer = () => { |
|
|
localStorage.setItem("answer", answers.toString()); |
|
|
localStorage.setItem("answer", answers.toString()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const getAnswer = () => { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const options = props.options!.map((option, key) => { |
|
|
const options = props.options!.map((option, key) => { |
|
|
return ( |
|
|
return ( |
|
|
<IonItem lines='none' key={key} className={(option === selected) ? styles.highlighted : ""}> |
|
|
|
|
|
<IonLabel>{option}</IonLabel> |
|
|
|
|
|
<IonRadio mode='md' slot="start" value={option} /> |
|
|
|
|
|
</IonItem> |
|
|
|
|
|
|
|
|
<div key={key} onClick={() => setSelected(option)}> |
|
|
|
|
|
<RadioButton option={option} isChecked={selected === option} /> |
|
|
|
|
|
</div> |
|
|
); |
|
|
); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@@ -92,9 +96,9 @@ const Options: React.FC<OwnProps> = (props) => { |
|
|
<div className={styles.optionHolder}> |
|
|
<div className={styles.optionHolder}> |
|
|
<IonList> |
|
|
<IonList> |
|
|
{props.type === "singleSelect" && |
|
|
{props.type === "singleSelect" && |
|
|
<IonRadioGroup onIonChange={e => setSelected(e.detail.value)} allowEmptySelection={true} className={styles.options}> |
|
|
|
|
|
|
|
|
<div className={styles.options}> |
|
|
{options} |
|
|
{options} |
|
|
</IonRadioGroup> |
|
|
|
|
|
|
|
|
</div> |
|
|
} |
|
|
} |
|
|
{props.type === "multiSelect" && |
|
|
{props.type === "multiSelect" && |
|
|
<div className={styles.options}> |
|
|
<div className={styles.options}> |
|
|