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

admin to local

parent 4f8ca417
import React, { useState } from 'react';
import AdminQuiz from './AdminQuiz'
import AdminSetting from './AdminSetting'
let QnAadmins = []
let QnAadmin = {}
// let QnAadmins = []
// let QnAadmin = {}
let Setadmins = []
let Setadmin = {}
// let Setadmins = []
// let Setadmin = {}
let QuizBtn=[]
function Admin() {
const [question, setQuestion] = useState('')
const [choose, setChoose] = useState('')
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)
const[result, setresult] = useState('')
const[QuizBtnCount, setQuizBtnCount] = useState(4)
function handleClickSetting(){
setresult(<AdminSetting/>)
}
const handleChangePassword = (event) => {
Setadmin['password'] = event.target.value
setPassword(event.target.value)
}
const handleChangeAdminPassword = (event) => {
Setadmin['AdminPassword'] = event.target.value
setAdminPassword(event.target.value)
}
const handleChangeTime = (event) => {
Setadmin['Time'] = event.target.value
setTime(event.target.value)
function handleClickQuiz(){
setresult(<AdminQuiz/>)
}
function handleClickQnA() {
if (!question) {
alert('문제가 입력되지 않았습니다.')
}
else if (!choose) {
alert('보기가 입력되지 않았습니다.')
}
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)
}
function handleClickAddQuiz(){
QuizBtn.push(
<button type='button' className='btn btn-outline-primary' id={QuizBtnCount} onClick={handleClickQuiz}>Quiz {QuizBtnCount}</button>
)
setQuizBtnCount(QuizBtnCount+1)
}
// const [question, setQuestion] = useState('')
// const [choose, setChoose] = useState('')
// 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)
// }
// const handleChangePassword = (event) => {
// Setadmin['password'] = event.target.value
// setPassword(event.target.value)
// }
// const handleChangeAdminPassword = (event) => {
// Setadmin['AdminPassword'] = event.target.value
// setAdminPassword(event.target.value)
// }
// const handleChangeTime = (event) => {
// Setadmin['Time'] = event.target.value
// setTime(event.target.value)
// }
// function handleClickQnA() {
// if (!question) {
// alert('문제가 입력되지 않았습니다.')
// }
// else if (!choose) {
// alert('보기가 입력되지 않았습니다.')
// }
// 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 (
<>
{/* {doneQnA ? alert('모두 입력되었습니다.') : ''}
{doneset ? alert('모두 입력되었습니다.') : ''} */}
<div className="container-fluid">
<div className="row justify-content-md-center mt-5 ">
<div className="col-2 text-center border">
<div className="container-fluid ">
<div className="navbar-header p-3 ">
<p className="navbar-brand border-bottom ">관리자 페이지</p>
<div className="my-5">
<h4>관리자페이지</h4>
</div>
<div className="nav flex-column nav-pills" id="v-pills-tab" role="tablist">
<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>
<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>
</div>
</div>
<div className="col-8">
<div className="tab-content" id="v-pills-tabContent">
<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="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 className="tab-pane fade" id="Quiz" role="tabpanel">
<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="문제를 입력하세요" />
{result}
</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>
<input type="text" className="form-control p-4" placeholder="보기를 입력하세요" onChange={handleChangechoose} />
</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 { Container } from 'react-bootstrap';
// import { Link } from 'react-router-dom';
import React,{ useState } from 'react'
function AdminSetting() {
let Setadmins = []
let Setadmin = {}
// let QnAadmin = []
// let Q = []
// let choose = []
// let N = []
function AdminSetting() {
const [password, setPassword] = useState('')
const [adminpassword, setAdminPassword] = useState('')
const [time, setTime] = useState('')
const [done, setDone] = useState(false)
const handleChangePassword = (event) => {
Setadmin['password'] = event.target.value
setPassword(event.target.value)
}
const handleChangeAdminPassword = (event) => {
Setadmin['AdminPassword'] = event.target.value
setAdminPassword(event.target.value)
}
const handleChangeTime = (event) => {
Setadmin['Time'] = event.target.value
setTime(event.target.value)
}
function handleClick() {
if (!password) {
alert('비밀번호 입력하세요')
alert('비밀번호 입력되지 않았습니다.')
}
else if (!adminpassword) {
alert('관리자 비밀번호 입력하세요')
alert('관리자 비밀번호 입력되지 않았습니다.')
}
else if (!time) {
alert('타이머를 설정해주세요')
alert('제한시간이 입력되지 않았습니다.') //타임은 조건은 빼도 될 듯
}
else {
alert('입력이 완료되었습니다')
localStorage.setItem('P', password)
localStorage.setItem('AP', adminpassword)
localStorage.setItem('T', time*1000)
setDone(true)
}
Setadmins.push(Setadmin)
localStorage.setItem('Set', JSON.stringify(Setadmins))
console.log(Setadmins)
alert('저장이 완료되었습니다.')
console.log(Setadmin)
// setDoneset(true)
}
}
return (
<>
{done ? alert('모두 입력되었습니다.') : ''}
<div>
<div className="container">
<div className="row d-flex justify-content-center">
<div className="col-8">
<h1 className="p-3 border">관리자 설정 변경 </h1>
<div className="p-3 border">
<h2>변경할 비밀번호를 입력하세요</h2>
......@@ -70,23 +65,12 @@ function AdminSetting() {
<input 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={handleClick}>작성완료</button>
</label>
</div>
</div>
</div>
{/* <div className="p-3 border">
<h2>패스워드를 입력하세요</h2>
<input type="text" onChange={handleChangeanswer} placeholder="Answer" />
</div> */}
</div>
</>
)
}
}
export default AdminSetting
\ No newline at end of file
export default AdminSetting
\ No newline at end of file
import React, { useState } from 'react'
import { Link, Redirect } from 'react-router-dom';
import Timer from 'react-compound-timer'; // 타이머쓰기위해 import
import logo from './img/img_question.png'
import logo from './img_question.png'
const QnA = [
{ Q: "6 X 4 = ?", Choose: [6, 12, 18, 24], N: 1 },
......@@ -9,7 +9,31 @@ const QnA = [
{ 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))
let Solutions = [4, 3, 2]
localStorage.setItem('Solutions', JSON.stringify(Solutions))
......@@ -22,8 +46,24 @@ function Quiz() {
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() {
setQuestion({ ...QnA[question.N]})
setQuestion({ ...QnA[question.N] })
setSelected("") //페이지 넘어가면 selected 초기화
}
......@@ -44,7 +84,7 @@ function Quiz() {
</div>
<div className="col-md-auto">
<div className="h2 mt-2">
{question.Q}
{question.Q} {b[0].Q}
</div>
<div className="mt-2">
<form>
......@@ -57,7 +97,7 @@ function Quiz() {
</form>
<span className="h5 font-weight-bold"> Your Answer :</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">
<button className="btn btn-outline-success" onClick={localStorage.setItem('Solutions', JSON.stringify(Solutions))}>제출</button>
</Link>
......@@ -66,11 +106,12 @@ function Quiz() {
</div>
<p className="h3 text-center text-danger ">
<Timer
initialTime={30010}
initialTime={3001000}
direction="backward"
checkpoints={[
{time:1,
callback:()=>alert('시간이 초과되었습니다.'),
{
time: 1,
callback: () => alert('시간이 초과되었습니다.'),
},
{
time: 0,
......@@ -91,7 +132,7 @@ function Quiz() {
</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