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>
......
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([
{ name: "", description: "", code: "" },
]);
const [values, setValues] = useState({ const [values, setValues] = useState({
title: "", title: "",
problems: [], problems: [],
...@@ -19,20 +21,19 @@ function Warning() { ...@@ -19,20 +21,19 @@ function Warning() {
endAt: "", endAt: "",
course: "", course: "",
}); });
const { authUser } = useAuth() const { authUser } = useAuth();
useEffect(() => { useEffect(() => {
const abortController = new AbortController() const abortController = new AbortController();
const signal = abortController.signal const signal = abortController.signal;
readUser(authUser.user._id, { t: authUser.token }).then(res => { readUser(authUser.user._id, { t: authUser.token }).then((res) => {
setData(res); setData(res);
}) });
list(signal).then(res => { list(signal).then((res) => {
setCourses(res) setCourses(res);
}) });
}, []); }, []);
const handleChange = (event) => { const handleChange = (event) => {
const { name, value } = event.target; const { name, value } = event.target;
console.log("name", name, "value", value); console.log("name", name, "value", value);
...@@ -49,12 +50,22 @@ function Warning() { ...@@ -49,12 +50,22 @@ function Warning() {
<div> <div>
<Container className="col-sm-6 col-md-5 col-lg-4 p-5"> <Container className="col-sm-6 col-md-5 col-lg-4 p-5">
<Form.Text className="text-muted"> <Form.Text className="text-muted">
<h1 className="text-center mt-1 pb-3 font-italic text-danger">Korea University</h1> <h1 className="text-center mt-1 pb-3 font-italic text-danger">
Korea University
</h1>
<Card className="p-3 "> <Card className="p-3 ">
<h4 className='card-title mb-4'>응시자 정보 </h4> <h4 className="card-title mb-4">응시자 정보 </h4>
<p className="ml-2">이름 : {data.name}</p> <p className="ml-2">이름 : {data.name}</p>
<p className="ml-2">e-mail : {data.email}</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">
{" "}
<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> */} {/* <p className="ml-2"> {courses.map((courses)=>(courses.name +':'+ courses.description))}</p> */}
<div className="mt-3 text-left">과목을 선택하세요.</div> <div className="mt-3 text-left">과목을 선택하세요.</div>
...@@ -65,7 +76,6 @@ function Warning() { ...@@ -65,7 +76,6 @@ function Warning() {
name="course" name="course"
onChange={handleChange} onChange={handleChange}
> >
{courses.map((course, i) => ( {courses.map((course, i) => (
<option key={i} value={i}> <option key={i} value={i}>
{course.name} {course.name}
...@@ -73,7 +83,7 @@ function Warning() { ...@@ -73,7 +83,7 @@ function Warning() {
))} ))}
</Form.Control> </Form.Control>
<div className="text-right"> <div className="text-right">
<Link to="/problems"> <Link to={`/problems/${authUser.user._id}`}>
<a className="btn btn-danger">Quiz Start</a> <a className="btn btn-danger">Quiz Start</a>
</Link> </Link>
{/* <a href="#" class="card-link">Another link</a> */} {/* <a href="#" class="card-link">Another link</a> */}
...@@ -82,11 +92,10 @@ function Warning() { ...@@ -82,11 +92,10 @@ function Warning() {
<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