HyeonJun Jeon

[Add] Week calendar

1 +import React, { useContext } from "react";
2 +import GridItem from "./GridItem.js";
3 +
4 +import { CalendarStateContext } from "../pages/Calendar";
5 +import { moveDate, toSunday } from "../utils/Dates";
6 +import "../styles/Week.css";
7 +
8 +const GridHead = () => {
9 + const days = ["일", "월", "화", "수", "목", "금", "토"];
10 + const renderItems = () => {
11 + const items = [];
12 + for (let i = 0; i < 7; i++) {
13 + items.push(
14 + <div className="GridHeadItem" key={i}>
15 + {days[i]}
16 + </div>
17 + );
18 + }
19 + return items;
20 + };
21 +
22 + return <div className="GridHead">{renderItems()}</div>;
23 +};
24 +
25 +const Row = () => {
26 + const { state } = useContext(CalendarStateContext);
27 +
28 + const renderItems = () => {
29 + const items = [];
30 + const ndate = new Date(state.date);
31 + toSunday(ndate);
32 +
33 + for (let i = 0; i < 6; i++) {
34 + items.push(<GridItem key={i} targetDate={new Date(ndate)} />);
35 + moveDate(ndate, "day", 1);
36 + }
37 +
38 + return items;
39 + };
40 +
41 + return <div className="Row">{renderItems()}</div>;
42 +};
43 +
44 +const Week = () => {
45 + return (
46 + <div className="Week">
47 + <GridHead />
48 + <Row />
49 + </div>
50 + );
51 +};
52 +
53 +export default Week;
...@@ -6,6 +6,7 @@ import Header from "../components/Header"; ...@@ -6,6 +6,7 @@ import Header from "../components/Header";
6 import Side from "../components/Side"; 6 import Side from "../components/Side";
7 import localforage from "localforage"; 7 import localforage from "localforage";
8 import axios from "axios"; 8 import axios from "axios";
9 +import Week from "../components/Week";
9 10
10 export const CalendarStateContext = React.createContext(); 11 export const CalendarStateContext = React.createContext();
11 12
...@@ -77,7 +78,7 @@ const Calendar = () => { ...@@ -77,7 +78,7 @@ const Calendar = () => {
77 <Side /> 78 <Side />
78 <Routes> 79 <Routes>
79 <Route path="/month/*" element={<Month />} /> 80 <Route path="/month/*" element={<Month />} />
80 - <Route path="/week/*" element={<></>} /> 81 + <Route path="/week/*" element={<Week />} />
81 <Route path="/day/*" element={<></>} /> 82 <Route path="/day/*" element={<></>} />
82 </Routes> 83 </Routes>
83 </div> 84 </div>
......
...@@ -64,7 +64,7 @@ button:disabled { ...@@ -64,7 +64,7 @@ button:disabled {
64 } 64 }
65 65
66 .s_start { 66 .s_start {
67 - color: deepskyblue; 67 + color: blue;
68 /* text-shadow: -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white; */ 68 /* text-shadow: -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white; */
69 } 69 }
70 70
...@@ -87,6 +87,7 @@ button:disabled { ...@@ -87,6 +87,7 @@ button:disabled {
87 left: 20px; 87 left: 20px;
88 background: rgb(246, 246, 246); 88 background: rgb(246, 246, 246);
89 border: solid thin black; 89 border: solid thin black;
90 + border-radius: 5px;
90 display: none; 91 display: none;
91 padding: 10px; 92 padding: 10px;
92 cursor: auto; 93 cursor: auto;
......
1 +.Week {
2 + display: flex;
3 + flex-direction: column;
4 + flex-grow: 1;
5 +}
6 +
7 +.GridItem,
8 +.GridHeadItem {
9 + flex-basis: 100px;
10 + flex-grow: 1;
11 +}
12 +
13 +.GridItem {
14 + border: solid thin lightgray;
15 + display: flex;
16 + flex-direction: column;
17 + /* height: 150px; */
18 + padding: 5px;
19 +}
20 +
21 +.GridHeadItem {
22 + height: 20px;
23 + text-align: center;
24 + line-height: 20px;
25 + padding: 10px 5px 10px 5px;
26 +}
27 +
28 +.GridHead {
29 + display: flex;
30 +}
31 +
32 +.GridHead {
33 + margin-right: 16.8px;
34 +}
35 +
36 +.Row {
37 + display: flex;
38 + overflow-y: auto;
39 + height: calc(100vh - 115px);
40 + border: solid thin gray;
41 +}
42 +
43 +.GridItem[relative] > span {
44 + color: gray;
45 +}