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

start, end 시간 설정중

parent 3411ed91
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 Form from "react-bootstrap/Form";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import Modal from "react-bootstrap/Modal";
import authHelpers from "../auth/auth-helpers";
......@@ -10,32 +12,43 @@ import { create } from "./api-quiz";
import Problem from "./Problem";
function NewQuiz() {
const [title, setTitle] = useState('')
const [problems, setProblems] = useState([])
const [show, setShow] = useState(false)
const [quiz, setQuiz] = useState({})
const [title, setTitle] = useState("");
const [problems, setProblems] = useState([]);
const [show, setShow] = useState(false);
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 handleChange = (event) => {
const { name, value } = event.target
if (name === 'title') {
setTitle(value)
}
const { name, value } = event.target;
console.log("name", name, "value", value);
console.log('values:', values);
setValues({...values, [name]: value})
if (name === "title") {
setTitle(value);
}
};
const addProblem = (problem) => {
console.log(problem)
setProblems([...problems, problem])
}
console.log(problem);
setProblems([...problems, problem]);
};
const clickSubmit = (event) => {
event.preventDefault();
const quizData = {
title,
problems
}
problems,
};
create({ userId: jwt.user._id }, { t: jwt.token }, quizData).then(
(data) => {
......@@ -43,41 +56,66 @@ function NewQuiz() {
console.log(data.error);
} else {
console.log(data);
setQuiz(data)
setShow(true)
setQuiz(data);
setShow(true);
}
}
);
};
return (
<div>
<h1 className="text-center">
New Quiz
</h1>
<label htmlFor='title'>Title</label>
<input id='title' name='title' onChange={handleChange} placeholder='Title' />
{
problems.map((problem, index) => {
return <Problem key={index} problem={problem} number={index} />
})
}
<Container>
<Form>
<h1 className="text-center">New Quiz</h1>
<Form.Group>
<Form.Label htmlFor="title">Title</Form.Label>
<Form.Control
id="title"
name="title"
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} />
<Button onClick={clickSubmit}>퀴즈 저장</Button>
</Form>
<Modal show={show}>
<Modal.Header>
<Modal.Title>New Quiz</Modal.Title>
</Modal.Header>
<Modal.Body>
New Quiz successfully created.
</Modal.Body>
<Modal.Body>New Quiz successfully created.</Modal.Body>
<Modal.Footer>
<Link to={`/quiz/${quiz._id}`}>
<Button>Go to quiz</Button>
</Link>
</Modal.Footer>
</Modal>
</div>
</Container>
);
}
......@@ -115,8 +153,8 @@ function NewQuizProblem({ addProblem }) {
};
return (
<div>
<Form>
<>
{/* <Form> */}
<Form.Group controlId="question">
<Form.Label>Question</Form.Label>
<Form.Control
......@@ -149,7 +187,7 @@ function NewQuizProblem({ addProblem }) {
);
})}
<Button onClick={clickAdd}>문제 추가</Button>
</Form>
</div>
{/* </Form> */}
</>
);
}
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({
image: {
type: Buffer,
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