Commit 7fbe9b17 authored by baesangjune's avatar baesangjune
Browse files

ddd

parent dd0704fc
...@@ -5,7 +5,7 @@ import AdminSetting from './AdminSetting' ...@@ -5,7 +5,7 @@ import AdminSetting from './AdminSetting'
let QuizBtn = [] let QuizBtn = []
function Admin() { function Admin() {
// QnA.length === 0 ? console.log(QnA.length) : QnA = JSON.parse(localStorage.getItem('QnA'))
const [result, setresult] = useState('') const [result, setresult] = useState('')
const [QuizBtnCount, setQuizBtnCount] = useState(4) const [QuizBtnCount, setQuizBtnCount] = useState(4)
...@@ -14,7 +14,16 @@ function Admin() { ...@@ -14,7 +14,16 @@ function Admin() {
} }
function handleClickQuiz(e) { function handleClickQuiz(e) {
(JSON.parse(localStorage.getItem('QnA')) === null) ? setresult(<AdminQuiz QuizNum={e.target.id} data={[{ Q: 'x', Choose: 'x', A: 'x' }]} />) : setresult(<AdminQuiz QuizNum={e.target.id} data={JSON.parse(localStorage.getItem('QnA'))} />)
let QnA = JSON.parse(localStorage.getItem('QnA'))
if (QnA !== null) {
(QnA[e.target.id - 1] === undefined) ? setresult(<AdminQuiz QuizNum={e.target.id} data={{ Q: '문제를 입력하세요', Choose: '보기를 입력하세요', A: '정답을 입력하세요' }} />) : setresult(<AdminQuiz QuizNum={e.target.id} data={QnA[e.target.id - 1]} />)
}
else {
setresult(<AdminQuiz QuizNum={e.target.id} data={{ Q: '문제를 입력하세요', Choose: '보기를 입력하세요', A: '정답을 입력하세요' }} />)
}
} }
function handleClickAddQuiz() { function handleClickAddQuiz() {
......
import React, { useState} from 'react'; import React, { useState } from 'react';
let list = [] let list = []
...@@ -7,9 +7,15 @@ let QnAadmin = {} ...@@ -7,9 +7,15 @@ let QnAadmin = {}
let savechoose = {} let savechoose = {}
function AdminQuiz(props) { function AdminQuiz(props) {
const [question, setQuestion] = useState('') const [question, setQuestion] = useState(props.data.Q)
const [choose, setChoose] = useState('') // setQuestion(props.data.Q)
const [answer, setAnswer] = useState('') // question = props.data.Q
const [choose, setChoose] = useState(props.data.Choose)
// setChoose(props.data.Choose)
// choose = props.data.Choose
const [answer, setAnswer] = useState(props.data.A)
// setAnswer(props.data.A)
// answer = props.data.A
const [selectOption, setselectOption] = useState(1) const [selectOption, setselectOption] = useState(1)
const handleChangeQuestion = (event) => { const handleChangeQuestion = (event) => {
...@@ -33,7 +39,7 @@ function AdminQuiz(props) { ...@@ -33,7 +39,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={ props.data[props.QuizNum-1].Choose===null ? (selectOption+1)+'번 보기를 입력하세요' : props.data[props.QuizNum-1].Choose[selectOption]} onChange={handleChangeChoose} /> <input type="text" class="form-control" id={String(selectOption + 1)} value={choose[selectOption]} placeholder={(selectOption + 1) + '번 보기를 입력하세요'} onChange={handleChangeChoose} />
</div> </div>
) )
setselectOption(selectOption + 1) setselectOption(selectOption + 1)
...@@ -67,12 +73,13 @@ function AdminQuiz(props) { ...@@ -67,12 +73,13 @@ 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">{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>
<input type="text" id="inputQuiz" className="form-control" onChange={handleChangeQuestion} placeholder={ props.data[props.QuizNum-1].Q==='x' ? '문제를 입력하세요' : props.data[props.QuizNum-1].Q} /> <input type="text" id="inputQuiz" className="form-control" onChange={handleChangeQuestion} value={question} placeholder={'문제를 입력하세요'} ></input>
</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>
...@@ -83,7 +90,7 @@ function AdminQuiz(props) { ...@@ -83,7 +90,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={ props.data[props.QuizNum-1].Choose==='x' ? '1번 보기를 입력하세요' : props.data[props.QuizNum-1].Choose[0]} onChange={handleChangeChoose} /> <input type="text" className="form-control" id='1' value={choose} placeholder={'1번 보기를 입력하세요'} 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>
...@@ -92,7 +99,7 @@ function AdminQuiz(props) { ...@@ -92,7 +99,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={ props.data[props.QuizNum-1].A==='x' ? '정답를 입력하세요' : props.data[props.QuizNum-1].A} /> <input type="text" onChange={handleChangeanswer} value={answer} placeholder={'정답를 입력하세요'} />
</div> </div>
<label for="inputLogin" className="d-flex justify-content-center"> <label for="inputLogin" className="d-flex justify-content-center">
...@@ -100,6 +107,7 @@ function AdminQuiz(props) { ...@@ -100,6 +107,7 @@ function AdminQuiz(props) {
</label> </label>
</div> </div>
</div> </div>
</>
) )
} }
......
...@@ -4,11 +4,11 @@ import React, { useState } from 'react' ...@@ -4,11 +4,11 @@ import React, { useState } from 'react'
import { Redirect } from 'react-router-dom'; import { Redirect } from 'react-router-dom';
function Home() { function Home() {
let info = []
let info=[{password:"0319", AdminPassword:"0001",Time : "30010"}] //수정.추가 if (JSON.parse(localStorage.getItem("Set")) === null) {
if(JSON.parse(localStorage.getItem("Set")) === null){ info = [{ password: "0319", AdminPassword: "0001", Time: "30010" }]
} }
else{ else {
info = JSON.parse(localStorage.getItem("Set")) info = JSON.parse(localStorage.getItem("Set"))
} //수정. 추가 } //수정. 추가
...@@ -32,14 +32,14 @@ function Home() { ...@@ -32,14 +32,14 @@ function Home() {
else if (!password) { else if (!password) {
alert('비밀번호를 입력하세요') alert('비밀번호를 입력하세요')
} }
else if (name === 'admin' && password === '0001') { else if (name === 'admin' && password === info[0].AdminPassword) {
console.log('done') console.log('done')
return (setAdmin(true) return (setAdmin(true)
) )
} }
else if (password !== '0319') { else if (password !== info[0].password) {
alert('유효한 비밀번호를 입력하세요') alert('유효한 비밀번호를 입력하세요')
} }
else { else {
...@@ -60,7 +60,7 @@ function Home() { ...@@ -60,7 +60,7 @@ function Home() {
{done ? <Redirect to='/quiz' /> : ''} {done ? <Redirect to='/quiz' /> : ''}
<div> <div>
<h3 className="text-center pb-5 font-weight-bold text-danger" style={{'font-family':'sans-serif'}}>Korea University</h3> <h3 className="text-center pb-5 font-weight-bold text-danger" style={{ 'font-family': 'sans-serif' }}>Korea University</h3>
</div> </div>
<div className="row justify-content-center"> <div className="row justify-content-center">
......
...@@ -6,11 +6,19 @@ import logo from './img_question.png' ...@@ -6,11 +6,19 @@ import logo from './img_question.png'
let localQnA = JSON.parse(localStorage.getItem('QnA')) let localQnA = JSON.parse(localStorage.getItem('QnA'))
let Answers = [] let Answers = []
function Quiz() { function Quiz() {
let Time=0
if (JSON.parse(localStorage.getItem("Set"))===null){
Time=30010
}
else{
Time=Number(JSON.parse(localStorage.getItem("Set"))[0].Time)
}
const [question, setQuestion] = useState({ const [question, setQuestion] = useState({
...localQnA[0] ...localQnA[0]
}) })
...@@ -57,7 +65,7 @@ function Quiz() { ...@@ -57,7 +65,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">
{localQnA[0].Q} {question.Q}
</div> </div>
<div className="mt-2"> <div className="mt-2">
<form> <form>
...@@ -79,7 +87,7 @@ function Quiz() { ...@@ -79,7 +87,7 @@ function Quiz() {
</div> </div>
<p className="h3 text-center text-danger "> <p className="h3 text-center text-danger ">
<Timer <Timer
initialTime={3000} initialTime={Time}
direction="backward" direction="backward"
checkpoints={[ checkpoints={[
{ {
......
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import 'react-dom' import 'react-dom'
import './index.css';
import App from './App'; import App from './App';
// import Quiz from './Quiz'; // import Quiz from './Quiz';
import * as serviceWorker from './serviceWorker'; import * as serviceWorker from './serviceWorker';
......
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