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-30 20:24:32 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e96ffc60614c0817f3e32b604fad6e26f3baaa87
e96ffc60
1 parent
6f623eab
[Modify] All storages to localForage
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
53 additions
and
31 deletions
README.md
src/components/Header.js
src/pages/Calendar.js
src/pages/Home.js
src/pages/Login.js
src/pages/Settings.js
src/utils/LocalForage.js
src/utils/Test.js
README.md
View file @
e96ffc6
...
...
@@ -6,7 +6,7 @@
-
Front-End : React
-
Back-End : Node.js
-
Storage : Local
Storage, Local
Forage
-
Storage : LocalForage
-
Crawl : Puppeteer
<br>
...
...
src/components/Header.js
View file @
e96ffc6
import
{
useContext
}
from
"react"
;
import
{
useNavigate
}
from
"react-router-dom"
;
import
{
CalendarStateContext
}
from
"../pages/Calendar"
;
import
"../styles/Header.css"
;
import
{
moveDate
,
toYMD
}
from
"../utils/Dates"
;
import
{
dataForage
}
from
"../utils/LocalForage"
;
const
Header
=
()
=>
{
const
{
state
,
setState
}
=
useContext
(
CalendarStateContext
);
...
...
@@ -90,8 +92,8 @@ const Header = () => {
<
/div
>
<
button
className
=
"hrb_r"
onClick
=
{()
=>
{
localSt
orage
.
setItem
(
"session"
,
""
);
onClick
=
{
async
()
=>
{
await
dataF
orage
.
setItem
(
"session"
,
""
);
navigate
(
"/"
);
}}
>
...
...
src/pages/Calendar.js
View file @
e96ffc6
import
React
,
{
useEffect
,
useReducer
,
useState
}
from
"react"
;
import
{
Navigate
,
Route
,
Routes
}
from
"react-router-dom"
;
import
{
useNavigate
,
Route
,
Routes
}
from
"react-router-dom"
;
import
{
initTempSubjects
}
from
"../utils/Test"
;
import
{
dataForage
,
subForage
}
from
"../utils/LocalForage"
;
import
Month
from
"../components/Month"
;
import
Header
from
"../components/Header"
;
import
Side
from
"../components/Side"
;
import
{
initTempSubjects
}
from
"../utils/Test"
;
import
{
subForage
}
from
"../utils/LocalForage"
;
export
const
CalendarStateContext
=
React
.
createContext
();
...
...
@@ -26,32 +27,35 @@ const render = (subsObj, args) => {
const
Calendar
=
()
=>
{
console
.
log
(
"visit Calendar"
);
const
session
=
localStorage
.
getItem
(
"session"
);
const
[
state
,
setState
]
=
useState
({
scope
:
"month"
,
date
:
new
Date
(),
});
const
[
subsObj
,
dispatch
]
=
useReducer
(
render
,
{});
const
navigate
=
useNavigate
();
useEffect
(()
=>
{
async
function
checkSession
()
{
if
(
!
(
await
dataForage
.
getItem
(
"session"
)))
navigate
(
"/login"
);
}
async
function
initSubsObj
()
{
if
(
!
localStorage
.
getItem
(
"Subjects"
))
await
initTempSubjects
();
const
subCodeLst
=
JSON
.
parse
(
localStorage
.
getItem
(
"Subjects"
));
if
(
!
(
await
dataForage
.
getItem
(
"Subjects"
)))
await
initTempSubjects
();
let
tsubsObj
=
{};
for
(
const
code
of
subCodeLst
)
{
for
(
const
code
of
await
dataForage
.
getItem
(
"Subjects"
)
)
{
tsubsObj
[
code
]
=
await
subForage
.
getItem
(
code
);
}
dispatch
({
type
:
"INIT"
,
subsObj
:
tsubsObj
});
}
checkSession
();
initSubsObj
();
},
[]);
},
[
navigate
]);
return
(
<
CalendarStateContext
.
Provider
value
=
{{
state
,
setState
,
subsObj
,
dispatch
}}
>
{
session
?
(
<
div
className
=
"Calendar"
>
<
Header
/>
<
div
className
=
"content"
>
...
...
@@ -63,9 +67,6 @@ const Calendar = () => {
<
/Routes
>
<
/div
>
<
/div
>
)
:
(
<
Navigate
to
=
"/login"
/>
)}
<
/CalendarStateContext.Provider
>
);
};
...
...
src/pages/Home.js
View file @
e96ffc6
import
{
useEffect
}
from
"react"
;
import
{
useNavigate
}
from
"react-router-dom"
;
import
{
dataForage
}
from
"../utils/LocalForage"
;
const
Home
=
()
=>
{
const
session
=
localStorage
.
getItem
(
"session"
);
console
.
log
(
"visit Home"
);
const
navigate
=
useNavigate
();
useEffect
(()
=>
{
async
function
where
()
{
let
destination
;
if
(
session
)
{
if
(
await
dataForage
.
getItem
(
"session"
)
)
{
destination
=
"/calendar/month"
;
}
else
{
destination
=
"/login"
;
}
navigate
(
destination
);
}
const
navigate
=
useNavigat
e
();
useEffect
(()
=>
navigate
(
destination
),
[
destination
,
navigate
]);
wher
e
();
},
[
navigate
]);
};
export
default
Home
;
...
...
src/pages/Login.js
View file @
e96ffc6
import
{
Navigate
,
useNavigate
}
from
"react-router-dom"
;
import
{
useEffect
}
from
"react"
;
import
{
useNavigate
}
from
"react-router-dom"
;
import
{
dataForage
}
from
"../utils/LocalForage"
;
const
Login
=
()
=>
{
console
.
log
(
"visit Login"
);
const
session
=
localStorage
.
getItem
(
"session"
);
const
navigate
=
useNavigate
();
const
login
=
()
=>
{
const
login
=
async
()
=>
{
if
(
true
)
{
//login success
localSt
orage
.
setItem
(
"session"
,
true
);
await
dataF
orage
.
setItem
(
"session"
,
true
);
navigate
(
"/"
);
}
};
return
session
?
(
<
Navigate
to
=
"/"
/>
)
:
(
useEffect
(()
=>
{
async
function
render
()
{
if
(
await
dataForage
.
getItem
(
"session"
))
navigate
(
"/"
);
}
render
();
},
[
navigate
]);
return
(
<
div
className
=
"Login"
>
<
button
onClick
=
{
login
}
>
로그인
<
/button
>
<
/div
>
...
...
src/pages/Settings.js
View file @
e96ffc6
import
{
Navigate
,
useNavigate
}
from
"react-router-dom"
;
import
"../styles/Settings.css"
;
import
{
dataForage
}
from
"../utils/LocalForage"
;
const
Settings
=
()
=>
{
console
.
log
(
"visit Settings"
);
const
session
=
localSt
orage
.
getItem
(
"session"
);
const
session
=
dataF
orage
.
getItem
(
"session"
);
const
navigate
=
useNavigate
();
...
...
src/utils/LocalForage.js
View file @
e96ffc6
...
...
@@ -10,4 +10,9 @@ const scheForage = localforage.createInstance({
storeName
:
"schedules"
,
});
export
{
subForage
,
scheForage
};
const
dataForage
=
localforage
.
createInstance
({
name
:
"localforage"
,
storeName
:
"data"
,
});
export
{
subForage
,
scheForage
,
dataForage
};
...
...
src/utils/Test.js
View file @
e96ffc6
import
{
subForage
,
scheForage
}
from
"./LocalForage"
;
import
{
subForage
,
scheForage
,
dataForage
}
from
"./LocalForage"
;
const
initTempSubjects
=
async
()
=>
{
scheForage
.
setItem
(
"20220503"
,
[
...
...
@@ -42,7 +42,7 @@ const initTempSubjects = async () => {
subCodeLst
.
push
(
code
);
await
subForage
.
setItem
(
code
,
tsub
);
}
localStorage
.
setItem
(
"Subjects"
,
JSON
.
stringify
(
subCodeLst
)
);
dataForage
.
setItem
(
"Subjects"
,
subCodeLst
);
};
export
{
initTempSubjects
};
...
...
Please
register
or
login
to post a comment