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-26 20:16:58 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3490187f00f05a2f9a0f04c1859b53c66786d6a2
3490187f
1 parent
8510a5ef
[Style] Set state type from int to Date
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
19 deletions
src/components/Grid.js
src/components/GridItem.js
src/components/GridRow.js
src/components/Header.js
src/pages/Calendar.js
src/components/Grid.js
View file @
3490187
...
...
@@ -4,18 +4,19 @@ import GridRow from "./GridRow.js";
import
React
,
{
useContext
}
from
"react"
;
import
{
CalendarStateContext
}
from
"../pages/Calendar"
;
import
{
moveDate
,
toSunday
,
toYMD
}
from
"../utils/Dates"
;
import
{
moveDate
,
toSunday
}
from
"../utils/Dates"
;
const
Grid
=
()
=>
{
const
[
state
]
=
useContext
(
CalendarStateContext
);
const
renderRows
=
()
=>
{
const
rows
=
[];
const
ndate
=
new
Date
(
state
.
year
,
state
.
month
-
1
,
1
);
const
ndate
=
new
Date
(
state
.
date
);
ndate
.
setDate
(
1
);
toSunday
(
ndate
);
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
rows
.
push
(
<
GridRow
key
=
{
i
}
startDate
=
{
toYMD
(
ndate
)}
/>
)
;
rows
.
push
(
<
GridRow
key
=
{
i
}
startDate
=
{
new
Date
(
ndate
)}
/>
)
;
moveDate
(
ndate
,
"week"
,
1
);
}
...
...
src/components/GridItem.js
View file @
3490187
import
{
useContext
}
from
"react"
;
import
{
CalendarStateContext
}
from
"../pages/Calendar"
;
import
{
toYMD
}
from
"../utils/Dates"
;
const
GridItem
=
({
targetDate
})
=>
{
const
[
state
]
=
useContext
(
CalendarStateContext
);
const
{
month
,
date
}
=
targetDate
;
const
{
month
}
=
toYMD
(
state
.
date
);
const
{
month
:
tmonth
,
date
:
tdate
}
=
toYMD
(
targetDate
);
const
displayDate
=
()
=>
{
if
(
state
.
month
!==
month
)
return
month
+
"/"
+
date
;
else
return
date
;
if
(
month
!==
tmonth
)
return
tmonth
+
"/"
+
t
date
;
else
return
t
date
;
};
return
(
<
div
className
=
"GridItem"
relative
=
{
month
-
state
.
month
||
null
}
>
<
div
className
=
"GridItem"
relative
=
{
tmonth
-
month
||
null
}
>
<
span
>
{
displayDate
()}
<
/span
>
<
/div
>
);
...
...
src/components/GridRow.js
View file @
3490187
import
{
moveDate
,
toYMD
}
from
"../utils/Dates"
;
import
{
moveDate
}
from
"../utils/Dates"
;
import
GridItem
from
"./GridItem"
;
const
GridRow
=
({
startDate
})
=>
{
const
{
year
,
month
,
date
}
=
startDate
;
const
renderItems
=
()
=>
{
const
items
=
[];
const
ndate
=
new
Date
(
year
,
month
-
1
,
d
ate
);
const
ndate
=
new
Date
(
startD
ate
);
for
(
let
i
=
0
;
i
<
7
;
i
++
)
{
items
.
push
(
<
GridItem
key
=
{
i
}
targetDate
=
{
toYMD
(
ndate
)}
/>
)
;
items
.
push
(
<
GridItem
key
=
{
i
}
targetDate
=
{
new
Date
(
ndate
)}
/>
)
;
moveDate
(
ndate
,
"day"
,
1
);
}
...
...
src/components/Header.js
View file @
3490187
...
...
@@ -6,6 +6,7 @@ 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
)
=>
{
...
...
@@ -17,19 +18,19 @@ const Header = () => {
};
const
move
=
(
e
)
=>
{
const
current
=
new
Date
(
state
.
year
,
state
.
month
-
1
,
state
.
date
);
const
current
=
new
Date
(
state
.
date
);
moveDate
(
current
,
state
.
scope
,
Number
(
e
.
target
.
value
));
setState
({
scope
:
state
.
scope
,
...
toYMD
(
current
)
});
setState
({
scope
:
state
.
scope
,
date
:
current
});
};
let
headLabel
;
switch
(
state
.
scope
)
{
case
"month"
:
case
"week"
:
headLabel
=
state
.
year
+
"년 "
+
state
.
month
+
"월"
;
headLabel
=
year
+
"년 "
+
month
+
"월"
;
break
;
case
"day"
:
headLabel
=
state
.
year
+
"년 "
+
state
.
month
+
"월 "
+
state
.
date
+
"일"
;
headLabel
=
year
+
"년 "
+
month
+
"월 "
+
date
+
"일"
;
break
;
default
:
headLabel
=
"unexpected scope"
;
...
...
@@ -43,7 +44,7 @@ const Header = () => {
<
div
className
=
"hc"
>
<
button
className
=
"hcb"
onClick
=
{()
=>
setState
({
scope
:
state
.
scope
,
...
toYMD
(
new
Date
()
)
})}
onClick
=
{()
=>
setState
({
scope
:
state
.
scope
,
date
:
new
Date
(
)
})}
>
오늘
<
/button
>
...
...
src/pages/Calendar.js
View file @
3490187
...
...
@@ -4,7 +4,6 @@ import { Route, Routes } from "react-router-dom";
import
Grid
from
"../components/Grid"
;
import
Header
from
"../components/Header"
;
import
"../styles/Home.css"
;
import
{
toYMD
}
from
"../utils/Dates"
;
export
const
CalendarStateContext
=
React
.
createContext
();
...
...
@@ -12,7 +11,7 @@ const Calendar = () => {
//scope는 day, state는 date
const
[
state
,
setState
]
=
useState
({
scope
:
"month"
,
...
toYMD
(
new
Date
()
),
date
:
new
Date
(
),
});
return
(
...
...
Please
register
or
login
to post a comment