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

Problems에 userId 추가

parent 6d061a01
...@@ -2,15 +2,11 @@ import React from 'react'; ...@@ -2,15 +2,11 @@ import React from 'react';
import { BrowserRouter, Switch, Route } from 'react-router-dom' import { BrowserRouter, Switch, Route } from 'react-router-dom'
import { AuthProvider } from './auth/auth-context'; import { AuthProvider } from './auth/auth-context';
import MainRouter from './MainRouter'; import MainRouter from './MainRouter';
import Problems from './quiz/Problems';
function App() { function App() {
return ( return (
<AuthProvider> <AuthProvider>
<BrowserRouter> <BrowserRouter>
<MainRouter /> <MainRouter />
<Switch>
<Route path="/problems" component={Problems}/>
</Switch>
</BrowserRouter> </BrowserRouter>
</AuthProvider> </AuthProvider>
); );
......
...@@ -9,6 +9,7 @@ import Signup from "./user/Signup"; ...@@ -9,6 +9,7 @@ import Signup from "./user/Signup";
import Quizzes from "./quiz/Quizzes"; import Quizzes from "./quiz/Quizzes";
import EditProblem from "./quiz/EditProblem"; import EditProblem from "./quiz/EditProblem";
import NewProblem from "./quiz/NewProblem"; import NewProblem from "./quiz/NewProblem";
import Problems from './quiz/Problems';
function MainRouter() { function MainRouter() {
return ( return (
...@@ -24,6 +25,9 @@ function MainRouter() { ...@@ -24,6 +25,9 @@ function MainRouter() {
<Route path="/signup"> <Route path="/signup">
<Signup /> <Signup />
</Route> </Route>
<Route path="/problems/:userId">
<Problems />
</Route>
<Route path="/quiz/new"> <Route path="/quiz/new">
<NewQuiz /> <NewQuiz />
</Route> </Route>
...@@ -37,7 +41,7 @@ function MainRouter() { ...@@ -37,7 +41,7 @@ function MainRouter() {
<EditProblem /> <EditProblem />
</Route> </Route>
{/* 아래 "/quiz/:quizId" 는 "/quiz/by/:userId"와 순서 바뀌면 안된다. */} {/* 아래 "/quiz/:quizId" 는 "/quiz/by/:userId"와 순서 바뀌면 안된다. */}
<Route path="/quiz/:quizId"> <Route path="/quiz/:quizId">
<Quiz /> <Quiz />
</Route> </Route>
</Switch> </Switch>
......
import React from 'react' import React from "react";
import Signin from '../auth/Signin' import Signin from "../auth/Signin";
import { useAuth } from "../auth/auth-context" import { useAuth } from "../auth/auth-context";
import Warning from './Warning' import Warning from "./Warning";
function Home() { function Home() {
const { authUser } = useAuth() const { authUser } = useAuth();
return ( return <div>{authUser ? <Warning /> : <Signin />}</div>;
<div>
{authUser ? <Warning/>:<Signin />}
</div>
)
} }
export default Home;
export default Home
import React, { useState } from "react" import React, { useState } from "react";
import { useAuth } from "../auth/auth-context" import { useAuth } from "../auth/auth-context";
import Form from "react-bootstrap/Form"; import Form from "react-bootstrap/Form";
import Container from "react-bootstrap/Container"; import Container from "react-bootstrap/Container";
import { read as readUser } from '../user/api-user'; import { read as readUser } from "../user/api-user";
import { list, read as readCourse } from '../course/api-course'; import { list, read as readCourse } from "../course/api-course";
import { useEffect } from "react"; import { useEffect } from "react";
import Card from "react-bootstrap/esm/Card"; import Card from "react-bootstrap/esm/Card";
import { Link, Redirect } from 'react-router-dom'; import { Link, Redirect } from "react-router-dom";
function Warning() { function Warning() {
const [data, setData] = useState({ name: "", }) const [data, setData] = useState({ name: "" });
const [courses, setCourses] = useState([{ name: "", description: "", code: "", }]) const [courses, setCourses] = useState([
const [values, setValues] = useState({ { name: "", description: "", code: "" },
title: "", ]);
problems: [], const [values, setValues] = useState({
show: false, title: "",
startAt: "", problems: [],
endAt: "", show: false,
course: "", startAt: "",
}); endAt: "",
const { authUser } = useAuth() course: "",
});
useEffect(() => { const { authUser } = useAuth();
const abortController = new AbortController()
const signal = abortController.signal
readUser(authUser.user._id, { t: authUser.token }).then(res => {
setData(res);
})
list(signal).then(res => {
setCourses(res)
})
}, []);
const handleChange = (event) => { useEffect(() => {
const { name, value } = event.target; const abortController = new AbortController();
console.log("name", name, "value", value); const signal = abortController.signal;
console.log("values:", values); readUser(authUser.user._id, { t: authUser.token }).then((res) => {
setData(res);
});
list(signal).then((res) => {
setCourses(res);
});
}, []);
if (name === "course") { const handleChange = (event) => {
console.log(`${name}: ${courses[value]._id}`); const { name, value } = event.target;
setValues({ ...values, [name]: courses[value]._id }); console.log("name", name, "value", value);
} else { console.log("values:", values);
setValues({ ...values, [name]: value });
}
};
return (
<div>
<Container className="col-sm-6 col-md-5 col-lg-4 p-5">
<Form.Text className="text-muted">
<h1 className="text-center mt-1 pb-3 font-italic text-danger">Korea University</h1>
<Card className="p-3 ">
<h4 className='card-title mb-4'>응시자 정보 </h4>
<p className="ml-2">이름 : {data.name}</p>
<p className="ml-2">e-mail : {data.email}</p>
<p className="ml-2"> <div className="mb-2">[수강과목]</div> {courses.map((course) => (<div>{course.name} ({course.description}교수님) </div>))} </p>
{/* <p className="ml-2"> {courses.map((courses)=>(courses.name +':'+ courses.description))}</p> */}
<div className="mt-3 text-left">과목을 선택하세요.</div> if (name === "course") {
<Form.Control console.log(`${name}: ${courses[value]._id}`);
className="mb-4 mt-2" setValues({ ...values, [name]: courses[value]._id });
as="select" } else {
id="course" setValues({ ...values, [name]: value });
name="course" }
onChange={handleChange} };
> return (
<div>
<Container className="col-sm-6 col-md-5 col-lg-4 p-5">
<Form.Text className="text-muted">
<h1 className="text-center mt-1 pb-3 font-italic text-danger">
Korea University
</h1>
<Card className="p-3 ">
<h4 className="card-title mb-4">응시자 정보 </h4>
<p className="ml-2">이름 : {data.name}</p>
<p className="ml-2">e-mail : {data.email}</p>
<p className="ml-2">
{" "}
<div className="mb-2">[수강과목]</div>{" "}
{courses.map((course) => (
<div>
{course.name} ({course.description}교수님){" "}
</div>
))}{" "}
</p>
{/* <p className="ml-2"> {courses.map((courses)=>(courses.name +':'+ courses.description))}</p> */}
{courses.map((course, i) => ( <div className="mt-3 text-left">과목을 선택하세요.</div>
<option key={i} value={i}> <Form.Control
{course.name} className="mb-4 mt-2"
</option> as="select"
))} id="course"
</Form.Control> name="course"
<div className="text-right"> onChange={handleChange}
<Link to="/problems"> >
<a className="btn btn-danger">Quiz Start</a> {courses.map((course, i) => (
</Link> <option key={i} value={i}>
{/* <a href="#" class="card-link">Another link</a> */} {course.name}
</div> </option>
{/* <p>시험문제 수 :</p> ))}
</Form.Control>
<div className="text-right">
<Link to={`/problems/${authUser.user._id}`}>
<a className="btn btn-danger">Quiz Start</a>
</Link>
{/* <a href="#" class="card-link">Another link</a> */}
</div>
{/* <p>시험문제 수 :</p>
<p>시험 시간 : </p> <p>시험 시간 : </p>
<p>공지 사항 : </p> */} <p>공지 사항 : </p> */}
</Card> </Card>
</Form.Text>
</Form.Text> </Container>
</Container> </div>
</div> );
)
} }
export default Warning export default Warning;
\ No newline at end of file
...@@ -129,7 +129,7 @@ import Button from "react-bootstrap/Button"; ...@@ -129,7 +129,7 @@ import Button from "react-bootstrap/Button";
import { listByUserId } from "./api-quiz"; import { listByUserId } from "./api-quiz";
import authHelpers from "../auth/auth-helpers"; import authHelpers from "../auth/auth-helpers";
function Problem({ problem, number, onUpdate, onRemove }) { function Problems({ problem, number, onUpdate, onRemove }) {
const { userId } = useParams(); const { userId } = useParams();
const [quizzes, setQuizzes] = useState([]); const [quizzes, setQuizzes] = useState([]);
...@@ -199,4 +199,4 @@ function Problem({ problem, number, onUpdate, onRemove }) { ...@@ -199,4 +199,4 @@ function Problem({ problem, number, onUpdate, onRemove }) {
); );
} }
export default Problem; export default Problems;
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