Header.js
2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { useContext } from "react";
import { useNavigate } from "react-router-dom";
import { CalendarStateContext } from "../pages/Calendar";
import "../styles/Header.css";
import { moveDate, toYMD } from "../utils/Dates";
const Header = () => {
const [state, setState] = useContext(CalendarStateContext);
const { year, month, date } = toYMD(state.date);
const navigate = useNavigate();
const setScope = (e) => {
setState({
...state,
[e.target.name]: e.target.value,
});
navigate("/calendar/" + e.target.value);
};
const move = (e) => {
const current = new Date(state.date);
moveDate(current, state.scope, Number(e.target.value));
setState({ scope: state.scope, date: current });
};
let headLabel;
switch (state.scope) {
case "month":
case "week":
headLabel = year + "년 " + month + "월";
break;
case "day":
headLabel = year + "년 " + month + "월 " + date + "일";
break;
default:
headLabel = "unexpected scope";
}
return (
<header>
<div className="hl">
<span className="hls">확장 캘린더</span>
</div>
<div className="hc">
<button
className="hcb"
onClick={() => setState({ scope: state.scope, date: new Date() })}
>
오늘
</button>
<div className="hcd">
<button onClick={move} value={-1}>
{"ᐸ"}
</button>
<button onClick={move} value={+1}>
{"ᐳ"}
</button>
</div>
<span className="hcs">{headLabel}</span>
</div>
<div className="hr">
<button className="hrb_l" onClick={() => navigate("/settings")}>
설정
</button>
<div className="hrd">
<button
disabled={state.scope === "day"}
onClick={setScope}
name="scope"
value="day"
>
일
</button>
<button
disabled={state.scope === "week"}
onClick={setScope}
name="scope"
value="week"
>
주
</button>
<button
disabled={state.scope === "month"}
onClick={setScope}
name="scope"
value="month"
>
월
</button>
</div>
<button
className="hrb_r"
onClick={() => {
localStorage.setItem("session", "");
navigate("/");
}}
>
로그아웃
</button>
</div>
</header>
);
};
export default Header;