-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPracticeField.tsx
More file actions
68 lines (66 loc) · 1.96 KB
/
PracticeField.tsx
File metadata and controls
68 lines (66 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import React, { useState, useEffect } from "react";
import useTypedBrailleString from "@/hooks/useTypedBrailleString";
import translateBraille from "@/utils/translateBraille";
import { TextField, Typography, Box } from "@mui/material";
import { BrailleArray } from "@dot-tutor/braille";
import CommonButton from "./CommonButton";
export default function PracticeField({
question,
answer,
}: {
question: string;
answer: string;
}): JSX.Element {
const [typedBrailleString, updateTypedBrailleString] =
useTypedBrailleString(6);
const [answered, setAnswered] = useState<boolean>(false);
const [correctOrNot, setCorrectOrNot] = useState<boolean>(false);
const [translatedBrailleString, setTranslatedBrailleString] =
useState<string>("");
useEffect(() => {
setTranslatedBrailleString(
translateBraille(new BrailleArray(typedBrailleString, 6)),
);
}, [typedBrailleString]);
return (
<Box display="flex" alignItems="center">
<Box m={1}>
<Typography m={1}>{question}</Typography>
<TextField
variant="outlined"
value={typedBrailleString}
onKeyDown={(e) => {
updateTypedBrailleString(e);
}}
onKeyUp={(e) => {
updateTypedBrailleString(e);
}}
/>
<Typography style={{ color: "gray", fontSize: "75%" }} m={1}>
{translatedBrailleString}
</Typography>
</Box>
<Box m={1}>
<CommonButton
variant="outlined"
onClick={() => {
setCorrectOrNot(false);
if (typedBrailleString === answer) {
setCorrectOrNot(true);
}
setAnswered(true);
}}
>
答え合わせをする
</CommonButton>
</Box>
<Box m={1}>
{answered
? `${
correctOrNot ? "正解です!" : "不正解です..."
} 答えは${answer}です。`
: " "}
</Box>
</Box>
);
}