Commit bfae38b7 authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

ㅇㅁㅇㅁㅇㅁㅇㅁ

parent 41b1059e
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
import AdminQuiz from './AdminQuiz' import AdminQuiz from './AdminQuiz'
import AdminSetting from './AdminSetting' import AdminSetting from './AdminSetting'
let QuizBtn = [] let QuizBtn = []
let QnAadmins = [] 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 [n, setn] = useState(0)
function handleClickSetting() { function handleClickSetting() {
setresult(<AdminSetting />) setresult(<AdminSetting />)
} }
function handleClickQuiz(e) { function handleClickQuiz(e) {
setn(e.target.id) if (QnAadmins) {
console.log(QnAadmins) let QnAadmins = []
setresult(<AdminQuiz quizNum={e.target.id} fn={handleClickSave} data={QnAadmins[e.target.id]} />) setn(e.target.id)
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() {
...@@ -28,7 +37,7 @@ function Admin() { ...@@ -28,7 +37,7 @@ function Admin() {
setQuizBtnCount(QuizBtnCount + 1) setQuizBtnCount(QuizBtnCount + 1)
} }
function handleClickSave(QnAadmin){ function handleClickSave(QnAadmin) {
QnAadmins.splice(n, 0, QnAadmin) QnAadmins.splice(n, 0, QnAadmin)
localStorage.setItem('QnA', JSON.stringify(QnAadmins)) localStorage.setItem('QnA', JSON.stringify(QnAadmins))
} }
......
...@@ -10,25 +10,6 @@ function AdminQuiz(props) { ...@@ -10,25 +10,6 @@ function AdminQuiz(props) {
const [choose, setChoose] = useState('') const [choose, setChoose] = useState('')
const [answer, setAnswer] = useState('') const [answer, setAnswer] = useState('')
const [selectOption, setselectOption] = useState(1) const [selectOption, setselectOption] = useState(1)
const [q, setq] = useState('')
const [c, setc] = useState([])
const [a, seta] = useState('')
useEffect(()=>{
setQuestion('')
setChoose('')
if(props.data){
setq(props.data.Q)
setc(props.data.Choose)
seta(props.data.A)
}
else {
setq('보기를 입력하세요')
setc(['보기를 입력하세요','보기를 입력하세요','보기를 입력하세요','보기를 입력하세요'])
seta('보기를 입력하세요')
}
},[props.quizNum])
const handleChangeQuestion = (event) => { const handleChangeQuestion = (event) => {
QnAadmin['Q'] = event.target.value QnAadmin['Q'] = event.target.value
...@@ -53,7 +34,7 @@ function AdminQuiz(props) { ...@@ -53,7 +34,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" class="form-control" id={String(selectOption + 1)} placeholder={c[1]} onChange={handleChangeChoose} /> <input type="text" class="form-control" id={String(selectOption + 1)} placeholder="보기를 입력하세요" onChange={handleChangeChoose} />
</div> </div>
) )
setselectOption(selectOption + 1) setselectOption(selectOption + 1)
...@@ -88,7 +69,7 @@ function AdminQuiz(props) { ...@@ -88,7 +69,7 @@ function AdminQuiz(props) {
<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>
<input type="text" id="inputQuiz" className="form-control" value={question} onChange={handleChangeQuestion} placeholder={q} /> <input type="text" id="inputQuiz" className="form-control" value={question} onChange={handleChangeQuestion} placeholder="문제를 입력하세요" />
</div> </div>
<div className="p-3 "> <div className="p-3 ">
<span className="font-weight-bold mr-2 h3">2. 보기 입력하기</span> <span className="font-weight-bold mr-2 h3">2. 보기 입력하기</span>
...@@ -99,7 +80,7 @@ function AdminQuiz(props) { ...@@ -99,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={c[0]} 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>
...@@ -108,7 +89,7 @@ function AdminQuiz(props) { ...@@ -108,7 +89,7 @@ function AdminQuiz(props) {
<div className="p-3 "> <div className="p-3 ">
<span className="font-weight-bold mr-2 h3">정답:</span> <span className="font-weight-bold mr-2 h3">정답:</span>
<input type="text" value={answer} onChange={handleChangeanswer} placeholder={a} /> <input type="text" value={answer} onChange={handleChangeanswer} placeholder="정답을 입력하세요" />
</div> </div>
<label for="inputLogin" className="d-flex justify-content-center"> <label for="inputLogin" className="d-flex justify-content-center">
......
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