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 22:44:36 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f79b53f6d359306f2db4b718cc0d730c17bc718a
f79b53f6
1 parent
3490187f
[Add] Pages for login, setting
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
101 additions
and
7 deletions
src/App.js
src/components/Header.js
src/pages/Calendar.js
src/pages/Home.js
src/pages/Login.js
src/pages/Settings.js
src/styles/Header.css
src/App.js
View file @
f79b53f
import
"./styles/App.css"
;
import
{
BrowserRouter
,
Route
,
Routes
}
from
"react-router-dom"
;
import
React
from
"react"
;
import
"./styles/App.css"
;
import
Calendar
from
"./pages/Calendar"
;
import
Home
from
"./pages/Home"
;
import
Login
from
"./pages/Login"
;
import
Settings
from
"./pages/Settings"
;
export
const
AppStateContext
=
React
.
createContext
();
function
App
()
{
return
(
<
BrowserRouter
>
<
AppStateContext
.
Provider
value
=
{[]}
>
<
div
className
=
"App"
>
<
Routes
>
<
Route
path
=
"/calendar/*"
element
=
{
<
Calendar
/>
}
/
>
<
Route
exact
path
=
"/login"
element
=
{
<><
/>} /
>
<
Route
exact
path
=
"/setting"
element
=
{
<><
/>} /
>
<
Route
path
=
"*"
element
=
{
<
Home
/>
}
/
>
<
Route
path
=
"/calendar/*"
element
=
{
<
Calendar
/>
}
/
>
<
Route
path
=
"/login"
element
=
{
<
Login
/>
}
/
>
<
Route
path
=
"/settings"
element
=
{
<
Settings
/>
}
/
>
<
/Routes
>
<
/div
>
<
/AppStateContext.Provider
>
<
/BrowserRouter
>
);
}
...
...
src/components/Header.js
View file @
f79b53f
...
...
@@ -59,6 +59,9 @@ const Header = () => {
<
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"
}
...
...
@@ -85,6 +88,15 @@ const Header = () => {
월
<
/button
>
<
/div
>
<
button
className
=
"hrb_r"
onClick
=
{()
=>
{
localStorage
.
setItem
(
"session"
,
""
);
navigate
(
"/"
);
}}
>
로그아웃
<
/button
>
<
/div
>
<
/header
>
);
...
...
src/pages/Calendar.js
View file @
f79b53f
import
React
,
{
useState
}
from
"react"
;
import
{
Route
,
Routes
}
from
"react-router-dom"
;
import
{
Navigate
,
Route
,
Routes
}
from
"react-router-dom"
;
import
Grid
from
"../components/Grid"
;
import
Header
from
"../components/Header"
;
...
...
@@ -8,7 +8,10 @@ import "../styles/Home.css";
export
const
CalendarStateContext
=
React
.
createContext
();
const
Calendar
=
()
=>
{
//scope는 day, state는 date
console
.
log
(
"visit Calendar"
);
const
session
=
localStorage
.
getItem
(
"session"
);
const
[
state
,
setState
]
=
useState
({
scope
:
"month"
,
date
:
new
Date
(),
...
...
@@ -16,6 +19,7 @@ const Calendar = () => {
return
(
<
CalendarStateContext
.
Provider
value
=
{[
state
,
setState
]}
>
{
session
?
(
<
div
className
=
"Calendar"
>
<
Header
/>
<
Routes
>
...
...
@@ -24,6 +28,9 @@ const Calendar = () => {
<
Route
path
=
"/day/*"
element
=
{
<><
/>} /
>
<
/Routes
>
<
/div
>
)
:
(
<
Navigate
to
=
"/login"
/>
)}
<
/CalendarStateContext.Provider
>
);
};
...
...
src/pages/Home.js
View file @
f79b53f
...
...
@@ -2,8 +2,18 @@ import { useEffect } from "react";
import
{
useNavigate
}
from
"react-router-dom"
;
const
Home
=
()
=>
{
const
session
=
localStorage
.
getItem
(
"session"
);
console
.
log
(
"visit Home"
);
let
destination
;
if
(
session
)
{
destination
=
"/calendar/month"
;
}
else
{
destination
=
"/login"
;
}
const
navigate
=
useNavigate
();
useEffect
(()
=>
navigate
(
"/calendar/month"
),
[
navigate
]);
useEffect
(()
=>
navigate
(
destination
),
[
destination
,
navigate
]);
};
export
default
Home
;
...
...
src/pages/Login.js
0 → 100644
View file @
f79b53f
import
{
Navigate
,
useNavigate
}
from
"react-router-dom"
;
const
Login
=
()
=>
{
console
.
log
(
"visit Login"
);
const
session
=
localStorage
.
getItem
(
"session"
);
const
navigate
=
useNavigate
();
const
login
=
()
=>
{
if
(
true
)
{
//login success
localStorage
.
setItem
(
"session"
,
true
);
navigate
(
"/"
);
}
};
return
session
?
(
<
Navigate
to
=
"/"
/>
)
:
(
<
div
className
=
"Login"
>
<
button
onClick
=
{
login
}
>
로그인
<
/button
>
<
/div
>
);
};
export
default
Login
;
src/pages/Settings.js
0 → 100644
View file @
f79b53f
import
{
Navigate
,
useNavigate
}
from
"react-router-dom"
;
const
Settings
=
()
=>
{
const
session
=
localStorage
.
getItem
(
"session"
);
const
navigate
=
useNavigate
();
return
session
?
(
<
div
className
=
"Settings"
>
<
button
onClick
=
{()
=>
{
navigate
(
-
1
);
}}
>
{
"<"
}
<
/button
>
<
/div
>
)
:
(
<
Navigate
to
=
"/login"
/>
);
};
export
default
Settings
;
src/styles/Header.css
View file @
f79b53f
...
...
@@ -41,7 +41,16 @@ header {
margin
:
10px
;
}
.hrd
{
margin-right
:
10px
;
margin-left
:
10px
;
}
.hrd
>
button
{
padding
:
8px
14px
8px
14px
;
font-size
:
medium
;
}
.hr
{
display
:
flex
;
}
...
...
Please
register
or
login
to post a comment