Admin.js 2.26 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
let QuizBtn = []
baesangjune's avatar
baesangjune committed
6

baesangjune's avatar
push    
baesangjune committed
7
function Admin() {
baesangjune's avatar
admin    
baesangjune committed
8

baesangjune's avatar
.    
baesangjune committed
9
10
    const [result, setresult] = useState('')
    const [QuizBtnCount, setQuizBtnCount] = useState(4)
baesangjune's avatar
push    
baesangjune committed
11

baesangjune's avatar
.    
baesangjune committed
12
13
    function handleClickSetting() {
        setresult(<AdminSetting />)
baesangjune's avatar
baesangjune committed
14
    }
baesangjune's avatar
push    
baesangjune committed
15

baesangjune's avatar
.    
baesangjune committed
16
    function handleClickQuiz(e) {
baesangjune's avatar
.    
baesangjune committed
17
        (JSON.parse(localStorage.getItem('QnA')) === null) ? setresult(<AdminQuiz QuizNum={e.target.id} data={{Q:'x' , Choose:'x', A:'x'}} />) : setresult(<AdminQuiz QuizNum={e.target.id} data={JSON.parse(localStorage.getItem('QnA'))} />)
baesangjune's avatar
baesangjune committed
18
    }
baesangjune's avatar
.    
baesangjune committed
19

baesangjune's avatar
.    
baesangjune committed
20
    function handleClickAddQuiz() {
baesangjune's avatar
.    
baesangjune committed
21
        QuizBtn.push(
baesangjune's avatar
.    
baesangjune committed
22
23
            <button type='button' className='btn btn-outline-primary' id={QuizBtnCount} onClick={handleClickQuiz}>Quiz {QuizBtnCount}</button>
        )
baesangjune's avatar
.    
baesangjune committed
24
        setQuizBtnCount(QuizBtnCount + 1)
baesangjune's avatar
baesangjune committed
25
26
    }

baesangjune's avatar
baesangjune committed
27
28
    return (
        <>
baesangjune's avatar
.    
baesangjune committed
29
30
            <div className="container-fluid">
                <div className="row justify-content-md-center mt-5">
baesangjune's avatar
.    
baesangjune committed
31
                    <div className="col-2 text-center border py-5">
baesangjune's avatar
.    
baesangjune committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
                        <div className="mb-5">
                            <h4>관리자페이지</h4>
                        </div>
                        <div>
                            <button type="button" className="btn btn-outline-info mb-5" onClick={handleClickSetting}>Setting</button>
                        </div>
                        <div class="btn-group-vertical">
                            <button type="button" className="btn btn-outline-primary" id="1" onClick={handleClickQuiz}>Quiz 1</button>
                            <button type="button" className="btn btn-outline-primary" id="2" onClick={handleClickQuiz}>Quiz 2</button>
                            <button type="button" className="btn btn-outline-primary" id="3" onClick={handleClickQuiz}>Quiz 3</button>
                            {QuizBtn.map((element) => element)}
                            <button type="button" className="btn btn-outline-primary" onClick={handleClickAddQuiz}>+</button>

                        </div>
baesangjune's avatar
baesangjune committed
46
                    </div>
baesangjune's avatar
baesangjune committed
47

baesangjune's avatar
.    
baesangjune committed
48
49
                    <div className="col-8 ">
                        {result}
baesangjune's avatar
baesangjune committed
50
51
                    </div>
                </div>
baesangjune's avatar
baesangjune committed
52
            </div>
baesangjune's avatar
baesangjune committed
53

baesangjune's avatar
admin    
baesangjune committed
54

baesangjune's avatar
.    
baesangjune committed
55
        </>
baesangjune's avatar
baesangjune committed
56
57
58
59
    )
}

export default Admin