Showing
3 changed files
with
25 additions
and
21 deletions
1 | import React, { useEffect, useReducer, useState } from "react"; | 1 | import React, { useEffect, useReducer, useState } from "react"; |
2 | import { Navigate, Route, Routes } from "react-router-dom"; | 2 | import { Navigate, Route, Routes } from "react-router-dom"; |
3 | -import localforage from "localforage"; | ||
4 | 3 | ||
5 | import Month from "../components/Month"; | 4 | import Month from "../components/Month"; |
6 | import Header from "../components/Header"; | 5 | import Header from "../components/Header"; |
7 | import Side from "../components/Side"; | 6 | import Side from "../components/Side"; |
8 | import { initTempSubjects } from "../utils/Test"; | 7 | import { initTempSubjects } from "../utils/Test"; |
8 | +import { subForage } from "../utils/LocalForage"; | ||
9 | 9 | ||
10 | export const CalendarStateContext = React.createContext(); | 10 | export const CalendarStateContext = React.createContext(); |
11 | 11 | ||
... | @@ -14,7 +14,7 @@ const render = (subsObj, args) => { | ... | @@ -14,7 +14,7 @@ const render = (subsObj, args) => { |
14 | case "CHECKED": | 14 | case "CHECKED": |
15 | const sub = subsObj[args.code]; | 15 | const sub = subsObj[args.code]; |
16 | sub.selected = !sub.selected; | 16 | sub.selected = !sub.selected; |
17 | - localforage.setItem(args.code, sub); | 17 | + subForage.setItem(args.code, sub); |
18 | return { ...subsObj, [args.code]: sub }; | 18 | return { ...subsObj, [args.code]: sub }; |
19 | case "INIT": | 19 | case "INIT": |
20 | return args.subsObj; | 20 | return args.subsObj; |
... | @@ -40,7 +40,7 @@ const Calendar = () => { | ... | @@ -40,7 +40,7 @@ const Calendar = () => { |
40 | const subCodeLst = JSON.parse(localStorage.getItem("Subjects")); | 40 | const subCodeLst = JSON.parse(localStorage.getItem("Subjects")); |
41 | let tsubsObj = {}; | 41 | let tsubsObj = {}; |
42 | for (const code of subCodeLst) { | 42 | for (const code of subCodeLst) { |
43 | - tsubsObj[code] = await localforage.getItem(code); | 43 | + tsubsObj[code] = await subForage.getItem(code); |
44 | } | 44 | } |
45 | dispatch({ type: "INIT", subsObj: tsubsObj }); | 45 | dispatch({ type: "INIT", subsObj: tsubsObj }); |
46 | } | 46 | } | ... | ... |
src/utils/LocalForage.js
0 → 100644
1 | +import localforage from "localforage"; | ||
2 | + | ||
3 | +const subForage = localforage.createInstance({ | ||
4 | + name: "localforage", | ||
5 | + storeName: "subjects", | ||
6 | +}); | ||
7 | + | ||
8 | +const scheForage = localforage.createInstance({ | ||
9 | + name: "localforage", | ||
10 | + storeName: "schedules", | ||
11 | +}); | ||
12 | + | ||
13 | +export { subForage, scheForage }; |
1 | -import localforage from "localforage"; | 1 | +import { subForage, scheForage } from "./LocalForage"; |
2 | 2 | ||
3 | const initTempSubjects = async () => { | 3 | const initTempSubjects = async () => { |
4 | + scheForage.setItem("20220503", [ | ||
5 | + { type: "zoom", category: "과목A", label: "", start: [9, 30] }, | ||
6 | + { type: "ecampus", category: "과목B", label: "과제", end: [23, 59] }, | ||
7 | + ]); | ||
8 | + | ||
4 | let tcolors = [ | 9 | let tcolors = [ |
5 | "red", | 10 | "red", |
6 | "green", | 11 | "green", |
... | @@ -16,40 +21,26 @@ const initTempSubjects = async () => { | ... | @@ -16,40 +21,26 @@ const initTempSubjects = async () => { |
16 | name: "과목A", | 21 | name: "과목A", |
17 | color: tcolors[0], | 22 | color: tcolors[0], |
18 | selected: true, | 23 | selected: true, |
19 | - schedule: [ | ||
20 | - { type: "zoom", category: "과목A", label: "", start: [9, 30] }, | ||
21 | - ], | ||
22 | }, | 24 | }, |
23 | 2: { | 25 | 2: { |
24 | name: "과목B", | 26 | name: "과목B", |
25 | color: tcolors[1], | 27 | color: tcolors[1], |
26 | selected: true, | 28 | selected: true, |
27 | - schedule: [ | ||
28 | - { | ||
29 | - date: new Date(2022, 5, 3), | ||
30 | - type: "ecampus", | ||
31 | - category: "과목B", | ||
32 | - label: "과제", | ||
33 | - end: [23, 59], | ||
34 | - }, | ||
35 | - ], | ||
36 | }, | 29 | }, |
37 | }; | 30 | }; |
38 | 31 | ||
39 | - await localforage.setItem("1", subObj["1"]); | 32 | + await subForage.setItem("1", subObj["1"]); |
40 | - await localforage.setItem("2", subObj["2"]); | 33 | + await subForage.setItem("2", subObj["2"]); |
41 | 34 | ||
42 | for (let i = 2; i < 7; i++) { | 35 | for (let i = 2; i < 7; i++) { |
43 | let code = (i + 1).toString(); | 36 | let code = (i + 1).toString(); |
44 | let tsub = { | 37 | let tsub = { |
45 | - date: new Date(2022, 5, 3), | ||
46 | name: "과목" + code, | 38 | name: "과목" + code, |
47 | color: tcolors[i], | 39 | color: tcolors[i], |
48 | selected: true, | 40 | selected: true, |
49 | - schedule: [], | ||
50 | }; | 41 | }; |
51 | subCodeLst.push(code); | 42 | subCodeLst.push(code); |
52 | - await localforage.setItem(code, tsub); | 43 | + await subForage.setItem(code, tsub); |
53 | } | 44 | } |
54 | localStorage.setItem("Subjects", JSON.stringify(subCodeLst)); | 45 | localStorage.setItem("Subjects", JSON.stringify(subCodeLst)); |
55 | }; | 46 | }; | ... | ... |
-
Please register or login to post a comment