Commit 9cd9d519 authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

ref

parent bfae38b7
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import AdminQuiz from './AdminQuiz' import AdminQuiz from './AdminQuiz'
import AdminSetting from './AdminSetting' import AdminSetting from './AdminSetting'
let QuizBtn = [] let QuizBtn = []
let QnAadmins
function Admin() { function Admin() {
const [result, setresult] = useState('') const [result, setresult] = useState('')
const [QuizBtnCount, setQuizBtnCount] = useState(4) const [QuizBtnCount, setQuizBtnCount] = useState(4)
const [n, setn] = useState(0) const indexRef = useRef(0)
const dbRef = useRef([])
useEffect(() => {
if (JSON.parse(localStorage.getItem('QnA'))) {
dbRef.current=JSON.parse(localStorage.getItem('QnA'))
}
}, [])
function handleClickSetting() { function handleClickSetting() {
setresult(<AdminSetting />) setresult(<AdminSetting />)
} }
function handleClickQuiz(e) { function handleClickQuiz(e) {
if (QnAadmins) { indexRef.current = Number(e.target.id) - 1
let QnAadmins = [] console.log(dbRef.current, indexRef.current)
setn(e.target.id) setresult(<AdminQuiz quizNum={e.target.id} fn={handleClickSave} data={dbRef.current} />)
setresult(<AdminQuiz quizNum={e.target.id} fn={handleClickSave} data={QnAadmins} />)
}
else {
setn(e.target.id)
// let QnAadmins = []
let QnAadmins = JSON.parse(localStorage.getItem('QnA'))
console.log(QnAadmins)
setresult(<AdminQuiz quizNum={e.target.id} fn={handleClickSave} data={QnAadmins[Number(n)]} />)
}
} }
function handleClickAddQuiz() { function handleClickAddQuiz() {
...@@ -38,25 +37,27 @@ function Admin() { ...@@ -38,25 +37,27 @@ function Admin() {
} }
function handleClickSave(QnAadmin) { function handleClickSave(QnAadmin) {
QnAadmins.splice(n, 0, QnAadmin) console.log(QnAadmin, indexRef.current)
localStorage.setItem('QnA', JSON.stringify(QnAadmins)) dbRef.current[indexRef.current] = QnAadmin
localStorage.setItem('QnA', JSON.stringify(dbRef.current))
} }
return ( return (
<> <>
<div className="container-fluid"> <div className="container-fluid bg-light">
<div className="row justify-content-md-center mt-5"> <div className="row justify-content-md-center mt-5">
<div className="col-2 text-center border py-5 bg-white"> <div className="col-2 text-center border py-5 bg-white">
<div className="py-3 border-top border-bottom"> <div className="py-3 border-top border-bottom">
<h5 className="font-weight-bold">ADMIN</h5> <h5 className="font-weight-bold">설정</h5>
</div> </div>
<div className="border-bottom py-4"> <div className="border-bottom py-4">
<button type="button" className="btn btn-info" onClick={handleClickSetting}>Setting</button> <button type="button" className="btn btn-info" onClick={handleClickSetting}>Setting</button>
</div> </div>
<div className="btn-group-vertical py-4"> <div className="btn-group-vertical py-4">
<button type="button" className="btn btn-outline-primary" id="1" onClick={handleClickQuiz}>Quiz 1</button> <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={2} onClick={handleClickQuiz}>Quiz 2</button>
<button type="button" className="btn btn-outline-primary" id="3" onClick={handleClickQuiz}>Quiz 3</button> <button type="button" className="btn btn-outline-primary" id={3} onClick={handleClickQuiz}>Quiz 3</button>
{QuizBtn.map((element) => element)} {QuizBtn.map((element) => element)}
<button type="button" className="btn btn-outline-primary" onClick={handleClickAddQuiz}>+</button> <button type="button" className="btn btn-outline-primary" onClick={handleClickAddQuiz}>+</button>
......
import React, { useState, useEffect} from 'react'; import React, { useState} from 'react';
let list = [] let list = []
let QnAadmin = {} let QnAadmin = {}
...@@ -53,7 +53,7 @@ function AdminQuiz(props) { ...@@ -53,7 +53,7 @@ function AdminQuiz(props) {
} }
else { else {
QnAadmin['Choose'] = Object.values(savechoose) QnAadmin['Choose'] = Object.values(savechoose)
QnAadmin['N'] = String(props.QuizNum) QnAadmin['N'] = String(props.quizNum)
props.fn(QnAadmin) props.fn(QnAadmin)
QnAadmin = {} QnAadmin = {}
alert('입력이 완료되었습니다.') alert('입력이 완료되었습니다.')
...@@ -65,7 +65,7 @@ function AdminQuiz(props) { ...@@ -65,7 +65,7 @@ function AdminQuiz(props) {
return ( return (
<div className="" id="Quiz1"> <div className="" id="Quiz1">
<h2 className="p-3 border text-center">{String(props.quizNum)} 문제만들기</h2> <h2 className="p-3 border text-center bg-white">{String(props.quizNum)} 문제만들기</h2>
<div className="p-3 borber"> <div className="p-3 borber">
<div className="p-3 "> <div className="p-3 ">
<span className="font-weight-bold mr-2 h3">1. 문제 입력하기</span> <span className="font-weight-bold mr-2 h3">1. 문제 입력하기</span>
...@@ -80,7 +80,7 @@ function AdminQuiz(props) { ...@@ -80,7 +80,7 @@ function AdminQuiz(props) {
<input type="radio" checked={false} name="answer" /> <input type="radio" checked={false} name="answer" />
</div> </div>
</div> </div>
<input type="text" className="form-control" id='1' placeholder="보기를 입력하세요" onChange={handleChangeChoose} /> <input type="text" className="form-control" id='1' placeholder="보기를 입력하세요" onChange={handleChangeChoose} />
</div> </div>
{list.map((element) => element)} {list.map((element) => element)}
<button className="btn btn-outline-secondary btn-sm" onClick={addSelectOption}>+</button> <button className="btn btn-outline-secondary btn-sm" onClick={addSelectOption}>+</button>
......
...@@ -47,19 +47,19 @@ function AdminSetting() { ...@@ -47,19 +47,19 @@ function AdminSetting() {
} }
return ( return (
<div className="col-8"> <div className="">
<h2 className="p-3 border text-center">관리자 설정 변경 </h2> <h2 className="p-3 border text-center bg-white">관리자 설정 변경 </h2>
<div className="p-3 border"> <div className="p-3 border bg-white">
<h4>변경할 비밀번호를 입력하세요</h4> <h4>변경할 비밀번호를 입력하세요</h4>
<input type="text" onChange={handleChangePassword} placeholder="New Password" /> <input type="text" onChange={handleChangePassword} placeholder="New Password" />
</div> </div>
<div className="p-3 border"> <div className="p-3 border bg-white">
<h4>변경할 관리자 비밀번호를 입력하세요</h4> <h4>변경할 관리자 비밀번호를 입력하세요</h4>
<input type="text" onChange={handleChangeAdminPassword} placeholder="New Admin Password" /> <input type="text" onChange={handleChangeAdminPassword} placeholder="New Admin Password" />
</div> </div>
<div className="p-3 border"> <div className="p-3 border bg-white">
<h4>타이머를 설정하세요(초단위)</h4> <h4>타이머를 설정하세요(초단위)</h4>
<input type="text" onChange={handleChangeTime} placeholder="Set Time" /> <input type="text" onChange={handleChangeTime} placeholder="Set Time" />
......
...@@ -10,9 +10,9 @@ function App() { ...@@ -10,9 +10,9 @@ function App() {
return ( return (
<Router> <Router>
<div className="container-fluid vh-100 bg-light"> <div className="container-fluid vh-100 bg-light">
<header className="border-bottom"> <header className="border-bottom bg-white">
<Link to="/"> <Link to="/">
<button className="ml-3 btn btn-light btn-lg font-weight-bold text-info">Home</button> <button className="ml-3 btn btn-white btn-lg font-weight-bold text-info">Home</button>
</Link> </Link>
</header> </header>
<Switch> <Switch>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment