Commit 4f8ca417 authored by JeongYeonwoo's avatar JeongYeonwoo
Browse files

quiz

parent 1be55b6e
import React, { useState } from 'react';
let QnAadmins = []
let QnAadmin = {}
let Setadmins = []
let Setadmin = {}
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 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="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>
<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>
</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="문제를 입력하세요" />
</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>
</>
)
}
export default Admin
\ No newline at end of file
import React, { useState } from 'react';
// import { Link } from 'react-router-dom';
function Admin() {
// let QnAadmin = []
// let Q = []
// let choose = []
// let N = []
const [number, setNumber] = useState('')
const [question, setQuestion] = useState('')
const [choose, setChoose] = useState('')
const [answer, setAnswer] = useState('')
const [done, setDone] = useState(false)
const handleChangenumber = (event) => {
setNumber(event.target.value)
}
const handleChangequestion = (event) => {
setQuestion(event.target.value)
}
const handleChangechoose = (event) => {
setChoose(event.target.value)
}
const handleChangeanswer = (event) => {
setAnswer(event.target.value)
}
function handleClick() {
alert('입력이 완료되었습니다')
localStorage.setItem('N', number)
localStorage.setItem('Q', question)
localStorage.setItem('Choose', choose)
localStorage.setItem('Answer',answer)
setDone(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>
<input type="text" onChange={handleChangenumber} placeholder="Number" />
</div>
<div className="p-3 border">
<h2>문제를 입력하세요</h2>
<input type="text" onChange={handleChangequestion} placeholder="Question" />
</div>
<div className="p-3 border">
<h2>보기를 입력하세요(배열형태)</h2>
<input type="text" onChange={handleChangechoose} placeholder="Choose" />
</div>
<div className="p-3 border">
<h2>답을 입력하세요</h2>
<input type="text" onChange={handleChangeanswer} placeholder="Answer" />
</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 Admin
\ No newline at end of file
import React, { useState } from 'react';
import { Container } from 'react-bootstrap';
// import { Link } from 'react-router-dom';
function AdminSetting() {
// let QnAadmin = []
// let Q = []
// let choose = []
// let N = []
const [password, setPassword] = useState('')
const [adminpassword, setAdminPassword] = useState('')
const [time, setTime] = useState('')
const [done, setDone] = useState(false)
const handleChangePassword = (event) => {
setPassword(event.target.value)
}
const handleChangeAdminPassword = (event) => {
setAdminPassword(event.target.value)
}
const handleChangeTime = (event) => {
setTime(event.target.value)
}
function handleClick() {
if (!password) {
alert('비밀번호를 입력하세요')
}
else if (!adminpassword) {
alert('관리자 비밀번호를 입력하세요')
}
else if (!time) {
alert('타이머를 설정해주세요')
}
else {
alert('입력이 완료되었습니다')
localStorage.setItem('P', password)
localStorage.setItem('AP', adminpassword)
localStorage.setItem('T', time*1000)
setDone(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>
<input type="text" onChange={handleChangePassword} placeholder="New Password" />
</div>
<div className="p-3 border">
<h2>변경할 관리자 비밀번호를 입력하세요</h2>
<input type="text" onChange={handleChangeAdminPassword} placeholder="New Admin Password" />
</div>
<div className="p-3 border">
<h2>타이머를 설정하세요(초단위)</h2>
<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
...@@ -3,29 +3,30 @@ import './App.css'; ...@@ -3,29 +3,30 @@ import './App.css';
import Home from './Home' import Home from './Home'
import Quiz from './Quiz' import Quiz from './Quiz'
import End from './End' import End from './End'
import Admin from './Admin'
import { BrowserRouter as Router, Link, Switch, Route } from 'react-router-dom'; import { BrowserRouter as Router, Link, Switch, Route, Redirect } from 'react-router-dom';
function App() { function App() {
return ( return (
<Router> <Router>
<header> <header>
<Link to="/"> <Link to="/">
<button className="calcButton">Calculus</button> <button>Calculus</button>
</Link> </Link>
</header> </header>
<hr /> <hr />
<div> <div>
<Switch> <Switch>
<Route exact path="/"> <Route exact path="/" component={Home} />
<Home />
</Route> <Route path="/quiz" component={Quiz} />
<Route path="/quiz">
<Quiz /> <Route path="/end" component={End} />
</Route>
<Route path="/end"> <Route path="/admin" component={Admin} />
<End />
</Route> <Redirect path="/admin" to="/admin" />
</Switch> </Switch>
</div> </div>
</Router> </Router>
......
import React from 'react';
import './App.css';
function App() {
return (
<div>
<header>
<Link to="/">
<button>Calculus</button>
</Link>
</header>
<hr />
</div>
)
}
export default App;
\ No newline at end of file
import React from 'react' import React from 'react'
import './End.css' // import tr from './img_end.jpg';
import tr from './img/img_end.jpg';
// import { Link } from 'react-router-dom'; // import { Link } from 'react-router-dom';
function End() { function End() {
let result = ''
let scores = [] let scores = []
let score = 0 let score = 0
const answers = JSON.parse(localStorage.getItem('Answers')) const answers = JSON.parse(localStorage.getItem('Answers'))
...@@ -17,11 +17,17 @@ function End() { ...@@ -17,11 +17,17 @@ function End() {
scores[i] = 1 scores[i] = 1
} }
else if (answers[i] === 0) {
scores[i] = -1
}
else { else {
scores[i] = 0 scores[i] = 0
} }
score += scores[i] score += scores[i]
if (score <0){
score =0
}
} }
return ( return (
...@@ -38,7 +44,17 @@ function End() { ...@@ -38,7 +44,17 @@ function End() {
<tbody> <tbody>
{scores.map((score, index) => { {scores.map((score, index) => {
return (score === 1) ? <tr><td>Quiz {index + 1}</td> <td> O </td></tr> : <tr><td>Quiz {index + 1}</td> <td> X</td></tr> if (score === -1) {
result = <tr><td>Quiz {index + 1}</td> <td> 정답이 입력되지 않았습니다. </td></tr>
}
else if (score === 1) {
result = <tr><td>Quiz {index + 1}</td> <td> O </td></tr>
}
else {
result = <tr><td>Quiz {index + 1}</td> <td> X</td></tr>
}
return result
})} })}
<tr> <tr>
<td>총점</td> <td>총점</td>
......
// import bg from './img_study.jpg' // import bg from './img_study.jpg'
// import korea from './img_korea.jpg' // import korea from './img_korea.jpg'
import React, { useState } from 'react' import React, { useState} from 'react'
import { Redirect } from 'react-router-dom'; import { Redirect } from 'react-router-dom';
function Home() { function Home() {
const [name, setName] = useState('') const [name, setName] = useState('')
const [password, SetPassword] = useState('') const [password, SetPassword] = useState('')
const [done, setDone] = useState(false) const [done, setDone] = useState(false)
const [admin, setAdmin] = useState(false);
const handleChangename = (event) => { const handleChangename = (event) => {
setName(event.target.value) setName(event.target.value)
} }
...@@ -23,7 +24,14 @@ function Home() { ...@@ -23,7 +24,14 @@ function Home() {
else if (!password) { else if (!password) {
alert('비밀번호를 입력하세요') alert('비밀번호를 입력하세요')
} }
else if (password !== '0000') { else if (name === 'admin' && password === '0001') {
console.log('done')
return (setAdmin(true)
)
}
else if (password !== '0319') {
alert('유효한 비밀번호를 입력하세요') alert('유효한 비밀번호를 입력하세요')
} }
else { else {
...@@ -35,18 +43,14 @@ function Home() { ...@@ -35,18 +43,14 @@ function Home() {
} }
return ( return (
<> <>
{admin ? <Redirect to='/admin' /> : ''}
{done ? <Redirect to='/quiz' /> : ''} {done ? <Redirect to='/quiz' /> : ''}
{/* <div style={{ backgroundImage: 'url(' + bg + ')', backgroundColor: "grey", backgroundSize: "100%", width: "100%", height: "880px", backgroundRepeat: 'no-repeat' }}>
<div className="Main"></div> */}
{/*
<div style={{ fontSize: '70px', marginBottom: '100px', textAlign: 'center', backgroundColor: '#AE0E36' }}> */}
{/* <img alt='korea' src={korea} width='10%'/> */}
{/* KOREA UNIVERSITY
</div> */}
<h1 className="h-3 mb-5 mx-3 text-center bg-danger py-2"> <h1 className="h-3 mb-5 mx-3 text-center bg-danger py-2">
KOREA UNIVERSITY KOREA UNIVERSITY
</h1> </h1>
...@@ -74,75 +78,6 @@ function Home() { ...@@ -74,75 +78,6 @@ function Home() {
</div> </div>
</div> </div>
</form> </form>
{/*
<div className="container">
<div className="row justify-content-center mb-5 mt-5">
<div className="col-md-4"></div>
<div className="col-md-4"> </div>
<div className="col-md-4"></div>
</div>
<div className="row text-center p-3">
<div className="col-md-4"></div>
<div className="col-md-4">이름입력<input className="ml-2 inputBox" onChange={handleChangename} /></div>
<div className="col-md-4"></div>
</div>
<div className="row text-center">
<div className="col-md-4"></div>
<div className="col-md-4">비밀번호<input type='password' className="ml-2 inputBox" onChange={handleChangepassword} /></div>
<div className="col-md-4"></div>
</div>
<div className="row text-center">
<div className="col-md-4"></div>
<div className="col-md-4"><button className="mt-4 btn btn-dark" onClick={handleClick}>Login</button></div>
<div className="col-md-4"></div>
</div>
</div>
*/}
{/*
<div className="d-flex justify-content-center ">
<table className="table table-bordered dark-table" style={{ width: "400px" }}>
<thead className="text-center">
<tr style={{ height: "0 px" }}>정보 입력</tr>
</thead>
<tbody className="text-center">
<tr>
<td>이름 입력<input className="ml-2 inputBox" onChange={handleChangename} /></td>
</tr>
<tr>
<td>비밀번호<input type='password' className="ml-2 inputBox" onChange={handleChangepassword} /></td>
</tr>
<tr>
<td><button className="mt-4 btn btn-dark" onClick={handleClick}>Login</button></td>
</tr>
</tbody>
</table>
</div>
*/}
{/* <div className="Box" style={{ border: 'solid', position: 'absolute', top: "300px", left: "68%"}} > */}
{/* <div className="Name" style={{boxShadow: '5px 5px 5px 5px gray', border: 'solid', fontSize: '30px', position: "absolute", top: "300px", left: "68%" }}>
이름(Name)
<input style={{ padding: '5px', border: 'solid', borderRight: 'none', borderBottom: 'none', borderTop: 'none', marginLeft: '105px', inlineSize: '160px', blockSize: '40px', fontSize: '40px' }} onChange={handleChangename} />
</div>
<div className="Name" style={{ boxShadow: '5px 5px 5px 5px gray',border: 'solid', fontSize: '30px', position: "absolute", top: "360px", left: "68%" }}>
비밀번호(Password)
<input type='password' style={{ padding: '5px', border: 'solid', borderRight: 'none', borderBottom: 'none', borderTop: 'none', marginLeft: '0px', inlineSize: '160px', blockSize: '40px', fontSize: '40px' }} onChange={handleChangepassword} />
</div>
<div className='Box2'>
<button style={{boxShadow: '5px 5px 5px 5px gray', marginLeft: '82%', marginTop: '10%', blockSize: '50px', inlineSize: '175px', fontSize: '35px' }} className="QuizStart" onClick={checking}>Start !</button>
</div> */}
{/* localStorage를 사용해야는지 localstorage를 사용해야하는지 */}
{/* </div> */}
{/* </div> */}
</> </>
) )
......
import React, { useState } from 'react' import React, { useState } from 'react'
import { Link } 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/img_question.png'
const QnA = [ const QnA = [
{ Q: "6 X 4 = ?", Choose: [6, 12, 18, 24], A: "4", N: 1 }, { Q: "6 X 4 = ?", Choose: [6, 12, 18, 24], N: 1 },
{ Q: "3 + 3 = ?", Choose: [2, 4, 6, 8], A: "3", N: 2 }, { Q: "3 + 3 = ?", Choose: [2, 4, 6, 8], N: 2 },
{ Q: "3 - 1 = ?", Choose: [1, 2, 3, 4], A: "2", N: 3 } { Q: "3 - 1 = ?", Choose: [1, 2, 3, 4], N: 3 }
] ]
let Answers = [] let Answers = [0,0,0]
localStorage.setItem('Answers', JSON.stringify(Answers))
let Solutions = [4, 3, 2] let Solutions = [4, 3, 2]
localStorage.setItem('Solutions', JSON.stringify(Solutions))
function Quiz() { function Quiz() {
const [question, setQuestion] = useState({ const [question, setQuestion] = useState({
...QnA[0], ...QnA[0]
i: 0,
page: 0,
}) })
const [selected, setSelected] = useState("") //선택한 답을 보여줄 것 const [selected, setSelected] = useState("") //선택한 답을 보여줄 것
const [timeout, settimeout] = useState(false)
function handleQuestion() { function handleQuestion() {
setQuestion({ ...QnA[question.i + 1], i: question.i + 1, page: question.page + 1 }) setQuestion({ ...QnA[question.N]})
setSelected("") //페이지 넘어가면 Your Answer 초기화 setSelected("") //페이지 넘어가면 selected 초기화
} }
let handleChange = (ev) => { let handleChange = (ev) => {
// ev.preventDefault() //새로고침 안되도록
setSelected(ev.target.value) //selected값 변경 setSelected(ev.target.value) //selected값 변경
Answers[question.N - 1] = Number(ev.target.id) + 1 Answers[question.N - 1] = Number(ev.target.id) + 1
localStorage.setItem('Answers', JSON.stringify(Answers)) localStorage.setItem('Answers', JSON.stringify(Answers))
console.log(Answers)
} }
return ( return (
<>
<div className="container-fluid"> <div className="container-fluid">
<div className="text-center h2 font-weight-bold bg-warning py-2">미적분학 퀴즈</div> <div className="text-center h2 font-weight-bold bg-warning py-2">미적분학 퀴즈</div>
<div className="row justify-content-md-center" > <div className="row justify-content-md-center" >
...@@ -50,17 +49,15 @@ function Quiz() { ...@@ -50,17 +49,15 @@ function Quiz() {
<div className="mt-2"> <div className="mt-2">
<form> <form>
{question.Choose.map((a, index) => {question.Choose.map((a, index) =>
<div key={index}> <div>
<input type="radio" name='answer' id={index} value={a} onChange={handleChange} checked={parseInt(selected) === a} /> <input type="radio" name='answer' id={index} value={a} onChange={handleChange} checked={selected === String(a)} />
<label className="font-weight-bold" htmlFor={a}>{a}</label> <label className="font-weight-bold" htmlFor={a}>{a}</label>
</div> </div>
)} )}
{/* <input hidden type="submit" value="확인" /> */}
{/*버튼 숨김*/}
</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.page === 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>
...@@ -69,19 +66,22 @@ function Quiz() { ...@@ -69,19 +66,22 @@ function Quiz() {
</div> </div>
<p className="h3 text-center text-danger "> <p className="h3 text-center text-danger ">
<Timer <Timer
initialTime={3600000} initialTime={30010}
direction="backward" direction="backward"
checkpoints={[ checkpoints={[
{time:1,
callback:()=>alert('시간이 초과되었습니다.'),
},
{ {
time: 0, time: 0,
callback: <Link to="/end">제출</Link> callback: () => settimeout(true),
// history.go(1)
} }
]} ]}
> >
{() => ( {() => (
<> <>
<Timer.Minutes /> : <Timer.Seconds></Timer.Seconds> / 60 : 00 </> <Timer.Minutes /> : <Timer.Seconds></Timer.Seconds> / 30 : 00 </>
)} )}
</Timer> {/* npm i react-compound-timer */} </Timer> {/* npm i react-compound-timer */}
</p> </p>
...@@ -91,6 +91,8 @@ function Quiz() { ...@@ -91,6 +91,8 @@ function Quiz() {
</div> </div>
</div> </div>
</div> </div>
{timeout ? <Redirect to='/end'/> : '' }
</>
) )
......
import React, { useState } from 'react';
// import { Link } from 'react-router-dom';
function Admin() {
const [question, setQuestion] = useState('')
const [choose, setChoose] = useState('')
const [answer, setAnswer] = useState('')
const [selectOption, setselectOption ] = useState('')
// const [done, setDone] = useState(false)
const handleChangeQuestion = (event) => {
setQuestion(event.target.value)
}
const handleChangechoose = (event) => {
setChoose(event.target.value)
}
const handleChangeanswer = (event) => {
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() {
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" class="form-control" placeholder="보기를 입력하세요" onChange={handleChangechoose} />
</div>
}
setselectOption(list)
}
return (
<>
{/* {done ? alert('모두 입력되었습니다.') : ''} */}
<div className="container-fluid">
<div className="row d-flex justify-content-center">
<div className="col-8">
<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" onChange={handleChangenumber} placeholder="Number" /> */}
<input type="text" 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="option"/>
</div>
</div>
<input type="text" class="form-control" 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 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>
</div>
</div>
</>
)
}
export default Admin
\ No newline at end of file
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import 'react-dom'
import './index.css'; import './index.css';
import App from './App'; import App from './App';
import 'bootstrap/dist/css/bootstrap.css'; // import Quiz from './Quiz';
import * as serviceWorker from './serviceWorker'; import * as serviceWorker from './serviceWorker';
import 'bootstrap/dist/css/bootstrap.css' import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap'
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>
......
import React from 'react';
import ReactDOM from 'react-dom';
import 'react-dom'
import './index.css';
import Home from './Home'
import Quiz from './Quiz'
import End from './End'
import { BrowserRouter as Router, Route } from 'react-router-dom';
// import Quiz from './Quiz';
import * as serviceWorker from './serviceWorker';
import 'bootstrap/dist/css/bootstrap.css'
ReactDOM.render(
<Router>
<Route exact path="/" component={Home} />
<Route path='/quiz' component={Quiz} />
<Route path='/end' component={End} />
</Router>,
document.getElementById('root')
);
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
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