Showing
3 changed files
with
30 additions
and
6 deletions
... | @@ -3,7 +3,7 @@ import { CalendarStateContext } from "../pages/Calendar"; | ... | @@ -3,7 +3,7 @@ import { CalendarStateContext } from "../pages/Calendar"; |
3 | import { toYMD } from "../utils/Dates"; | 3 | import { toYMD } from "../utils/Dates"; |
4 | 4 | ||
5 | const GridItem = ({ targetDate }) => { | 5 | const GridItem = ({ targetDate }) => { |
6 | - const [state] = useContext(CalendarStateContext); | 6 | + const { state } = useContext(CalendarStateContext); |
7 | const { month } = toYMD(state.date); | 7 | const { month } = toYMD(state.date); |
8 | const { month: tmonth, date: tdate } = toYMD(targetDate); | 8 | const { month: tmonth, date: tdate } = toYMD(targetDate); |
9 | 9 | ... | ... |
... | @@ -5,7 +5,7 @@ import "../styles/Header.css"; | ... | @@ -5,7 +5,7 @@ import "../styles/Header.css"; |
5 | import { moveDate, toYMD } from "../utils/Dates"; | 5 | import { moveDate, toYMD } from "../utils/Dates"; |
6 | 6 | ||
7 | const Header = () => { | 7 | const Header = () => { |
8 | - const [state, setState] = useContext(CalendarStateContext); | 8 | + const { state, setState } = useContext(CalendarStateContext); |
9 | const { year, month, date } = toYMD(state.date); | 9 | const { year, month, date } = toYMD(state.date); |
10 | 10 | ||
11 | const navigate = useNavigate(); | 11 | const navigate = useNavigate(); | ... | ... |
1 | import React, { useState } from "react"; | 1 | import React, { useState } from "react"; |
2 | import { Navigate, Route, Routes } from "react-router-dom"; | 2 | import { Navigate, Route, Routes } from "react-router-dom"; |
3 | 3 | ||
4 | -import Grid from "../components/Grid"; | 4 | +import Month from "../components/Month"; |
5 | import Header from "../components/Header"; | 5 | import Header from "../components/Header"; |
6 | -import "../styles/Home.css"; | 6 | +import Side from "../components/Side"; |
7 | +import Subject from "../utils/Subject"; | ||
7 | 8 | ||
8 | export const CalendarStateContext = React.createContext(); | 9 | export const CalendarStateContext = React.createContext(); |
9 | 10 | ||
... | @@ -17,17 +18,40 @@ const Calendar = () => { | ... | @@ -17,17 +18,40 @@ const Calendar = () => { |
17 | date: new Date(), | 18 | date: new Date(), |
18 | }); | 19 | }); |
19 | 20 | ||
21 | + if (!localStorage.getItem("Subjects")) { | ||
22 | + let tsubs = []; | ||
23 | + let tcolors = [ | ||
24 | + "red", | ||
25 | + "green", | ||
26 | + "blue", | ||
27 | + "orange", | ||
28 | + "gold", | ||
29 | + "aqua", | ||
30 | + "chartreuse", | ||
31 | + ]; | ||
32 | + for (let i = 0; i < 7; i++) { | ||
33 | + tsubs.push(new Subject("과목" + (i + 1), tcolors[i], true)); | ||
34 | + } | ||
35 | + localStorage.setItem("Subjects", JSON.stringify(tsubs)); | ||
36 | + } | ||
37 | + const [subs, setSubs] = useState( | ||
38 | + JSON.parse(localStorage.getItem("Subjects")) | ||
39 | + ); | ||
40 | + | ||
20 | return ( | 41 | return ( |
21 | - <CalendarStateContext.Provider value={[state, setState]}> | 42 | + <CalendarStateContext.Provider value={{ state, setState, subs, setSubs }}> |
22 | {session ? ( | 43 | {session ? ( |
23 | <div className="Calendar"> | 44 | <div className="Calendar"> |
24 | <Header /> | 45 | <Header /> |
46 | + <div className="content"> | ||
47 | + <Side /> | ||
25 | <Routes> | 48 | <Routes> |
26 | - <Route path="/month/*" element={<Grid />} /> | 49 | + <Route path="/month/*" element={<Month />} /> |
27 | <Route path="/week/*" element={<></>} /> | 50 | <Route path="/week/*" element={<></>} /> |
28 | <Route path="/day/*" element={<></>} /> | 51 | <Route path="/day/*" element={<></>} /> |
29 | </Routes> | 52 | </Routes> |
30 | </div> | 53 | </div> |
54 | + </div> | ||
31 | ) : ( | 55 | ) : ( |
32 | <Navigate to="/login" /> | 56 | <Navigate to="/login" /> |
33 | )} | 57 | )} | ... | ... |
-
Please register or login to post a comment