import React, { useState, useEffect, useRef } from 'react';
import AdminQuiz from './AdminQuiz'
import AdminSetting from './AdminSetting'
let QuizBtn = []
function Admin() {
const [result, setresult] = useState('')
const [QuizBtnCount, setQuizBtnCount] = useState(4)
const indexRef = useRef(0)
const dbRef = useRef([])
useEffect(() => {
if (JSON.parse(localStorage.getItem('QnA'))) {
dbRef.current=JSON.parse(localStorage.getItem('QnA'))
}
}, [])
function handleClickSetting() {
setresult()
}
function handleClickQuiz(e) {
indexRef.current = Number(e.target.id) - 1
// console.log(dbRef.current, indexRef.current)
if(dbRef.current[e.target.id-1]){
setresult()
}
else{
dbRef.current[e.target.id-1] = {'Q':'x', 'Choose':[0,0,0,0], 'A':'x'}
setresult()
}
}
function handleClickAddQuiz() {
QuizBtn.push(
)
setQuizBtnCount(QuizBtnCount + 1)
}
function handleClickSave(QnAadmin) {
console.log(QnAadmin, indexRef.current)
dbRef.current[indexRef.current] = QnAadmin
localStorage.setItem('QnA', JSON.stringify(dbRef.current))
}
return (
<>
설정
{QuizBtn.map((element) => element)}
{result}
>
)
}
export default Admin