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

JeongYeonwoo's avatar
JeongYeonwoo committed
5
let QuizBtn = []
JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
6
7
8

function Admin() {

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

JeongYeonwoo's avatar
JeongYeonwoo committed
12
13
    function handleClickSetting() {
        setresult(<AdminSetting />)
JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
14
15
    }

JeongYeonwoo's avatar
JeongYeonwoo committed
16
17
    function handleClickQuiz(e) {
        (JSON.parse(localStorage.getItem('QnA')) === null) ? setresult(<AdminQuiz QuizNum={e.target.id} data={[{ Q: 'x', Choose: 'x', A: 'x' ,N :1},{ Q: 'x', Choose: 'x', A: 'x' ,N :2},{ Q: 'x', Choose: 'x', A: 'x' ,N :3}]} />) : setresult(<AdminQuiz QuizNum={e.target.id} data={JSON.parse(localStorage.getItem('QnA'))} />)
JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
18
    }
JeongYeonwoo's avatar
JeongYeonwoo committed
19
20

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

    return (
        <>
JeongYeonwoo's avatar
JeongYeonwoo committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
            <div className="container-fluid">
                <div className="row justify-content-md-center mt-5">
                    <div className="col-2 text-center border py-5">
                        <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>
JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
44

JeongYeonwoo's avatar
JeongYeonwoo committed
45
                        </div>
JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
46
                    </div>
JeongYeonwoo's avatar
JeongYeonwoo committed
47

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

JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
54

JeongYeonwoo's avatar
JeongYeonwoo committed
55
        </>
JeongYeonwoo's avatar
quiz    
JeongYeonwoo committed
56
57
58
59
    )
}

export default Admin