Admin.js 10 KB
Newer Older
baesangjune's avatar
baesangjune committed
1
import React, { useState } from 'react';
baesangjune's avatar
baesangjune committed
2

baesangjune's avatar
baesangjune committed
3

baesangjune's avatar
push    
baesangjune committed
4
5
let QnAadmins = []
let QnAadmin = {}
baesangjune's avatar
baesangjune committed
6

baesangjune's avatar
push    
baesangjune committed
7
8
let Setadmins = []
let Setadmin = {}
baesangjune's avatar
baesangjune committed
9

baesangjune's avatar
push    
baesangjune committed
10
function Admin() {
baesangjune's avatar
admin    
baesangjune committed
11

baesangjune's avatar
baesangjune committed
12
13
14
    const [question, setQuestion] = useState('')
    const [choose, setChoose] = useState('')
    const [answer, setAnswer] = useState('')
baesangjune's avatar
baesangjune committed
15
16
17
    const [password, setPassword] = useState('')
    const [adminpassword, setAdminPassword] = useState('')
    const [time, setTime] = useState('')
baesangjune's avatar
admin    
baesangjune committed
18
19
    const [addQuiz, setaddQuiz] = useState('')
    const [selectOption, setselectOption] = useState('')
baesangjune's avatar
baesangjune committed
20

baesangjune's avatar
admin    
baesangjune committed
21
22

    const handleChangeQuestion = (event) => {
baesangjune's avatar
push    
baesangjune committed
23
24
25
       
        QnAadmin['Q'] = event.target.value

baesangjune's avatar
baesangjune committed
26
        setQuestion(event.target.value)
baesangjune's avatar
push    
baesangjune committed
27
        
baesangjune's avatar
baesangjune committed
28
29
    }
    const handleChangechoose = (event) => {
baesangjune's avatar
push    
baesangjune committed
30
31
32
      
        QnAadmin['Choose'] = event.target.value

baesangjune's avatar
baesangjune committed
33
        setChoose(event.target.value)
baesangjune's avatar
push    
baesangjune committed
34
35


baesangjune's avatar
baesangjune committed
36
37
    }
    const handleChangeanswer = (event) => {
baesangjune's avatar
push    
baesangjune committed
38
39
40
        
        QnAadmin['A'] = event.target.value
      
baesangjune's avatar
baesangjune committed
41
        setAnswer(event.target.value)
baesangjune's avatar
push    
baesangjune committed
42
43
44

  

baesangjune's avatar
baesangjune committed
45
    }
baesangjune's avatar
baesangjune committed
46
    const handleChangePassword = (event) => {
baesangjune's avatar
push    
baesangjune committed
47
        Setadmin['password'] = event.target.value
baesangjune's avatar
baesangjune committed
48
        setPassword(event.target.value)
baesangjune's avatar
push    
baesangjune committed
49

baesangjune's avatar
baesangjune committed
50
51
    }
    const handleChangeAdminPassword = (event) => {
baesangjune's avatar
push    
baesangjune committed
52
        Setadmin['AdminPassword'] = event.target.value
baesangjune's avatar
baesangjune committed
53
54
55
        setAdminPassword(event.target.value)
    }
    const handleChangeTime = (event) => {
baesangjune's avatar
push    
baesangjune committed
56
        Setadmin['Time'] = event.target.value
baesangjune's avatar
baesangjune committed
57
58
59
        setTime(event.target.value)
    }

baesangjune's avatar
baesangjune committed
60

baesangjune's avatar
push    
baesangjune committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    function handleClickQnA() {
        if (!question) {
            alert('문제가 입력되지 않았습니다.')
        }
        else if (!choose) {
            alert('보기가 입력되지 않았습니다.')
        }
        else if (!answer) {
            alert('정답이 입력되지 않았습니다.')
        }
        else {
            console.log(QnAadmin)
            QnAadmins.push(QnAadmin)
            localStorage.setItem('QnA', JSON.stringify(QnAadmins))
            console.log(QnAadmins)
            alert('입력이 완료되었습니다.')
        }
baesangjune's avatar
baesangjune committed
78

baesangjune's avatar
push    
baesangjune committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    }
    function handleClicksetting() {
        if (!password) {
            alert('비밀번호가 입력되지 않았습니다.')
        }
        else if (!adminpassword) {
            alert('관리자 비밀번호가 입력되지 않았습니다.')
        }
        else if (!time) {
            alert('제한시간이 입력되지 않았습니다.') //타임은 조건은 빼도 될 듯
        }
        else {
            Setadmins.push(Setadmin)
            localStorage.setItem('Set', JSON.stringify(Setadmins))
            console.log(Setadmins)
            alert('저장이 완료되었습니다.')
            console.log(Setadmin)

            // setDoneset(true)
        }
baesangjune's avatar
baesangjune committed
99

baesangjune's avatar
admin    
baesangjune committed
100
101
102
103
104
105
106
107
108
    }
    function addSelectOption() {
        let list = function () {
            return <div className="input-group">
                <div className="input-group-prepend">
                    <div className="input-group-text">
                        <input type="radio" id="option" />
                    </div>
                </div>
baesangjune's avatar
css    
baesangjune committed
109
                <input type="text" className="form-control" placeholder="보기를 입력하세요" onChange={handleChangechoose} />
baesangjune's avatar
admin    
baesangjune committed
110
111
112
            </div>
        }
        setselectOption(list)
baesangjune's avatar
baesangjune committed
113
    }
baesangjune's avatar
baesangjune committed
114
    function handleClickQuiz() {
baesangjune's avatar
admin    
baesangjune committed
115
        let addQuiz = function () {
baesangjune's avatar
push    
baesangjune committed
116
117
            return <a className="nav-link" id="Quiz4-tab" data-toggle="pill" href="#Quiz" role="tab" >Quiz4</a>
        }   
baesangjune's avatar
baesangjune committed
118
119
        setaddQuiz(addQuiz)
    }
baesangjune's avatar
baesangjune committed
120

baesangjune's avatar
baesangjune committed
121
122
    return (
        <>
baesangjune's avatar
push    
baesangjune committed
123
124
125
            {/* {doneQnA ? alert('모두 입력되었습니다.') : ''}
            {doneset ? alert('모두 입력되었습니다.') : ''} */}

baesangjune's avatar
.    
baesangjune committed
126
            <div className="row justify-content-md-center mt-5 ">
baesangjune's avatar
css    
baesangjune committed
127
                <div className="col-2 text-center border">
baesangjune's avatar
baesangjune committed
128
                    <div className="container-fluid ">
baesangjune's avatar
css    
baesangjune committed
129
130
                        <div className="navbar-header p-3 ">
                            <p className="navbar-brand border-bottom ">관리자 페이지</p>
baesangjune's avatar
baesangjune committed
131
                        </div>
baesangjune's avatar
.    
baesangjune committed
132
                        <div className="nav flex-column nav-pills" id="v-pills-tab" role="tablist">
baesangjune's avatar
admin    
baesangjune committed
133

baesangjune's avatar
css    
baesangjune committed
134
                            <p className="navbar-text border-bottom">관리자 설정 변경하기</p>
baesangjune's avatar
admin    
baesangjune committed
135

baesangjune's avatar
.    
baesangjune committed
136
                            <a className="nav-link" id="setting-tab" data-toggle='pill' href="#setting">Setting</a>
baesangjune's avatar
admin    
baesangjune committed
137
138


baesangjune's avatar
push    
baesangjune committed
139
                            <p className="navbar-text border-bottom">Quiz 입력하기</p> {/*Quiz1 버튼에 무언갈 쓰고 Quiz2를 누르면 초기화되도록하기*/}
baesangjune's avatar
admin    
baesangjune committed
140

baesangjune's avatar
push    
baesangjune committed
141
142
143
                            <a className="nav-link" id="Quiz-tab" data-toggle="pill" href="#Quiz" >Quiz1</a>
                            <a className="nav-link" id="Quiz-tab" data-toggle="pill" href="#Quiz" >Quiz2</a>
                            <a className="nav-link" id="Quiz-tab" data-toggle="pill" href="#Quiz" >Quiz3</a>
baesangjune's avatar
admin    
baesangjune committed
144
                            {addQuiz}
baesangjune's avatar
css    
baesangjune committed
145
                            <button className="btn btn-danger navbar-btn" onClick={handleClickQuiz} >Quiz 추가</button>
baesangjune's avatar
admin    
baesangjune committed
146

baesangjune's avatar
baesangjune committed
147
148

                        </div>
baesangjune's avatar
baesangjune committed
149
150
                    </div>
                </div>
baesangjune's avatar
css    
baesangjune committed
151
                <div className="col-8">
baesangjune's avatar
baesangjune committed
152
                    <div className="tab-content" id="v-pills-tabContent">
baesangjune's avatar
css    
baesangjune committed
153
                        <div className="tab-pane fade show active" id="setting" role="tabpanel" >
baesangjune's avatar
baesangjune committed
154
155
156
157
                            <div>
                                <div className="container">
                                    <div className="row d-flex justify-content-center">
                                        <div className="col-8">
baesangjune's avatar
baesangjune committed
158

baesangjune's avatar
.    
baesangjune committed
159
                                            <h2 className="p-3 border text-center bg-danger">관리자 설정변경</h2>
baesangjune's avatar
baesangjune committed
160
                                            <div className="p-3 border">
baesangjune's avatar
.    
baesangjune committed
161
162
                                                <h3>변경할 비밀번호를 입력하세요</h3>
                                                <input className='p-2' type="text" onChange={handleChangePassword} placeholder="New Password" />
baesangjune's avatar
baesangjune committed
163

baesangjune's avatar
baesangjune committed
164
165
                                            </div>
                                            <div className="p-3 border">
baesangjune's avatar
.    
baesangjune committed
166
167
                                                <h3>변경할 관리자 비밀번호를 입력하세요</h3>
                                                <input className='p-2' type="text" onChange={handleChangeAdminPassword} placeholder="New Admin Password" />
baesangjune's avatar
baesangjune committed
168

baesangjune's avatar
baesangjune committed
169
170
                                            </div>
                                            <div className="p-3 border">
baesangjune's avatar
.    
baesangjune committed
171
172
                                                <h3>타이머를 설정하세요(초단위)</h3>
                                                <input className='p-2' type="text" onChange={handleChangeTime} placeholder="Set Time" />
baesangjune's avatar
baesangjune committed
173

baesangjune's avatar
baesangjune committed
174
175
176
177
                                            </div>


                                            <label for="inputLogin" className="d-flex justify-content-center">
baesangjune's avatar
push    
baesangjune committed
178
                                                <button className="mt-4 btn btn-dark" onClick={handleClicksetting}>작성완료</button>
baesangjune's avatar
baesangjune committed
179
180
181
182
183
                                            </label>

                                        </div>
                                    </div>
                                </div>
baesangjune's avatar
baesangjune committed
184

baesangjune's avatar
baesangjune committed
185
                            </div>
baesangjune's avatar
baesangjune committed
186

baesangjune's avatar
baesangjune committed
187
                        </div>
baesangjune's avatar
admin    
baesangjune committed
188

baesangjune's avatar
push    
baesangjune committed
189
                        <div className="tab-pane fade" id="Quiz" role="tabpanel">
baesangjune's avatar
baesangjune committed
190
191
192
193
                            <div className="container">
                                <div className="row d-flex justify-content-center">
                                    <div className="col-8">

baesangjune's avatar
.    
baesangjune committed
194
                                        <h2 className="p-3 border text-center bg-danger">문제만들기</h2>
baesangjune's avatar
baesangjune committed
195

baesangjune's avatar
admin    
baesangjune committed
196
197
198
199
                                        <div className="p-3 borber">
                                            <div className="p-3 ">
                                                <span className="font-weight-bold mr-2 h3">1.</span>
                                                {/* <input type="text" onChange={handleChangenumber} placeholder="Number" /> */}
baesangjune's avatar
.    
baesangjune committed
200
                                                <input className='p-2' type="text" onChange={handleChangeQuestion} placeholder="문제를 입력하세요" />
baesangjune's avatar
baesangjune committed
201

baesangjune's avatar
admin    
baesangjune committed
202
                                            </div>
baesangjune's avatar
baesangjune committed
203

baesangjune's avatar
admin    
baesangjune committed
204
205
206
                                            <div className="p-3 ">
                                                <div className="input-group">
                                                    <div className="input-group-prepend">
baesangjune's avatar
.    
baesangjune committed
207
                                                        <div className="input-group-text p-3">
baesangjune's avatar
admin    
baesangjune committed
208
209
210
                                                            <input type="radio" id="option" />
                                                        </div>
                                                    </div>
baesangjune's avatar
.    
baesangjune committed
211
                                                    <input type="text" className="form-control p-4" placeholder="보기를 입력하세요" onChange={handleChangechoose} />
baesangjune's avatar
admin    
baesangjune committed
212
213
                                                </div>
                                                {selectOption}
baesangjune's avatar
baesangjune committed
214

baesangjune's avatar
admin    
baesangjune committed
215
216
217
                                                <button className="btn btn-outline-secondary btn-sm" onClick={addSelectOption}>+</button>

                                            </div>
baesangjune's avatar
baesangjune committed
218

baesangjune's avatar
admin    
baesangjune committed
219
220
                                            <div className="p-3 ">
                                                <span className="font-weight-bold mr-2 h3">정답:</span>
baesangjune's avatar
.    
baesangjune committed
221
                                                <input className='p-2' type="text" onChange={handleChangeanswer} placeholder="정답을 입력하세요" />
baesangjune's avatar
admin    
baesangjune committed
222
                                            </div>
baesangjune's avatar
baesangjune committed
223

baesangjune's avatar
admin    
baesangjune committed
224
                                            <label for="inputLogin" className="d-flex justify-content-center">
baesangjune's avatar
push    
baesangjune committed
225
                                                <button className="mt-4 btn btn-dark" onClick={handleClickQnA}>작성완료</button>
baesangjune's avatar
admin    
baesangjune committed
226
227
228
                                            </label>

                                        </div>
baesangjune's avatar
baesangjune committed
229
230
231
                                    </div>
                                </div>
                            </div>
baesangjune's avatar
baesangjune committed
232
233
234
235
                        </div>
                    </div>
                </div>
            </div>
baesangjune's avatar
admin    
baesangjune committed
236

baesangjune's avatar
baesangjune committed
237
238
239
240
241
        </>
    )
}

export default Admin