|
1 |
| -import { GeoEAGTask, GeoETATask } from "@/types/JGeoGLUE"; |
| 1 | +import { JGeoGLUETask } from "@prisma/client"; |
2 | 2 | import { useState } from "react";
|
3 | 3 |
|
4 |
| -const GeoEAGOptions = ["✅ 全く同じ", "🟡 部分的に一致", "❌️ 全く違う"]; |
| 4 | +const GeoEAGOptions = [ |
| 5 | + { label: "✅ 全く同じ", value: "全く同じ" }, |
| 6 | + { label: "🟡 部分的に一致", value: "部分的に一致" }, |
| 7 | + { label: "❌️ 全く違う", value: "全く違う" }, |
| 8 | +]; |
5 | 9 |
|
6 | 10 | const GeoETAOptions = [
|
7 |
| - "🏞️ 都道府県", |
8 |
| - "🏙️ 市区町村", |
9 |
| - "🏘️ 町名", |
10 |
| - "🏠 番地", |
11 |
| - "🏢 施設名", |
12 |
| - "🏗️ その他", |
| 11 | + { label: "🏞️ 都道府県", value: "都道府県" }, |
| 12 | + { label: "🏙️ 市区町村", value: "市区町村" }, |
| 13 | + { label: "🏘️ 町名", value: "町名" }, |
| 14 | + { label: "🏠 番地", value: "番地" }, |
| 15 | + { label: "🏢 施設名", value: "施設名" }, |
| 16 | + { label: "🏗️ その他", value: "その他" }, |
13 | 17 | ];
|
14 | 18 |
|
15 | 19 | export const GeoGLUETaskCard: React.FC<{
|
16 |
| - task: GeoEAGTask | GeoETATask; |
| 20 | + task: JGeoGLUETask; |
17 | 21 | onNext: () => void;
|
18 | 22 | }> = ({ task, onNext }) => {
|
19 | 23 | const [answerIsCorrect, setAnswerIsCorrect] = useState<boolean | null>(null);
|
20 | 24 |
|
21 | 25 | const options = task.type === "GeoEAG" ? GeoEAGOptions : GeoETAOptions;
|
22 | 26 |
|
23 |
| - const handleAnswer = (option: string) => { |
24 |
| - setAnswerIsCorrect(option.includes(task.correctAnswer)); |
| 27 | + const handleAnswer = (optionValue: string) => { |
| 28 | + const isCorrect = task.correctAnswer === optionValue; |
| 29 | + setAnswerIsCorrect(isCorrect); |
| 30 | + fetch("/api/tasks/answer", { |
| 31 | + method: "POST", |
| 32 | + headers: { |
| 33 | + "Content-Type": "application/json", |
| 34 | + }, |
| 35 | + body: JSON.stringify({ |
| 36 | + answer: { |
| 37 | + taskId: task.id, |
| 38 | + answer: optionValue, |
| 39 | + isCorrect, |
| 40 | + }, |
| 41 | + }), |
| 42 | + }); |
25 | 43 | };
|
26 | 44 |
|
27 | 45 | const handleNext = () => {
|
@@ -56,19 +74,19 @@ export const GeoGLUETaskCard: React.FC<{
|
56 | 74 | {options.map((option) => {
|
57 | 75 | return (
|
58 | 76 | <button
|
59 |
| - key={option} |
60 |
| - onClick={() => handleAnswer(option)} |
| 77 | + key={option.value} |
| 78 | + onClick={() => handleAnswer(option.value)} |
61 | 79 | style={{
|
62 | 80 | border: "none",
|
63 | 81 | borderRadius: "0.375rem",
|
64 | 82 | display: "block",
|
65 | 83 | padding: "10px",
|
66 | 84 | }}
|
67 | 85 | disabled={
|
68 |
| - answerIsCorrect !== null && option !== task.correctAnswer |
| 86 | + answerIsCorrect !== null && option.value !== task.correctAnswer |
69 | 87 | }
|
70 | 88 | >
|
71 |
| - {option} |
| 89 | + {option.label} |
72 | 90 | </button>
|
73 | 91 | );
|
74 | 92 | })}
|
|
0 commit comments