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
9cd9d519
Commit
9cd9d519
authored
Aug 17, 2020
by
Jiwon Yoon
Browse files
ref
parent
bfae38b7
Changes
4
Show whitespace changes
Inline
Side-by-side
src/Admin.js
View file @
9cd9d519
import
React
,
{
useState
,
useEffect
}
from
'
react
'
;
import
React
,
{
useState
,
useEffect
,
useRef
}
from
'
react
'
;
import
AdminQuiz
from
'
./AdminQuiz
'
import
AdminSetting
from
'
./AdminSetting
'
let
QuizBtn
=
[]
let
QnAadmins
function
Admin
()
{
const
[
result
,
setresult
]
=
useState
(
''
)
const
[
QuizBtnCount
,
setQuizBtnCount
]
=
useState
(
4
)
const
[
n
,
setn
]
=
useState
(
0
)
const
indexRef
=
useRef
(
0
)
const
dbRef
=
useRef
([])
useEffect
(()
=>
{
if
(
JSON
.
parse
(
localStorage
.
getItem
(
'
QnA
'
)))
{
dbRef
.
current
=
JSON
.
parse
(
localStorage
.
getItem
(
'
QnA
'
))
}
},
[])
function
handleClickSetting
()
{
setresult
(
<
AdminSetting
/>
)
}
function
handleClickQuiz
(
e
)
{
if
(
QnAadmins
)
{
let
QnAadmins
=
[]
setn
(
e
.
target
.
id
)
setresult
(
<
AdminQuiz
quizNum
=
{
e
.
target
.
id
}
fn
=
{
handleClickSave
}
data
=
{
QnAadmins
}
/>
)
}
else
{
setn
(
e
.
target
.
id
)
// let QnAadmins = []
let
QnAadmins
=
JSON
.
parse
(
localStorage
.
getItem
(
'
QnA
'
))
console
.
log
(
QnAadmins
)
setresult
(
<
AdminQuiz
quizNum
=
{
e
.
target
.
id
}
fn
=
{
handleClickSave
}
data
=
{
QnAadmins
[
Number
(
n
)]}
/>
)
}
indexRef
.
current
=
Number
(
e
.
target
.
id
)
-
1
console
.
log
(
dbRef
.
current
,
indexRef
.
current
)
setresult
(
<
AdminQuiz
quizNum
=
{
e
.
target
.
id
}
fn
=
{
handleClickSave
}
data
=
{
dbRef
.
current
}
/>
)
}
function
handleClickAddQuiz
()
{
...
...
@@ -38,25 +37,27 @@ function Admin() {
}
function
handleClickSave
(
QnAadmin
)
{
QnAadmins
.
splice
(
n
,
0
,
QnAadmin
)
localStorage
.
setItem
(
'
QnA
'
,
JSON
.
stringify
(
QnAadmins
))
console
.
log
(
QnAadmin
,
indexRef
.
current
)
dbRef
.
current
[
indexRef
.
current
]
=
QnAadmin
localStorage
.
setItem
(
'
QnA
'
,
JSON
.
stringify
(
dbRef
.
current
))
}
return
(
<>
<
div
className
=
"
container-fluid
"
>
<
div
className
=
"
container-fluid
bg-light
"
>
<
div
className
=
"
row justify-content-md-center mt-5
"
>
<
div
className
=
"
col-2 text-center border py-5 bg-white
"
>
<
div
className
=
"
py-3 border-top border-bottom
"
>
<
h5
className
=
"
font-weight-bold
"
>
ADMIN
<
/h5
>
<
h5
className
=
"
font-weight-bold
"
>
설정
<
/h5
>
<
/div
>
<
div
className
=
"
border-bottom py-4
"
>
<
button
type
=
"
button
"
className
=
"
btn btn-info
"
onClick
=
{
handleClickSetting
}
>
Setting
<
/button
>
<
/div
>
<
div
className
=
"
btn-group-vertical py-4
"
>
<
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
>
<
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
>
...
...
src/AdminQuiz.js
View file @
9cd9d519
import
React
,
{
useState
,
useEffect
}
from
'
react
'
;
import
React
,
{
useState
}
from
'
react
'
;
let
list
=
[]
let
QnAadmin
=
{}
...
...
@@ -53,7 +53,7 @@ function AdminQuiz(props) {
}
else
{
QnAadmin
[
'
Choose
'
]
=
Object
.
values
(
savechoose
)
QnAadmin
[
'
N
'
]
=
String
(
props
.
Q
uizNum
)
QnAadmin
[
'
N
'
]
=
String
(
props
.
q
uizNum
)
props
.
fn
(
QnAadmin
)
QnAadmin
=
{}
alert
(
'
입력이 완료되었습니다.
'
)
...
...
@@ -65,7 +65,7 @@ function AdminQuiz(props) {
return
(
<
div
className
=
""
id
=
"
Quiz1
"
>
<
h2
className
=
"
p-3 border text-center
"
>
{
String
(
props
.
quizNum
)}
번
문제만들기
<
/h2
>
<
h2
className
=
"
p-3 border text-center
bg-white
"
>
{
String
(
props
.
quizNum
)}
번
문제만들기
<
/h2
>
<
div
className
=
"
p-3 borber
"
>
<
div
className
=
"
p-3
"
>
<
span
className
=
"
font-weight-bold mr-2 h3
"
>
1
.
문제
입력하기
<
/span
>
...
...
src/AdminSetting.js
View file @
9cd9d519
...
...
@@ -47,19 +47,19 @@ function AdminSetting() {
}
return
(
<
div
className
=
"
col-8
"
>
<
h2
className
=
"
p-3 border text-center
"
>
관리자
설정
변경
창
<
/h2
>
<
div
className
=
"
p-3 border
"
>
<
div
className
=
""
>
<
h2
className
=
"
p-3 border text-center
bg-white
"
>
관리자
설정
변경
창
<
/h2
>
<
div
className
=
"
p-3 border
bg-white
"
>
<
h4
>
변경할
비밀번호를
입력하세요
<
/h4
>
<
input
type
=
"
text
"
onChange
=
{
handleChangePassword
}
placeholder
=
"
New Password
"
/>
<
/div
>
<
div
className
=
"
p-3 border
"
>
<
div
className
=
"
p-3 border
bg-white
"
>
<
h4
>
변경할
관리자
비밀번호를
입력하세요
<
/h4
>
<
input
type
=
"
text
"
onChange
=
{
handleChangeAdminPassword
}
placeholder
=
"
New Admin Password
"
/>
<
/div
>
<
div
className
=
"
p-3 border
"
>
<
div
className
=
"
p-3 border
bg-white
"
>
<
h4
>
타이머를
설정하세요
(
초단위
)
<
/h4
>
<
input
type
=
"
text
"
onChange
=
{
handleChangeTime
}
placeholder
=
"
Set Time
"
/>
...
...
src/App.js
View file @
9cd9d519
...
...
@@ -10,9 +10,9 @@ function App() {
return
(
<
Router
>
<
div
className
=
"
container-fluid vh-100 bg-light
"
>
<
header
className
=
"
border-bottom
"
>
<
header
className
=
"
border-bottom
bg-white
"
>
<
Link
to
=
"
/
"
>
<
button
className
=
"
ml-3 btn btn-
light
btn-lg font-weight-bold text-info
"
>
Home
<
/button
>
<
button
className
=
"
ml-3 btn btn-
white
btn-lg font-weight-bold text-info
"
>
Home
<
/button
>
<
/Link
>
<
/header
>
<
Switch
>
...
...
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