Toggle navigation
Toggle navigation
This project
Loading...
Sign in
HyeonJun Jeon
/
Extended-Calendar
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
HyeonJun Jeon
2022-05-27 14:26:51 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b3773d42365c1a41f609cdeb2583e5738bc51434
b3773d42
1 parent
d23b79d6
[Style] Change Context type from array to object
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
6 deletions
src/components/GridItem.js
src/components/Header.js
src/pages/Calendar.js
src/components/GridItem.js
View file @
b3773d4
...
...
@@ -3,7 +3,7 @@ import { CalendarStateContext } from "../pages/Calendar";
import
{
toYMD
}
from
"../utils/Dates"
;
const
GridItem
=
({
targetDate
})
=>
{
const
[
state
]
=
useContext
(
CalendarStateContext
);
const
{
state
}
=
useContext
(
CalendarStateContext
);
const
{
month
}
=
toYMD
(
state
.
date
);
const
{
month
:
tmonth
,
date
:
tdate
}
=
toYMD
(
targetDate
);
...
...
src/components/Header.js
View file @
b3773d4
...
...
@@ -5,7 +5,7 @@ import "../styles/Header.css";
import
{
moveDate
,
toYMD
}
from
"../utils/Dates"
;
const
Header
=
()
=>
{
const
[
state
,
setState
]
=
useContext
(
CalendarStateContext
);
const
{
state
,
setState
}
=
useContext
(
CalendarStateContext
);
const
{
year
,
month
,
date
}
=
toYMD
(
state
.
date
);
const
navigate
=
useNavigate
();
...
...
src/pages/Calendar.js
View file @
b3773d4
import
React
,
{
useState
}
from
"react"
;
import
{
Navigate
,
Route
,
Routes
}
from
"react-router-dom"
;
import
Grid
from
"../components/Grid
"
;
import
Month
from
"../components/Month
"
;
import
Header
from
"../components/Header"
;
import
"../styles/Home.css"
;
import
Side
from
"../components/Side"
;
import
Subject
from
"../utils/Subject"
;
export
const
CalendarStateContext
=
React
.
createContext
();
...
...
@@ -17,17 +18,40 @@ const Calendar = () => {
date
:
new
Date
(),
});
if
(
!
localStorage
.
getItem
(
"Subjects"
))
{
let
tsubs
=
[];
let
tcolors
=
[
"red"
,
"green"
,
"blue"
,
"orange"
,
"gold"
,
"aqua"
,
"chartreuse"
,
];
for
(
let
i
=
0
;
i
<
7
;
i
++
)
{
tsubs
.
push
(
new
Subject
(
"과목"
+
(
i
+
1
),
tcolors
[
i
],
true
));
}
localStorage
.
setItem
(
"Subjects"
,
JSON
.
stringify
(
tsubs
));
}
const
[
subs
,
setSubs
]
=
useState
(
JSON
.
parse
(
localStorage
.
getItem
(
"Subjects"
))
);
return
(
<
CalendarStateContext
.
Provider
value
=
{
[
state
,
setState
]
}
>
<
CalendarStateContext
.
Provider
value
=
{
{
state
,
setState
,
subs
,
setSubs
}
}
>
{
session
?
(
<
div
className
=
"Calendar"
>
<
Header
/>
<
div
className
=
"content"
>
<
Side
/>
<
Routes
>
<
Route
path
=
"/month/*"
element
=
{
<
Grid
/>
}
/
>
<
Route
path
=
"/month/*"
element
=
{
<
Month
/>
}
/
>
<
Route
path
=
"/week/*"
element
=
{
<><
/>} /
>
<
Route
path
=
"/day/*"
element
=
{
<><
/>} /
>
<
/Routes
>
<
/div
>
<
/div
>
)
:
(
<
Navigate
to
=
"/login"
/>
)}
...
...
Please
register
or
login
to post a comment