Commit 5d9b4992 authored by baesangjune's avatar baesangjune
Browse files

choose

parent 70813adc
...@@ -4,7 +4,7 @@ let list = [] ...@@ -4,7 +4,7 @@ let list = []
let QnAadmins = [] let QnAadmins = []
let QnAadmin = {} let QnAadmin = {}
let c = {}
function AdminQuiz() { function AdminQuiz() {
...@@ -21,8 +21,8 @@ function AdminQuiz() { ...@@ -21,8 +21,8 @@ function AdminQuiz() {
setQuestion(event.target.value) setQuestion(event.target.value)
} }
const handleChangeChoose = (event) => { const handleChangeChoose = (event) => {
c[event.target.id] = event.target.value
QnAadmin['Choose'] = event.target.value // QnAadmin['Choose'] = event.target.value
setChoose(event.target.value) setChoose(event.target.value)
} }
...@@ -40,16 +40,16 @@ function AdminQuiz() { ...@@ -40,16 +40,16 @@ function AdminQuiz() {
<div className="input-group"> <div className="input-group">
<div className="input-group-prepend"> <div className="input-group-prepend">
<div className="input-group-text"> <div className="input-group-text">
<input type="radio" id={selectOption + 1} name="answer" /> <input type="radio" name="answer" />
</div> </div>
</div> </div>
<input type="text" class="form-control" placeholder="보기를 입력하세요" onChange={handleChangeChoose} /> <input type="text" class="form-control" id={String(selectOption + 1)} placeholder="보기를 입력하세요" onChange={handleChangeChoose} />
</div> </div>
) )
setselectOption(selectOption + 1) setselectOption(selectOption + 1)
} }
function handleClick() { function handleClick() {
if (!question) { if (!question) {
alert('문제가 입력되지 않았습니다.') alert('문제가 입력되지 않았습니다.')
...@@ -62,8 +62,9 @@ function AdminQuiz() { ...@@ -62,8 +62,9 @@ function AdminQuiz() {
} }
else { else {
console.log(QnAadmin) console.log(QnAadmin)
QnAadmin['Choose']=Object.values(c)
QnAadmins.push(QnAadmin) QnAadmins.push(QnAadmin)
QnAadmin ={} QnAadmin = {}
localStorage.setItem('QnA', JSON.stringify(QnAadmins)) localStorage.setItem('QnA', JSON.stringify(QnAadmins))
console.log(QnAadmins) console.log(QnAadmins)
alert('입력이 완료되었습니다.') alert('입력이 완료되었습니다.')
...@@ -83,13 +84,13 @@ function AdminQuiz() { ...@@ -83,13 +84,13 @@ function AdminQuiz() {
<input type="text" className="form-control" onChange={handleChangeQuestion} placeholder="문제를 입력하세요" /> <input type="text" className="form-control" 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>
<div className="input-group"> <div className="input-group">
<div className="input-group-prepend"> <div className="input-group-prepend">
<div className="input-group-text"> <div className="input-group-text">
<input type="radio" id={selectOption} name="answer" /> <input type="radio" id={selectOption} name="answer" />
</div> </div>
</div> </div>
<input type="text" className="form-control" placeholder="보기를 입력하세요" onChange={handleChangeChoose} /> <input type="text" className="form-control" placeholder="보기를 입력하세요" onChange={handleChangeChoose} />
</div> </div>
{list.map((element) => element)} {list.map((element) => element)}
......
import React, { useState } from 'react'; import React, { useState } from 'react';
// import { Link } from 'react-router-dom';
function Admin() { let list = []
let QnAadmins = []
let QnAadmin = {}
let c = {}
function AdminQuiz() {
const [question, setQuestion] = useState('') const [question, setQuestion] = useState('')
const [choose, setChoose] = useState('') const [choose, setChoose] = useState('')
const [answer, setAnswer] = useState('') const [answer, setAnswer] = useState('')
const [selectOption, setselectOption ] = useState('') const [selectOption, setselectOption] = useState(1)
// const [done, setDone] = useState(false)
const handleChangeQuestion = (event) => { const handleChangeQuestion = (event) => {
QnAadmin['Q'] = event.target.value
setQuestion(event.target.value) setQuestion(event.target.value)
} }
const handleChangechoose = (event) => { const handleChangeChoose = (event) => {
c[event.target.id] = event.target.value
// QnAadmin['Choose'] = event.target.value
setChoose(event.target.value) setChoose(event.target.value)
} }
const handleChangeanswer = (event) => { const handleChangeanswer = (event) => {
QnAadmin['A'] = event.target.value
setAnswer(event.target.value) setAnswer(event.target.value)
} }
function handleClick() {
// localStorage.setItem('N', number)
localStorage.setItem('Q', question)
localStorage.setItem('Choose', choose)
localStorage.setItem('Answer', answer)
// setDone(true)
alert('입력이 완료되었습니다')
}
function addSelectOption() { function addSelectOption() {
let list = function(){ list.push(
return <div className="input-group"> <div className="input-group">
<div className="input-group-prepend"> <div className="input-group-prepend">
<div className="input-group-text"> <div className="input-group-text">
<input type="radio" id="option" /> <input type="radio" name="answer" />
</div>
</div> </div>
<input type="text" class="form-control" id={String(selectOption + 1)} placeholder="보기를 입력하세요" onChange={handleChangeChoose} />
</div> </div>
<input type="text" class="form-control" placeholder="보기를 입력하세요" onChange={handleChangechoose} /> )
</div> setselectOption(selectOption + 1)
}
setselectOption(list)
} }
return (
<> function handleClick() {
{/* {done ? alert('모두 입력되었습니다.') : ''} */} if (!question) {
alert('문제가 입력되지 않았습니다.')
<div className="container-fluid"> }
<div className="row d-flex justify-content-center"> else if (!choose) {
<div className="col-8"> alert('보기가 입력되지 않았습니다.')
}
else if (!answer) {
alert('정답이 입력되지 않았습니다.')
}
else {
console.log(QnAadmin)
QnAadmin['Choose']=Object.values(c)
QnAadmins.push(QnAadmin)
localStorage.setItem('QnA', JSON.stringify(QnAadmins))
console.log(QnAadmins)
alert('입력이 완료되었습니다.')
}
<h2 className="p-3 border text-center">문제만들기</h2> }
<div className="p-3 borber"> // function handleChangeQuestion(){}
<div className="p-3 ">
<span className="font-weight-bold mr-2 h3">1.</span>
{/* <input type="text" onChange={handleChangenumber} placeholder="Number" /> */}
<input type="text" onChange={handleChangeQuestion} placeholder="문제를 입력하세요" />
</div>
<div className="p-3 "> return (
<div className="input-group"> <div className="" id="Quiz1">
<div className="input-group-prepend"> <h2 className="p-3 border text-center">문제만들기</h2>
<div className="input-group-text"> <div className="p-3 borber">
<input type="radio" id="option"/> <div className="p-3 ">
</div> <span className="font-weight-bold mr-2 h3">1.</span>
</div> <input type="text" className="form-control" onChange={handleChangeQuestion} placeholder="문제를 입력하세요" />
<input type="text" class="form-control" placeholder="보기를 입력하세요" onChange={handleChangechoose} /> </div>
</div> <div className="p-3 ">
{selectOption} <div className="input-group">
<div className="input-group-prepend">
<button className="btn btn-outline-secondary btn-sm" onClick={addSelectOption}>+</button> <div className="input-group-text">
<input type="radio" id={selectOption} name="answer" />
</div>
<div className="p-3 ">
<span className="font-weight-bold mr-2 h3">정답:</span>
<input type="text" onChange={handleChangeanswer} placeholder="정답을 입력하세요" />
</div> </div>
<label for="inputLogin" className="d-flex justify-content-center">
<button className="mt-4 btn btn-dark" onClick={handleClick}>작성완료</button>
</label>
</div> </div>
<input type="text" className="form-control" id='1' placeholder="보기를 입력하세요" onChange={handleChangeChoose} />
</div> </div>
{list.map((element) => element)}
<button className="btn btn-outline-secondary btn-sm" onClick={addSelectOption}>+</button>
</div>
<div className="p-3 ">
<span className="font-weight-bold mr-2 h3">정답:</span>
<input type="text" onChange={handleChangeanswer} placeholder="정답을 입력하세요" />
</div> </div>
<label for="inputLogin" className="d-flex justify-content-center">
<button className="mt-4 btn btn-dark" onClick={handleClick}>작성완료</button>
</label>
</div> </div>
</> </div>
) )
} }
export default Admin export default AdminQuiz
\ No newline at end of file
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