Commit 8d9a692a authored by Yoon, Daeki's avatar Yoon, Daeki 😅
Browse files

start, end 시간 설정중

parent 3411ed91
import React, { useState } from "react"; import React, { useState } from "react";
import {Link} from 'react-router-dom' import { Link } from "react-router-dom";
import Container from "react-bootstrap/Container";
import Button from "react-bootstrap/Button"; import Button from "react-bootstrap/Button";
import Form from "react-bootstrap/Form"; import Form from "react-bootstrap/Form";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col"; import Col from "react-bootstrap/Col";
import Modal from "react-bootstrap/Modal"; import Modal from "react-bootstrap/Modal";
import authHelpers from "../auth/auth-helpers"; import authHelpers from "../auth/auth-helpers";
...@@ -10,32 +12,43 @@ import { create } from "./api-quiz"; ...@@ -10,32 +12,43 @@ import { create } from "./api-quiz";
import Problem from "./Problem"; import Problem from "./Problem";
function NewQuiz() { function NewQuiz() {
const [title, setTitle] = useState('') const [title, setTitle] = useState("");
const [problems, setProblems] = useState([]) const [problems, setProblems] = useState([]);
const [show, setShow] = useState(false) const [show, setShow] = useState(false);
const [quiz, setQuiz] = useState({}) const [quiz, setQuiz] = useState({});
const [startAt, setStartAt] = useState()
const [endAt, setEndAt] = useState()
const [values, setValues] = useState({
title: '',
show: false,
startAt: '',
endAt: '',
})
const jwt = authHelpers.isAuthenticated(); const jwt = authHelpers.isAuthenticated();
const handleChange = (event) => { const handleChange = (event) => {
const { name, value } = event.target const { name, value } = event.target;
if (name === 'title') { console.log("name", name, "value", value);
setTitle(value) console.log('values:', values);
} setValues({...values, [name]: value})
if (name === "title") {
setTitle(value);
} }
};
const addProblem = (problem) => { const addProblem = (problem) => {
console.log(problem) console.log(problem);
setProblems([...problems, problem]) setProblems([...problems, problem]);
} };
const clickSubmit = (event) => { const clickSubmit = (event) => {
event.preventDefault(); event.preventDefault();
const quizData = { const quizData = {
title, title,
problems problems,
} };
create({ userId: jwt.user._id }, { t: jwt.token }, quizData).then( create({ userId: jwt.user._id }, { t: jwt.token }, quizData).then(
(data) => { (data) => {
...@@ -43,41 +56,66 @@ function NewQuiz() { ...@@ -43,41 +56,66 @@ function NewQuiz() {
console.log(data.error); console.log(data.error);
} else { } else {
console.log(data); console.log(data);
setQuiz(data) setQuiz(data);
setShow(true) setShow(true);
} }
} }
); );
}; };
return ( return (
<div> <Container>
<h1 className="text-center"> <Form>
New Quiz <h1 className="text-center">New Quiz</h1>
</h1> <Form.Group>
<label htmlFor='title'>Title</label> <Form.Label htmlFor="title">Title</Form.Label>
<input id='title' name='title' onChange={handleChange} placeholder='Title' /> <Form.Control
{ id="title"
problems.map((problem, index) => { name="title"
return <Problem key={index} problem={problem} number={index} /> onChange={handleChange}
}) placeholder="Title"
} />
</Form.Group>
<Row className="justify-content-between">
<Form.Group>
<Form.Label>Start Time</Form.Label>
<Form.Control
type="datetime-local"
id="start-time"
name="startAt"
onChange={handleChange}
/>
</Form.Group>
<Form.Group>
<Form.Label>End Time</Form.Label>
<Form.Control
type="datetime-local"
id="start-time"
name="endAt"
onChange={handleChange}
/>
</Form.Group>
</Row>
{problems.map((problem, index) => {
return <Problem key={index} problem={problem} number={index} />;
})}
<NewQuizProblem addProblem={addProblem} /> <NewQuizProblem addProblem={addProblem} />
<Button onClick={clickSubmit}>퀴즈 저장</Button> <Button onClick={clickSubmit}>퀴즈 저장</Button>
</Form>
<Modal show={show}> <Modal show={show}>
<Modal.Header> <Modal.Header>
<Modal.Title>New Quiz</Modal.Title> <Modal.Title>New Quiz</Modal.Title>
</Modal.Header> </Modal.Header>
<Modal.Body> <Modal.Body>New Quiz successfully created.</Modal.Body>
New Quiz successfully created.
</Modal.Body>
<Modal.Footer> <Modal.Footer>
<Link to={`/quiz/${quiz._id}`}> <Link to={`/quiz/${quiz._id}`}>
<Button>Go to quiz</Button> <Button>Go to quiz</Button>
</Link> </Link>
</Modal.Footer> </Modal.Footer>
</Modal> </Modal>
</div> </Container>
); );
} }
...@@ -115,8 +153,8 @@ function NewQuizProblem({ addProblem }) { ...@@ -115,8 +153,8 @@ function NewQuizProblem({ addProblem }) {
}; };
return ( return (
<div> <>
<Form> {/* <Form> */}
<Form.Group controlId="question"> <Form.Group controlId="question">
<Form.Label>Question</Form.Label> <Form.Label>Question</Form.Label>
<Form.Control <Form.Control
...@@ -149,7 +187,7 @@ function NewQuizProblem({ addProblem }) { ...@@ -149,7 +187,7 @@ function NewQuizProblem({ addProblem }) {
); );
})} })}
<Button onClick={clickAdd}>문제 추가</Button> <Button onClick={clickAdd}>문제 추가</Button>
</Form> {/* </Form> */}
</div> </>
); );
} }
import mongoose from 'mongoose'
const CourseSchema = new mongoose.Schema({
name: String,
description: String,
image: {data: Buffer, contentType: String},
instructor: {
type: mongoose.SchemaTypes.ObjectId,
ref: 'User'
},
created: {
type: Date,
default: Date.now
},
updated: Date,
})
export default mongoose.model('Course', CourseSchema)
\ No newline at end of file
import mongoose from 'mongoose'
const EnrollmentSchema = new mongoose.Schema({
course: {
type: mongoose.SchemaTypes.ObjectId,
ref: 'Course'
},
student: {
type: mongoose.SchemaTypes.ObjectId,
ref: 'User'
},
created: {
type: Date,
default: Date.now
},
updated: Date,
completed: Boolean
})
\ No newline at end of file
...@@ -23,6 +23,10 @@ const QuizSchema = new mongoose.Schema({ ...@@ -23,6 +23,10 @@ const QuizSchema = new mongoose.Schema({
image: { image: {
type: Buffer, type: Buffer,
contentType: String, contentType: String,
},
course: {
type: mongoose.SchemaTypes.ObjectId,
ref: 'Course'
} }
}) })
......
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