Commit 909b2687 authored by JeongYeonwoo's avatar JeongYeonwoo
Browse files

admin to local

parent 4f8ca417
import React, { useState } from 'react'; import React, { useState } from 'react';
import AdminQuiz from './AdminQuiz'
import AdminSetting from './AdminSetting'
let QnAadmins = [] // let QnAadmins = []
let QnAadmin = {} // let QnAadmin = {}
let Setadmins = [] // let Setadmins = []
let Setadmin = {} // let Setadmin = {}
let QuizBtn=[]
function Admin() { function Admin() {
const [question, setQuestion] = useState('') const[result, setresult] = useState('')
const [choose, setChoose] = useState('') const[QuizBtnCount, setQuizBtnCount] = useState(4)
const [answer, setAnswer] = useState('')
const [password, setPassword] = useState('')
const [adminpassword, setAdminPassword] = useState('')
const [time, setTime] = useState('')
const [addQuiz, setaddQuiz] = useState('')
const [selectOption, setselectOption] = useState('')
const handleChangeQuestion = (event) => {
QnAadmin['Q'] = event.target.value
setQuestion(event.target.value)
}
const handleChangechoose = (event) => {
QnAadmin['Choose'] = event.target.value
setChoose(event.target.value)
}
const handleChangeanswer = (event) => {
QnAadmin['A'] = event.target.value
setAnswer(event.target.value)
function handleClickSetting(){
setresult(<AdminSetting/>)
} }
const handleChangePassword = (event) => {
Setadmin['password'] = event.target.value
setPassword(event.target.value)
} function handleClickQuiz(){
const handleChangeAdminPassword = (event) => { setresult(<AdminQuiz/>)
Setadmin['AdminPassword'] = event.target.value
setAdminPassword(event.target.value)
}
const handleChangeTime = (event) => {
Setadmin['Time'] = event.target.value
setTime(event.target.value)
} }
function handleClickAddQuiz(){
function handleClickQnA() { QuizBtn.push(
if (!question) { <button type='button' className='btn btn-outline-primary' id={QuizBtnCount} onClick={handleClickQuiz}>Quiz {QuizBtnCount}</button>
alert('문제가 입력되지 않았습니다.') )
} setQuizBtnCount(QuizBtnCount+1)
else if (!choose) { }
alert('보기가 입력되지 않았습니다.')
}
else if (!answer) { // const [question, setQuestion] = useState('')
alert('정답이 입력되지 않았습니다.') // const [choose, setChoose] = useState('')
} // const [answer, setAnswer] = useState('')
else { // const [password, setPassword] = useState('')
console.log(QnAadmin) // const [adminpassword, setAdminPassword] = useState('')
QnAadmins.push(QnAadmin) // const [time, setTime] = useState('')
localStorage.setItem('QnA', JSON.stringify(QnAadmins)) // const [addQuiz, setaddQuiz] = useState('')
console.log(QnAadmins) // const [selectOption, setselectOption] = useState('')
alert('입력이 완료되었습니다.')
}
// const handleChangeQuestion = (event) => {
}
function handleClicksetting() { // QnAadmin['Q'] = event.target.value
if (!password) {
alert('비밀번호가 입력되지 않았습니다.') // setQuestion(event.target.value)
} // }
else if (!adminpassword) { // const handleChangechoose = (event) => {
alert('관리자 비밀번호가 입력되지 않았습니다.')
} // QnAadmin['Choose'] = event.target.value
else if (!time) {
alert('제한시간이 입력되지 않았습니다.') //타임은 조건은 빼도 될 듯 // setChoose(event.target.value)
} // }
else { // const handleChangeanswer = (event) => {
Setadmins.push(Setadmin)
localStorage.setItem('Set', JSON.stringify(Setadmins)) // QnAadmin['A'] = event.target.value
console.log(Setadmins)
alert('저장이 완료되었습니다.') // setAnswer(event.target.value)
console.log(Setadmin) // }
// const handleChangePassword = (event) => {
// setDoneset(true) // Setadmin['password'] = event.target.value
} // setPassword(event.target.value)
} // }
function addSelectOption() { // const handleChangeAdminPassword = (event) => {
let list = function () { // Setadmin['AdminPassword'] = event.target.value
return <div className="input-group"> // setAdminPassword(event.target.value)
<div className="input-group-prepend"> // }
<div className="input-group-text"> // const handleChangeTime = (event) => {
<input type="radio" id="option" /> // Setadmin['Time'] = event.target.value
</div> // setTime(event.target.value)
</div> // }
<input type="text" className="form-control" placeholder="보기를 입력하세요" onChange={handleChangechoose} />
</div>
} // function handleClickQnA() {
setselectOption(list) // if (!question) {
} // alert('문제가 입력되지 않았습니다.')
function handleClickQuiz() { // }
let addQuiz = function () { // else if (!choose) {
return <a className="nav-link" id="Quiz4-tab" data-toggle="pill" href="#Quiz" role="tab" >Quiz4</a> // alert('보기가 입력되지 않았습니다.')
} // }
setaddQuiz(addQuiz) // else if (!answer) {
} // alert('정답이 입력되지 않았습니다.')
// }
// else {
// console.log(QnAadmin)
// QnAadmins.push(QnAadmin)
// localStorage.setItem('QnA', JSON.stringify(QnAadmins))
// console.log(QnAadmins)
// alert('입력이 완료되었습니다.')
// }
// }
// function handleClicksetting() {
// if (!password) {
// alert('비밀번호가 입력되지 않았습니다.')
// }
// else if (!adminpassword) {
// alert('관리자 비밀번호가 입력되지 않았습니다.')
// }
// else if (!time) {
// alert('제한시간이 입력되지 않았습니다.') //타임은 조건은 빼도 될 듯
// }
// else {
// Setadmins.push(Setadmin)
// localStorage.setItem('Set', JSON.stringify(Setadmins))
// console.log(Setadmins)
// alert('저장이 완료되었습니다.')
// console.log(Setadmin)
// // setDoneset(true)
// }
// }
// function addSelectOption() {
// let list = function () {
// return <div className="input-group">
// <div className="input-group-prepend">
// <div className="input-group-text">
// <input type="radio" id="option" />
// </div>
// </div>
// <input type="text" className="form-control" placeholder="보기를 입력하세요" onChange={handleChangechoose} />
// </div>
// }
// setselectOption(list)
// // }
// function handleClickQuiz() {
// let addQuiz = function () {
// return <a className="nav-link" id="Quiz4-tab" data-toggle="pill" href="#Quiz" role="tab" >Quiz4</a>
// }
// setaddQuiz(addQuiz)
// }
return ( return (
<> <>
{/* {doneQnA ? alert('모두 입력되었습니다.') : ''} <div className="container-fluid">
{doneset ? alert('모두 입력되었습니다.') : ''} */}
<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"> <div className="col-2 text-center border">
<div className="container-fluid "> <div className="my-5">
<div className="navbar-header p-3 "> <h4>관리자페이지</h4>
<p className="navbar-brand border-bottom ">관리자 페이지</p>
</div> </div>
<div className="nav flex-column nav-pills" id="v-pills-tab" role="tablist"> <div>
<button type="button" className="btn btn-outline-info mb-5" onClick={handleClickSetting}>Setting</button>
<p className="navbar-text border-bottom">관리자 설정 변경하기</p>
<a className="nav-link" id="setting-tab" data-toggle='pill' href="#setting">Setting</a>
<p className="navbar-text border-bottom">Quiz 입력하기</p> {/*Quiz1 버튼에 무언갈 쓰고 Quiz2를 누르면 초기화되도록하기*/}
<a className="nav-link" id="Quiz-tab" data-toggle="pill" href="#Quiz" >Quiz1</a>
<a className="nav-link" id="Quiz-tab" data-toggle="pill" href="#Quiz" >Quiz2</a>
<a className="nav-link" id="Quiz-tab" data-toggle="pill" href="#Quiz" >Quiz3</a>
{addQuiz}
<button className="btn btn-danger navbar-btn" onClick={handleClickQuiz} >Quiz 추가</button>
</div> </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> </div>
</div> </div>
<div className="col-8"> <div className="col-8">
<div className="tab-content" id="v-pills-tabContent"> <div className="tab-content" id="v-pills-tabContent">
<div className="tab-pane fade show active" id="setting" role="tabpanel" > <div className="tab-pane fade show active" id="setting" role="tabpanel" >
<div>
<div className="container">
<div className="row d-flex justify-content-center"> <div className="row d-flex justify-content-center">
<div className="col-8">
<h2 className="p-3 border text-center bg-danger">관리자 설정변경</h2>
<div className="p-3 border">
<h3>변경할 비밀번호를 입력하세요</h3>
<input className='p-2' type="text" onChange={handleChangePassword} placeholder="New Password" />
</div>
<div className="p-3 border">
<h3>변경할 관리자 비밀번호를 입력하세요</h3>
<input className='p-2' type="text" onChange={handleChangeAdminPassword} placeholder="New Admin Password" />
</div>
<div className="p-3 border">
<h3>타이머를 설정하세요(초단위)</h3>
<input className='p-2' type="text" onChange={handleChangeTime} placeholder="Set Time" />
</div>
<label for="inputLogin" className="d-flex justify-content-center">
<button className="mt-4 btn btn-dark" onClick={handleClicksetting}>작성완료</button>
</label>
</div>
</div>
</div>
</div> </div>
</div> </div>
<div className="tab-pane fade" id="Quiz" role="tabpanel"> {result}
<div className="container">
<div className="row d-flex justify-content-center">
<div className="col-8">
<h2 className="p-3 border text-center bg-danger">문제만들기</h2>
<div className="p-3 borber">
<div className="p-3 ">
<span className="font-weight-bold mr-2 h3">1.</span>
{/* <input type="text" onChange={handleChangenumber} placeholder="Number" /> */}
<input className='p-2' type="text" onChange={handleChangeQuestion} placeholder="문제를 입력하세요" />
</div> </div>
<div className="p-3 ">
<div className="input-group">
<div className="input-group-prepend">
<div className="input-group-text p-3">
<input type="radio" id="option" />
</div> </div>
</div> </div>
<input type="text" className="form-control p-4" placeholder="보기를 입력하세요" onChange={handleChangechoose} />
</div> </div>
{selectOption}
<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 className='p-2' type="text" onChange={handleChangeanswer} placeholder="정답을 입력하세요" />
</div>
<label for="inputLogin" className="d-flex justify-content-center">
<button className="mt-4 btn btn-dark" onClick={handleClickQnA}>작성완료</button>
</label>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</> </>
) )
......
import React, { useState } from 'react';
let list = []
let QnAadmins = []
let QnAadmin = {}
function AdminQuiz() {
const [question, setQuestion] = useState('')
const [choose, setChoose] = useState('')
const [answer, setAnswer] = useState('')
const [selectOption, setselectOption] = useState(1)
const handleChangeQuestion = (event) => {
QnAadmin['Q'] = event.target.value
setQuestion(event.target.value)
}
const handleChangeChoose = (event) => {
QnAadmin['Choose'] = event.target.value
setChoose(event.target.value)
}
const handleChangeanswer = (event) => {
QnAadmin['A'] = event.target.value
setAnswer(event.target.value)
}
function addSelectOption() {
list.push(
<div className="input-group">
<div className="input-group-prepend">
<div className="input-group-text">
<input type="radio" id={selectOption + 1} name="answer" />
</div>
</div>
<input type="text" class="form-control" placeholder="보기를 입력하세요" onChange={handleChangeChoose} />
</div>
)
setselectOption(selectOption + 1)
}
function handleClick() {
if (!question) {
alert('문제가 입력되지 않았습니다.')
}
else if (!choose) {
alert('보기가 입력되지 않았습니다.')
}
else if (!answer) {
alert('정답이 입력되지 않았습니다.')
}
else {
console.log(QnAadmin)
QnAadmins.push(QnAadmin)
QnAadmin={}
localStorage.setItem('QnA', JSON.stringify(QnAadmins))
console.log(QnAadmins)
alert('입력이 완료되었습니다.')
}
}
// function handleChangeQuestion(){}
return (
<div className="" id="Quiz1">
<h2 className="p-3 border text-center">문제만들기</h2>
<div className="p-3 borber">
<div className="p-3 ">
<span className="font-weight-bold mr-2 h3">1.</span>
<input type="text" className="form-control" onChange={handleChangeQuestion} placeholder="문제를 입력하세요" />
</div>
<div className="p-3 ">
<div className="input-group">
<div className="input-group-prepend">
<div className="input-group-text">
<input type="radio" id={selectOption} name="answer" />
</div>
</div>
<input type="text" className="form-control" placeholder="보기를 입력하세요" onChange={handleChangeChoose} />
</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>
<label for="inputLogin" className="d-flex justify-content-center">
<button className="mt-4 btn btn-dark" onClick={handleClick}>작성완료</button>
</label>
</div>
</div>
)
}
export default AdminQuiz
import React, { useState } from 'react'; import React,{ useState } from 'react'
import { Container } from 'react-bootstrap';
// import { Link } from 'react-router-dom';
function AdminSetting() {
let Setadmins = []
let Setadmin = {}
// let QnAadmin = [] function AdminSetting() {
// let Q = []
// let choose = []
// let N = []
const [password, setPassword] = useState('') const [password, setPassword] = useState('')
const [adminpassword, setAdminPassword] = useState('') const [adminpassword, setAdminPassword] = useState('')
const [time, setTime] = useState('') const [time, setTime] = useState('')
const [done, setDone] = useState(false)
const handleChangePassword = (event) => { const handleChangePassword = (event) => {
Setadmin['password'] = event.target.value
setPassword(event.target.value) setPassword(event.target.value)
} }
const handleChangeAdminPassword = (event) => { const handleChangeAdminPassword = (event) => {
Setadmin['AdminPassword'] = event.target.value
setAdminPassword(event.target.value) setAdminPassword(event.target.value)
} }
const handleChangeTime = (event) => { const handleChangeTime = (event) => {
Setadmin['Time'] = event.target.value
setTime(event.target.value) setTime(event.target.value)
} }
function handleClick() { function handleClick() {
if (!password) { if (!password) {
alert('비밀번호 입력하세요') alert('비밀번호 입력되지 않았습니다.')
} }
else if (!adminpassword) { else if (!adminpassword) {
alert('관리자 비밀번호 입력하세요') alert('관리자 비밀번호 입력되지 않았습니다.')
} }
else if (!time) { else if (!time) {
alert('타이머를 설정해주세요') alert('제한시간이 입력되지 않았습니다.') //타임은 조건은 빼도 될 듯
} }
else { else {
alert('입력이 완료되었습니다') Setadmins.push(Setadmin)
localStorage.setItem('P', password) localStorage.setItem('Set', JSON.stringify(Setadmins))
localStorage.setItem('AP', adminpassword) console.log(Setadmins)
localStorage.setItem('T', time*1000) alert('저장이 완료되었습니다.')
setDone(true) console.log(Setadmin)
}
// setDoneset(true)
} }
}
return ( return (
<>
{done ? alert('모두 입력되었습니다.') : ''}
<div>
<div className="container">
<div className="row d-flex justify-content-center">
<div className="col-8"> <div className="col-8">
<h1 className="p-3 border">관리자 설정 변경 </h1> <h1 className="p-3 border">관리자 설정 변경 </h1>
<div className="p-3 border"> <div className="p-3 border">
<h2>변경할 비밀번호를 입력하세요</h2> <h2>변경할 비밀번호를 입력하세요</h2>
...@@ -70,23 +65,12 @@ function AdminSetting() { ...@@ -70,23 +65,12 @@ function AdminSetting() {
<input type="text" onChange={handleChangeTime} placeholder="Set Time" /> <input type="text" onChange={handleChangeTime} placeholder="Set Time" />
</div> </div>
<label for="inputLogin" className="d-flex justify-content-center"> <label for="inputLogin" className="d-flex justify-content-center">
<button className="mt-4 btn btn-dark" onClick={handleClick}>작성완료</button> <button className="mt-4 btn btn-dark" onClick={handleClick}>작성완료</button>
</label> </label>
</div>
</div> </div>
</div>
{/* <div className="p-3 border">
<h2>패스워드를 입력하세요</h2>
<input type="text" onChange={handleChangeanswer} placeholder="Answer" />
</div> */}
</div>
</>
) )
} }
export default AdminSetting export default AdminSetting
\ No newline at end of file \ No newline at end of file
import React, { useState } from 'react' import React, { useState } from 'react'
import { Link, Redirect } from 'react-router-dom'; import { Link, Redirect } from 'react-router-dom';
import Timer from 'react-compound-timer'; // 타이머쓰기위해 import import Timer from 'react-compound-timer'; // 타이머쓰기위해 import
import logo from './img/img_question.png' import logo from './img_question.png'
const QnA = [ const QnA = [
{ Q: "6 X 4 = ?", Choose: [6, 12, 18, 24], N: 1 }, { Q: "6 X 4 = ?", Choose: [6, 12, 18, 24], N: 1 },
...@@ -9,7 +9,31 @@ const QnA = [ ...@@ -9,7 +9,31 @@ const QnA = [
{ Q: "3 - 1 = ?", Choose: [1, 2, 3, 4], N: 3 } { Q: "3 - 1 = ?", Choose: [1, 2, 3, 4], N: 3 }
] ]
let Answers = [0,0,0] let a = localStorage.getItem('QnA')
let b = JSON.parse(a)
// let q=[]
// let p =b.map((x)=>{
// q.push(x.A)
// })
// localStorage.setItem("userAnswer",JSON.stringify(q))
// let c = b.map((x,index) =>{
// delete x.A
// return {...x , N : index+1}
// })
// const [z, setz] = useState({
// ...c[0]
// })
let Answers = [0, 0, 0]
localStorage.setItem('Answers', JSON.stringify(Answers)) localStorage.setItem('Answers', JSON.stringify(Answers))
let Solutions = [4, 3, 2] let Solutions = [4, 3, 2]
localStorage.setItem('Solutions', JSON.stringify(Solutions)) localStorage.setItem('Solutions', JSON.stringify(Solutions))
...@@ -22,8 +46,24 @@ function Quiz() { ...@@ -22,8 +46,24 @@ function Quiz() {
const [timeout, settimeout] = useState(false) const [timeout, settimeout] = useState(false)
let q = [] //빈 배열
console.log(b)
b.map((x) => { //A만 꺼내서 q에 추가
q.push(x.A)
})
console.log(q, b)
localStorage.setItem("userAnswer", JSON.stringify(q)) //그걸 로컬에 저장
let c = b.map((x, index) => {
//delete x.A //A 삭제
return { ...x, N: index + 1 } //N 추가
})
console.log(c)
function handleQuestion() { function handleQuestion() {
setQuestion({ ...QnA[question.N]}) setQuestion({ ...QnA[question.N] })
setSelected("") //페이지 넘어가면 selected 초기화 setSelected("") //페이지 넘어가면 selected 초기화
} }
...@@ -44,7 +84,7 @@ function Quiz() { ...@@ -44,7 +84,7 @@ function Quiz() {
</div> </div>
<div className="col-md-auto"> <div className="col-md-auto">
<div className="h2 mt-2"> <div className="h2 mt-2">
{question.Q} {question.Q} {b[0].Q}
</div> </div>
<div className="mt-2"> <div className="mt-2">
<form> <form>
...@@ -57,7 +97,7 @@ function Quiz() { ...@@ -57,7 +97,7 @@ function Quiz() {
</form> </form>
<span className="h5 font-weight-bold"> Your Answer :</span> <span className="h5 font-weight-bold"> Your Answer :</span>
<span className="h2 font-weight-bold text-danger"> {selected}</span> {/* 선택한 보여줌 */} <span className="h2 font-weight-bold text-danger"> {selected}</span> {/* 선택한 보여줌 */}
<div className="text-center my-3"> {(question.N-1 === QnA.length - 1) <div className="text-center my-3"> {(question.N - 1 === QnA.length - 1)
? <Link to="/end"> ? <Link to="/end">
<button className="btn btn-outline-success" onClick={localStorage.setItem('Solutions', JSON.stringify(Solutions))}>제출</button> <button className="btn btn-outline-success" onClick={localStorage.setItem('Solutions', JSON.stringify(Solutions))}>제출</button>
</Link> </Link>
...@@ -66,11 +106,12 @@ function Quiz() { ...@@ -66,11 +106,12 @@ function Quiz() {
</div> </div>
<p className="h3 text-center text-danger "> <p className="h3 text-center text-danger ">
<Timer <Timer
initialTime={30010} initialTime={3001000}
direction="backward" direction="backward"
checkpoints={[ checkpoints={[
{time:1, {
callback:()=>alert('시간이 초과되었습니다.'), time: 1,
callback: () => alert('시간이 초과되었습니다.'),
}, },
{ {
time: 0, time: 0,
...@@ -91,7 +132,7 @@ function Quiz() { ...@@ -91,7 +132,7 @@ function Quiz() {
</div> </div>
</div> </div>
</div> </div>
{timeout ? <Redirect to='/end'/> : '' } {timeout ? <Redirect to='/end' /> : ''}
</> </>
) )
......
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