Admin.js 10.1 KB
Newer Older
baesangjune's avatar
baesangjune committed
1
import React, { useState } from 'react';
baesangjune's avatar
.    
baesangjune committed
2
3
import AdminQuiz from './AdminQuiz'
import AdminSetting from './AdminSetting'
baesangjune's avatar
baesangjune committed
4

baesangjune's avatar
baesangjune committed
5

baesangjune's avatar
push    
baesangjune committed
6
7
let QnAadmins = []
let QnAadmin = {}
baesangjune's avatar
baesangjune committed
8

baesangjune's avatar
push    
baesangjune committed
9
10
let Setadmins = []
let Setadmin = {}
baesangjune's avatar
baesangjune committed
11

baesangjune's avatar
push    
baesangjune committed
12
function Admin() {
baesangjune's avatar
admin    
baesangjune committed
13

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

baesangjune's avatar
admin    
baesangjune committed
23
24

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

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

baesangjune's avatar
baesangjune committed
35
        setChoose(event.target.value)
baesangjune's avatar
push    
baesangjune committed
36
37


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

  

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

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

baesangjune's avatar
baesangjune committed
62

baesangjune's avatar
push    
baesangjune committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
    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
80

baesangjune's avatar
push    
baesangjune committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
    }
    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
101

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

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

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

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

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


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

baesangjune's avatar
push    
baesangjune committed
143
144
145
                            <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
146
                            {addQuiz}
baesangjune's avatar
css    
baesangjune committed
147
                            <button className="btn btn-danger navbar-btn" onClick={handleClickQuiz} >Quiz 추가</button>
baesangjune's avatar
admin    
baesangjune committed
148

baesangjune's avatar
baesangjune committed
149
150

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

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

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

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

baesangjune's avatar
baesangjune committed
176
177
178
179
                                            </div>


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

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

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

baesangjune's avatar
baesangjune committed
189
                        </div>
baesangjune's avatar
admin    
baesangjune committed
190

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

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

baesangjune's avatar
admin    
baesangjune committed
198
199
200
201
                                        <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
202
                                                <input className='p-2' type="text" onChange={handleChangeQuestion} placeholder="문제를 입력하세요" />
baesangjune's avatar
baesangjune committed
203

baesangjune's avatar
admin    
baesangjune committed
204
                                            </div>
baesangjune's avatar
baesangjune committed
205

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

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

                                            </div>
baesangjune's avatar
baesangjune committed
220

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

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

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

baesangjune's avatar
baesangjune committed
239
240
241
242
243
        </>
    )
}

export default Admin