AdminQuiz.js 3.74 KB
Newer Older
Jiwon Yoon's avatar
ref    
Jiwon Yoon committed
1
import React, { useState} from 'react';
Jiwon Yoon's avatar
Jiwon Yoon committed
2
3

let list = []
Jiwon Yoon's avatar
a    
Jiwon Yoon committed
4
let QnAadmin = {}
Jiwon Yoon's avatar
asd    
Jiwon Yoon committed
5
let savechoose = {}
Jiwon Yoon's avatar
choose    
Jiwon Yoon committed
6

Jiwon Yoon's avatar
A    
Jiwon Yoon committed
7
function AdminQuiz(props) {
Jiwon Yoon's avatar
Jiwon Yoon committed
8
9
10
11
12
13
14

    const [question, setQuestion] = useState('')
    const [choose, setChoose] = useState('')
    const [answer, setAnswer] = useState('')
    const [selectOption, setselectOption] = useState(1)

    const handleChangeQuestion = (event) => {
Jiwon Yoon's avatar
a    
Jiwon Yoon committed
15
        QnAadmin['Q'] = event.target.value
Jiwon Yoon's avatar
Jiwon Yoon committed
16
17
        setQuestion(event.target.value)
    }
Jiwon Yoon's avatar
ha..    
Jiwon Yoon committed
18

Jiwon Yoon's avatar
Jiwon Yoon committed
19
    const handleChangeChoose = (event) => {
Jiwon Yoon's avatar
asd    
Jiwon Yoon committed
20
        savechoose[event.target.id] = event.target.value
Jiwon Yoon's avatar
Jiwon Yoon committed
21
22
        setChoose(event.target.value)
    }
Jiwon Yoon's avatar
a    
Jiwon Yoon committed
23

Jiwon Yoon's avatar
a    
Jiwon Yoon committed
24
    const handleChangeanswer = (event) => {
Jiwon Yoon's avatar
a    
Jiwon Yoon committed
25
        QnAadmin['A'] = event.target.value
Jiwon Yoon's avatar
Jiwon Yoon committed
26
27
28
29
30
31
32
33
        setAnswer(event.target.value)
    }

    function addSelectOption() {
        list.push(
            <div className="input-group">
                <div className="input-group-prepend">
                    <div className="input-group-text">
Jiwon Yoon's avatar
ha..    
Jiwon Yoon committed
34
                        <input type="radio" checked={false} name="answer" />
Jiwon Yoon's avatar
Jiwon Yoon committed
35
36
                    </div>
                </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
37
                <input type="text" class="form-control" id={String(selectOption + 1)} placeholder="보기를 입력하세요" onChange={handleChangeChoose} />
Jiwon Yoon's avatar
Jiwon Yoon committed
38
39
40
41
42
            </div>
        )
        setselectOption(selectOption + 1)
    }

Jiwon Yoon's avatar
A    
Jiwon Yoon committed
43

Jiwon Yoon's avatar
Jiwon Yoon committed
44
    function handleClick() {
Jiwon Yoon's avatar
a    
Jiwon Yoon committed
45
46
47
48
49
50
51
52
53
54
        if (!question) {
            alert('문제가 입력되지 않았습니다.')
        }
        else if (!choose) {
            alert('보기가 입력되지 않았습니다.')
        }
        else if (!answer) {
            alert('정답이 입력되지 않았습니다.')
        }
        else {
Jiwon Yoon's avatar
ha..    
Jiwon Yoon committed
55
            QnAadmin['Choose'] = Object.values(savechoose)
Jiwon Yoon's avatar
ref    
Jiwon Yoon committed
56
            QnAadmin['N'] = String(props.quizNum)
Jiwon Yoon's avatar
splice    
Jiwon Yoon committed
57
            props.fn(QnAadmin)
Jiwon Yoon's avatar
asd    
Jiwon Yoon committed
58
            QnAadmin = {}
Jiwon Yoon's avatar
a    
Jiwon Yoon committed
59
60
            alert('입력이 완료되었습니다.')
        }
Jiwon Yoon's avatar
Jiwon Yoon committed
61
62
63

    }

baesangjune's avatar
.    
baesangjune committed
64
65


Jiwon Yoon's avatar
Jiwon Yoon committed
66
67
    return (
        <div className="" id="Quiz1">
Jiwon Yoon's avatar
ref    
Jiwon Yoon committed
68
            <h2 className="p-3 border text-center bg-white">{String(props.quizNum)} 문제만들기</h2>
Jiwon Yoon's avatar
Jiwon Yoon committed
69
70
            <div className="p-3 borber">
                <div className="p-3 ">
Jiwon Yoon's avatar
A    
Jiwon Yoon committed
71
                    <span className="font-weight-bold mr-2 h3">1. 문제 입력하기</span>
Jiwon Yoon's avatar
Jiwon Yoon committed
72
                    <input type="text" id="inputQuiz" className="form-control" value={question} onChange={handleChangeQuestion} placeholder="문제를 입력하세요" />
Jiwon Yoon's avatar
Jiwon Yoon committed
73
74
                </div>
                <div className="p-3 ">
Jiwon Yoon's avatar
A    
Jiwon Yoon committed
75
76
                    <span className="font-weight-bold mr-2 h3">2. 보기 입력하기</span>
                    <div className="p-3 ">
baesangjune's avatar
.    
baesangjune committed
77
78
79
                    <div className="input-group">
                        <div className="input-group-prepend">
                            <div className="input-group-text">
baesangjune's avatar
.    
baesangjune committed
80
                            <input type="radio" checked={false} name="answer" />
Jiwon Yoon's avatar
Jiwon Yoon committed
81
82
                            </div>
                        </div>
Jiwon Yoon's avatar
ref    
Jiwon Yoon committed
83
                        <input type="text" className="form-control" id='1' placeholder="보기를 입력하세요" onChange={handleChangeChoose} />
Jiwon Yoon's avatar
Jiwon Yoon committed
84
                    </div>
baesangjune's avatar
.    
baesangjune committed
85
86
87
                    {list.map((element) => element)}
                    <button className="btn btn-outline-secondary btn-sm" onClick={addSelectOption}>+</button>
                </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
88
                </div>
Jiwon Yoon's avatar
A    
Jiwon Yoon committed
89

Jiwon Yoon's avatar
Jiwon Yoon committed
90
91
                <div className="p-3 ">
                    <span className="font-weight-bold mr-2 h3">정답:</span>
Jiwon Yoon's avatar
Jiwon Yoon committed
92
                    <input type="text" value={answer} onChange={handleChangeanswer} placeholder="정답을 입력하세요" />
Jiwon Yoon's avatar
Jiwon Yoon committed
93
94
95
96
97
98
99
100
101
102
103
                </div>

                <label for="inputLogin" className="d-flex justify-content-center">
                    <button className="mt-4 btn btn-dark" onClick={handleClick}>작성완료</button>
                </label>
            </div>
        </div>
    )
}

export default AdminQuiz