Created the first exercise of the listening demo
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
import {errorButtonStyle, infoButtonStyle} from "@/constants/buttonStyles";
|
||||
import {MatchSentencesExercise} from "@/interfaces/exam";
|
||||
import {mdiArrowLeft, mdiArrowRight} from "@mdi/js";
|
||||
import Icon from "@mdi/react";
|
||||
import clsx from "clsx";
|
||||
import {useState} from "react";
|
||||
import LineTo from "react-lineto";
|
||||
import {CommonProps} from ".";
|
||||
|
||||
const AVAILABLE_COLORS = ["#63526a", "#f7651d", "#278f04", "#ef4487", "#ca68c0", "#f5fe9b", "#b3ab01", "#af963a", "#9a85f1", "#1b1750"];
|
||||
|
||||
export default function MatchSentences({allowRepetition, options, prompt, sentences}: MatchSentencesExercise) {
|
||||
export default function MatchSentences({allowRepetition, options, prompt, sentences, onNext, onBack}: MatchSentencesExercise & CommonProps) {
|
||||
const [selectedQuestion, setSelectedQuestion] = useState<string>();
|
||||
const [userSolutions, setUserSolutions] = useState<{question: string; option: string}[]>([]);
|
||||
|
||||
@@ -20,60 +24,77 @@ export default function MatchSentences({allowRepetition, options, prompt, senten
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-8">
|
||||
<span className="text-lg font-medium text-center px-48">{prompt}</span>
|
||||
<div className="grid grid-cols-2 gap-16 place-items-center">
|
||||
<div className="flex flex-col gap-1">
|
||||
{sentences.map(({sentence, id, color}) => (
|
||||
<div
|
||||
key={`question_${id}`}
|
||||
className="flex items-center justify-end gap-2 cursor-pointer"
|
||||
onClick={() => setSelectedQuestion((prev) => (prev === id ? undefined : id))}>
|
||||
<span>
|
||||
<span className="font-semibold">{id}.</span> {sentence}{" "}
|
||||
</span>
|
||||
<>
|
||||
<div className="flex flex-col items-center gap-8">
|
||||
<span className="text-lg font-medium text-center px-48">{prompt}</span>
|
||||
<div className="grid grid-cols-2 gap-16 place-items-center">
|
||||
<div className="flex flex-col gap-1">
|
||||
{sentences.map(({sentence, id, color}) => (
|
||||
<div
|
||||
style={{borderColor: color, backgroundColor: selectedQuestion === id ? color : "transparent"}}
|
||||
className={clsx("border-2 border-blue-500 w-4 h-4 rounded-full", id)}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
{options.map(({sentence, id}) => (
|
||||
<div
|
||||
key={`answer_${id}`}
|
||||
className={clsx("flex items-center justify-start gap-2 cursor-pointer")}
|
||||
onClick={() => selectOption(id)}>
|
||||
<div
|
||||
style={
|
||||
userSolutions.find((x) => x.option === id)
|
||||
? {
|
||||
border: `2px solid ${getSentenceColor(userSolutions.find((x) => x.option === id)!.question)}`,
|
||||
}
|
||||
: {}
|
||||
}
|
||||
className={clsx("border-2 border-green-500 bg-transparent w-4 h-4 rounded-full", id)}
|
||||
/>
|
||||
<span>
|
||||
<span className="font-semibold">{id}.</span> {sentence}{" "}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{userSolutions.map((solution, index) => (
|
||||
<div key={`solution_${index}`} className="absolute">
|
||||
<LineTo
|
||||
className="rounded-full"
|
||||
from={solution.question}
|
||||
to={solution.option}
|
||||
borderColor={sentences.find((x) => x.id === solution.question)!.color}
|
||||
borderWidth={5}
|
||||
/>
|
||||
key={`question_${id}`}
|
||||
className="flex items-center justify-end gap-2 cursor-pointer"
|
||||
onClick={() => setSelectedQuestion((prev) => (prev === id ? undefined : id))}>
|
||||
<span>
|
||||
<span className="font-semibold">{id}.</span> {sentence}{" "}
|
||||
</span>
|
||||
<div
|
||||
style={{borderColor: color, backgroundColor: selectedQuestion === id ? color : "transparent"}}
|
||||
className={clsx("border-2 border-blue-500 w-4 h-4 rounded-full", id)}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
<div className="flex flex-col gap-1">
|
||||
{options.map(({sentence, id}) => (
|
||||
<div
|
||||
key={`answer_${id}`}
|
||||
className={clsx("flex items-center justify-start gap-2 cursor-pointer")}
|
||||
onClick={() => selectOption(id)}>
|
||||
<div
|
||||
style={
|
||||
userSolutions.find((x) => x.option === id)
|
||||
? {
|
||||
border: `2px solid ${getSentenceColor(userSolutions.find((x) => x.option === id)!.question)}`,
|
||||
}
|
||||
: {}
|
||||
}
|
||||
className={clsx("border-2 border-green-500 bg-transparent w-4 h-4 rounded-full", id)}
|
||||
/>
|
||||
<span>
|
||||
<span className="font-semibold">{id}.</span> {sentence}{" "}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{userSolutions.map((solution, index) => (
|
||||
<div key={`solution_${index}`} className="absolute">
|
||||
<LineTo
|
||||
className="rounded-full"
|
||||
from={solution.question}
|
||||
to={solution.option}
|
||||
borderColor={sentences.find((x) => x.id === solution.question)!.color}
|
||||
borderWidth={5}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="self-end flex gap-8">
|
||||
<button className={clsx("btn btn-wide gap-4 relative text-white", errorButtonStyle)} onClick={onBack}>
|
||||
<div className="absolute left-4">
|
||||
<Icon path={mdiArrowLeft} color="white" size={1} />
|
||||
</div>
|
||||
Back
|
||||
</button>
|
||||
<button className={clsx("btn btn-wide gap-4 relative text-white", infoButtonStyle)} onClick={onNext}>
|
||||
Next
|
||||
<div className="absolute right-4">
|
||||
<Icon path={mdiArrowRight} color="white" size={1} />
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user