Menu.js 3.75 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
import { useState, useEffect } from "react";
Kim, Subin's avatar
Kim, Subin committed
2
import { Link } from "react-router-dom";
Kim, Subin's avatar
Kim, Subin committed
3
import todoApi from "../../apis/todo.api";
4
import { useAuth } from "../../utils/context.js";
Kim, Subin's avatar
Kim, Subin committed
5
import catchErrors from "../../utils/catchErrors";
Kim, Subin's avatar
Monthly    
Kim, Subin committed
6
import moment from "moment";
7
8
import styles from "./menu.module.scss";

Kim, Subin's avatar
Kim, Subin committed
9
const Menu = () => {
Kim, Subin's avatar
context    
Kim, Subin committed
10
    const { user, logout } = useAuth();
Kim, Subin's avatar
Kim, Subin committed
11
    const [todoList, setTodoList] = useState({ percent: 0, list: [] })
Kim, Subin's avatar
Kim, Subin committed
12
13
14
15
16
17
18
19
20
    const [error, setError] = useState("");

    useEffect(() => {
        todayTodo()
    }, [])

    async function todayTodo() {
        try {
            setError("")
Kim, Subin's avatar
Kim, Subin committed
21
            const result = await todoApi.getTodopercent(user.id, moment().format("YYYY-MM-DD"))
Kim, Subin's avatar
Kim, Subin committed
22
            console.log("client resList",result)
Kim, Subin's avatar
Kim, Subin committed
23
            setTodoList({...todoList, ...result})
Kim, Subin's avatar
Kim, Subin committed
24
25
26
27
        } catch (error) {
            catchErrors(error, setError)
        }
    }
Kim, Subin's avatar
Kim, Subin committed
28

Kim, Subin's avatar
Kim, Subin committed
29
    return (
30
31
32
33
34
        <>
            <button className="btn btn-crimson shadow-none mt-2" type="button" data-bs-toggle="collapse" data-bs-target="#menuContent" aria-controls="menuContent" aria-expanded="false" aria-label="menu">
                <i className="bi bi-list fs-4"></i>
            </button>
            <div className={`collapse collapse-horizontal position-absolute top-0 start-0 h-100 ${styles.content}`} id="menuContent">
Kim, Subin's avatar
Kim, Subin committed
35
36
37
                <div className="d-flex flex-column" style={{ transition: ".15s ease", height: "inherit" }}>
                    <button type="button" className={`btn-close btn-close-white btn-lg position-absolute ${styles.close}`} data-bs-toggle="collapse" data-bs-target="#menuContent" aria-controls="menuContent" aria-expanded="true" aria-label="menu"></button>
                    <div className="d-flex flex-column align-items-center text-white py-5" style={{ backgroundColor: "crimson" }}>
Kim, Subin's avatar
context    
Kim, Subin committed
38
                        <h1 className="my-3">{user.name} </h1>
Kim, Subin's avatar
Kim, Subin committed
39
                        <h2 className="my-2">오늘의 목표 {todoList.percent}% 달성!</h2>
Kim, Subin's avatar
Kim, Subin committed
40
                    </div>
Kim, Subin's avatar
Kim, Subin committed
41
42
                    <div className="d-flex flex-column justify-content-between flex-grow-1 py-4 ps-3 text-dark" >
                        <div className="user-select-none w-75 ps-3">
Kim, Subin's avatar
Kim, Subin committed
43
44
45
46
47
                            <h2 className="mb-4">To-do</h2>
                            {todoList.list.length!==0 ? todoList.list.map((todo, idx) => {
                                if (idx <= 2) return <div className="d-flex">
                                <p className={`form-check-label border-bottom border-2 fs-5 pb-1 me-3 ${styles.title}`}>{todo.title}</p>
                                <input className={`form-check-input rounded-0 border-dark shadow-none mt-1 ${styles.checkBox}`} type="checkbox" id="inlineCheckbox1" aria-label="checkbox" checked={todo.done} />
Kim, Subin's avatar
Kim, Subin committed
48
                            </div>
Kim, Subin's avatar
Kim, Subin committed
49
                            }) : null}
Kim, Subin's avatar
Kim, Subin committed
50
                            <Link className="d-flex justify-content-center text-dark text-decoration-none" to={`/todo/${moment().format("YYYY-MM-DD")}`}>
Kim, Subin's avatar
Kim, Subin committed
51
52
53
54
55
                                <i className="bi bi-plus-lg me-2"></i>
                                <p className="mb-0">더보기</p>
                            </Link>
                        </div>
                        <div className="d-flex flex-column">
Kim, Subin's avatar
Monthly    
Kim, Subin committed
56
                            <Link className="text-dark text-decoration-none" to={`/schedule/${moment().format("YYYY-MM-DD")}`}><i className="bi bi-check"></i>일정</Link>
Kim, Subin's avatar
Kim, Subin committed
57
58
                            <Link className="text-dark text-decoration-none" to="/studyplan"><i className="bi bi-check"></i>학업별 계획</Link>
                        </div>
59
                        <p className={`position-absolute bottom-0 text-dark ${styles.logout}`} onClick={logout}>로그아웃</p>
Kim, Subin's avatar
Kim, Subin committed
60
61
                    </div>
                </div>
62
63
            </div>
        </>
Kim, Subin's avatar
Kim, Subin committed
64
65
66
67
    )
}

export default Menu