Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
online-quiz-react
Commits
41b1059e
Commit
41b1059e
authored
Aug 17, 2020
by
Jiwon Yoon
Browse files
ASD
parent
217e0071
Changes
4
Show whitespace changes
Inline
Side-by-side
src/Admin.js
View file @
41b1059e
...
...
@@ -17,7 +17,8 @@ function Admin() {
function
handleClickQuiz
(
e
)
{
setn
(
e
.
target
.
id
)
setresult
(
<
AdminQuiz
quizNum
=
{
e
.
target
.
id
}
fn
=
{
handleClickSave
}
data
=
{
QnAadmins
}
/>
)
console
.
log
(
QnAadmins
)
setresult
(
<
AdminQuiz
quizNum
=
{
e
.
target
.
id
}
fn
=
{
handleClickSave
}
data
=
{
QnAadmins
[
e
.
target
.
id
]}
/>
)
}
function
handleClickAddQuiz
()
{
...
...
@@ -27,7 +28,6 @@ function Admin() {
setQuizBtnCount
(
QuizBtnCount
+
1
)
}
function
handleClickSave
(
QnAadmin
){
QnAadmins
.
splice
(
n
,
0
,
QnAadmin
)
localStorage
.
setItem
(
'
QnA
'
,
JSON
.
stringify
(
QnAadmins
))
...
...
src/AdminQuiz.js
View file @
41b1059e
...
...
@@ -14,22 +14,21 @@ function AdminQuiz(props) {
const
[
c
,
setc
]
=
useState
([])
const
[
a
,
seta
]
=
useState
(
''
)
// useEffect(()=>{
// setQuestion('')
// if(JSON.parse(localStorage.getItem('QnA'))[props.QuizNum]){
// setq(props.data[props.QuizNum-1].Q)
// setc(props.data[props.QuizNum-1].Choose)
// seta(props.data[props.QuizNum-1].A)
// }
// else {
// setq('보기를 입력하세요')
// setc(['보기를 입력하세요','보기를 입력하세요','보기를 입력하세요','보기를 입력하세요'])
// seta('보기를 입력하세요')
// }
// },[props.QuizNum])
useEffect
(()
=>
{
setQuestion
(
''
)
setChoose
(
''
)
if
(
props
.
data
){
setq
(
props
.
data
.
Q
)
setc
(
props
.
data
.
Choose
)
seta
(
props
.
data
.
A
)
}
else
{
setq
(
'
보기를 입력하세요
'
)
setc
([
'
보기를 입력하세요
'
,
'
보기를 입력하세요
'
,
'
보기를 입력하세요
'
,
'
보기를 입력하세요
'
])
seta
(
'
보기를 입력하세요
'
)
}
},[
props
.
quizNum
])
const
handleChangeQuestion
=
(
event
)
=>
{
QnAadmin
[
'
Q
'
]
=
event
.
target
.
value
...
...
src/Home.js
View file @
41b1059e
// import bg from './img_study.jpg'
// import korea from './img_korea.jpg'
import
React
,
{
useState
}
from
'
react
'
import
{
Redirect
}
from
'
react-router-dom
'
;
function
Home
()
{
let
info
=
[]
if
(
JSON
.
parse
(
localStorage
.
getItem
(
"
Set
"
))
===
null
){
info
=
[{
password
:
"
0319
"
,
AdminPassword
:
"
0001
"
,
Time
:
"
30010
"
}]
//수정.추가
}
else
{
info
=
JSON
.
parse
(
localStorage
.
getItem
(
"
Set
"
))
}
//수정. 추가
const
[
name
,
setName
]
=
useState
(
''
)
const
[
password
,
SetPassword
]
=
useState
(
''
)
const
[
done
,
setDone
]
=
useState
(
false
)
...
...
@@ -24,14 +31,14 @@ function Home() {
else
if
(
!
password
)
{
alert
(
'
비밀번호를 입력하세요
'
)
}
else
if
(
name
===
'
admin
'
&&
password
===
'
0001
'
)
{
else
if
(
name
===
'
admin
'
&&
password
===
info
[
0
].
AdminPassword
)
{
console
.
log
(
'
done
'
)
return
(
setAdmin
(
true
)
)
}
else
if
(
password
!==
'
0319
'
)
{
else
if
(
password
!==
info
[
0
].
password
)
{
alert
(
'
유효한 비밀번호를 입력하세요
'
)
}
else
{
...
...
@@ -83,4 +90,3 @@ function Home() {
}
export
default
Home
;
src/Quiz.js
View file @
41b1059e
...
...
@@ -6,11 +6,16 @@ import logo from './img/img_question.png'
let
localQnA
=
JSON
.
parse
(
localStorage
.
getItem
(
'
QnA
'
))
let
Answers
=
[]
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
({
...
localQnA
[
0
]
})
...
...
@@ -20,10 +25,10 @@ function Quiz() {
//for each 사용하기
let
Solutions
=
[]
//빈 배열
console
.
log
(
localQnA
)
localQnA
.
map
((
x
)
=>
{
//A만 꺼내서 q에 추가
// Answers.push(0)
return
Solutions
.
push
(
x
.
A
)
})
localQnA
.
forEach
((
element
)
=>
{
Solutions
.
push
(
Number
(
element
.
A
)
)
})
;
useEffect
(()
=>
{
for
(
let
i
=
1
;
i
<=
Solutions
.
length
;
i
++
)
{
Answers
.
push
(
0
)
...
...
@@ -57,7 +62,7 @@ function Quiz() {
<
/div
>
<
div
className
=
"
col-md-auto
"
>
<
div
className
=
"
h2 mt-2
"
>
{
localQnA
[
0
]
.
Q
}
{
question
.
Q
}
<
/div
>
<
div
className
=
"
mt-2
"
>
<
form
>
...
...
@@ -79,7 +84,8 @@ function Quiz() {
<
/div
>
<
p
className
=
"
h3 text-center text-danger
"
>
<
Timer
initialTime
=
{
3000
}
initialTime
=
{
Time
}
// 수정. 추가. 새로설정한 시간으로 설정. 하지만 새로고침해야 적용됨
// initialTime={Number(JSON.parse(localStorage.getItem("Set"))[0].Time)}
direction
=
"
backward
"
checkpoints
=
{[
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment