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 02:45:30 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
075dca1c8776ff624863196c00f197d32df4b43b
075dca1c
1 parent
a99cd44d
[Style] Separate storage of Subjects and Schedules
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
21 deletions
src/pages/Calendar.js
src/utils/LocalForage.js
src/utils/Test.js
src/pages/Calendar.js
View file @
075dca1
import
React
,
{
useEffect
,
useReducer
,
useState
}
from
"react"
;
import
{
Navigate
,
Route
,
Routes
}
from
"react-router-dom"
;
import
localforage
from
"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
();
...
...
@@ -14,7 +14,7 @@ const render = (subsObj, args) => {
case
"CHECKED"
:
const
sub
=
subsObj
[
args
.
code
];
sub
.
selected
=
!
sub
.
selected
;
localf
orage
.
setItem
(
args
.
code
,
sub
);
subF
orage
.
setItem
(
args
.
code
,
sub
);
return
{
...
subsObj
,
[
args
.
code
]:
sub
};
case
"INIT"
:
return
args
.
subsObj
;
...
...
@@ -40,7 +40,7 @@ const Calendar = () => {
const
subCodeLst
=
JSON
.
parse
(
localStorage
.
getItem
(
"Subjects"
));
let
tsubsObj
=
{};
for
(
const
code
of
subCodeLst
)
{
tsubsObj
[
code
]
=
await
localf
orage
.
getItem
(
code
);
tsubsObj
[
code
]
=
await
subF
orage
.
getItem
(
code
);
}
dispatch
({
type
:
"INIT"
,
subsObj
:
tsubsObj
});
}
...
...
src/utils/LocalForage.js
0 → 100644
View file @
075dca1
import
localforage
from
"localforage"
;
const
subForage
=
localforage
.
createInstance
({
name
:
"localforage"
,
storeName
:
"subjects"
,
});
const
scheForage
=
localforage
.
createInstance
({
name
:
"localforage"
,
storeName
:
"schedules"
,
});
export
{
subForage
,
scheForage
};
src/utils/Test.js
View file @
075dca1
import
localforage
from
"localf
orage"
;
import
{
subForage
,
scheForage
}
from
"./LocalF
orage"
;
const
initTempSubjects
=
async
()
=>
{
scheForage
.
setItem
(
"20220503"
,
[
{
type
:
"zoom"
,
category
:
"과목A"
,
label
:
""
,
start
:
[
9
,
30
]
},
{
type
:
"ecampus"
,
category
:
"과목B"
,
label
:
"과제"
,
end
:
[
23
,
59
]
},
]);
let
tcolors
=
[
"red"
,
"green"
,
...
...
@@ -16,40 +21,26 @@ const initTempSubjects = async () => {
name
:
"과목A"
,
color
:
tcolors
[
0
],
selected
:
true
,
schedule
:
[
{
type
:
"zoom"
,
category
:
"과목A"
,
label
:
""
,
start
:
[
9
,
30
]
},
],
},
2
:
{
name
:
"과목B"
,
color
:
tcolors
[
1
],
selected
:
true
,
schedule
:
[
{
date
:
new
Date
(
2022
,
5
,
3
),
type
:
"ecampus"
,
category
:
"과목B"
,
label
:
"과제"
,
end
:
[
23
,
59
],
},
],
},
};
await
localf
orage
.
setItem
(
"1"
,
subObj
[
"1"
]);
await
localf
orage
.
setItem
(
"2"
,
subObj
[
"2"
]);
await
subF
orage
.
setItem
(
"1"
,
subObj
[
"1"
]);
await
subF
orage
.
setItem
(
"2"
,
subObj
[
"2"
]);
for
(
let
i
=
2
;
i
<
7
;
i
++
)
{
let
code
=
(
i
+
1
).
toString
();
let
tsub
=
{
date
:
new
Date
(
2022
,
5
,
3
),
name
:
"과목"
+
code
,
color
:
tcolors
[
i
],
selected
:
true
,
schedule
:
[],
};
subCodeLst
.
push
(
code
);
await
localf
orage
.
setItem
(
code
,
tsub
);
await
subF
orage
.
setItem
(
code
,
tsub
);
}
localStorage
.
setItem
(
"Subjects"
,
JSON
.
stringify
(
subCodeLst
));
};
...
...
Please
register
or
login
to post a comment