StudyPlanList.js 1.39 KB
Newer Older
Choi Ga Young's avatar
Choi Ga Young committed
1
import { useState, useEffect } from 'react';
Choi Ga Young's avatar
Choi Ga Young committed
2
import { Link } from "react-router-dom";
Kim, Subin's avatar
Kim, Subin committed
3
4
import StudyPlanCard from "./Card/StudyPlanCard";
import subjectApi from '../apis/subject.api';
Kim, Subin's avatar
Kim, Subin committed
5
6
import catchErrors from "../utils/catchErrors";
import { useAuth } from "../utils/context";
Choi Ga Young's avatar
Choi Ga Young committed
7
import styles from "./StudyPlan/studyplan.module.scss";
Choi Ga Young's avatar
Choi Ga Young committed
8
9

const StudyPlanList = () => {
Choi Ga Young's avatar
Choi Ga Young committed
10
  const { user } = useAuth();
Kim, Subin's avatar
Kim, Subin committed
11
12
  const [renList, setRenList] = useState([])
  const [error, setError] = useState("")
Choi Ga Young's avatar
Choi Ga Young committed
13

Choi Ga Young's avatar
Choi Ga Young committed
14
15
16
17
  useEffect(() => {
    getList(user.id);
  }, [])

Kim, Subin's avatar
Kim, Subin committed
18
19
20
21
22
23
24
25
  async function getList(userId) {
    try {
      setError("")
      const result = await subjectApi.allSubject(userId)
      setRenList(result)
    } catch (error) {
      catchErrors(error, setError)
    }
Choi Ga Young's avatar
Choi Ga Young committed
26
  }
Kim, Subin's avatar
Kim, Subin committed
27

Choi Ga Young's avatar
Choi Ga Young committed
28
  return (
Choi Ga Young's avatar
Choi Ga Young committed
29
    <div className={`mt-4 ${styles.list}`}>
Kim, Subin's avatar
Kim, Subin committed
30
31
      <div className="d-flex flex-column align-items-center">
        {renList.length !== 0 ? renList.map((info, idx) => <StudyPlanCard key={idx} renList={info} />) : null}
Kim, Subin's avatar
Kim, Subin committed
32
33
        <Link className="card text-decoration-none link-dark" to="/subject/edit" style={{ width: "20rem" }}>
          <div className="card-body d-flex flex-column bg-secondary bg-opacity-25">
Kim, Subin's avatar
Kim, Subin committed
34
35
            <i className="bi bi-plus-lg d-flex justify-content-center fs-3"></i>
            <p className="card-text mt-2 text-center">새로운 과목 추가하기</p>
Choi Ga Young's avatar
Choi Ga Young committed
36
37
38
          </div>
        </Link>
      </div>
Choi Ga Young's avatar
Choi Ga Young committed
39
    </div>
Choi Ga Young's avatar
Choi Ga Young committed
40
41
42
43
  )
}

export default StudyPlanList;