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-31 00:37:46 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ef6f8955d07748e23f0e38ed27d003a1da8f23a0
ef6f8955
1 parent
e96ffc60
[Implement] Calendar sync with DB
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
36 deletions
src/components/GridItem.js
src/components/ScheduleItem.js
src/pages/Calendar.js
src/utils/Dates.js
src/utils/Test.js
src/components/GridItem.js
View file @
ef6f895
import
{
useContext
}
from
"react"
;
import
{
useContext
,
useEffect
,
useState
}
from
"react"
;
import
{
toYMD
,
toYMDStr
}
from
"../utils/Dates"
;
import
{
scheForage
}
from
"../utils/LocalForage"
;
import
{
CalendarStateContext
}
from
"../pages/Calendar"
;
import
{
toYMD
}
from
"../utils/Dates"
;
import
ScheduleItem
from
"./ScheduleItem"
;
const
GridItem
=
({
targetDate
})
=>
{
const
{
state
}
=
useContext
(
CalendarStateContext
);
const
{
month
}
=
toYMD
(
state
.
date
);
const
{
month
:
tmonth
,
date
:
tdate
}
=
toYMD
(
targetDate
);
const
{
month
:
calMonth
}
=
toYMD
(
state
.
date
);
const
{
month
,
date
}
=
toYMD
(
targetDate
);
const
[
schedules
,
setSchedules
]
=
useState
();
const
tempSchedules
=
[
{
type
:
"zoom"
,
category
:
"오픈소스"
,
label
:
""
,
start
:
[
9
,
30
]
},
{
type
:
"ecampus"
,
category
:
"논리회로"
,
label
:
"요약"
,
end
:
[
23
,
59
]
},
];
const
renderScheduleItems
=
()
=>
{
if
(
targetDate
.
getDay
()
===
5
)
return
(
<>
<
ScheduleItem
schedule
=
{
tempSchedules
[
0
]}
><
/ScheduleItem
>
<
ScheduleItem
schedule
=
{
tempSchedules
[
1
]}
><
/ScheduleItem
>
<
/
>
);
};
useEffect
(()
=>
{
async
function
loadScheduleItems
()
{
setSchedules
(
await
scheForage
.
getItem
(
toYMDStr
(
targetDate
)));
}
loadScheduleItems
();
},
[
targetDate
]);
return
(
<
div
className
=
"GridItem"
relative
=
{
tmonth
-
m
onth
||
null
}
>
<
div
className
=
"GridItem"
relative
=
{
month
-
calM
onth
||
null
}
>
<
span
className
=
"date"
>
{
month
!==
tmonth
?
tmonth
+
"/"
+
tdate
:
t
date
}
{
calMonth
!==
month
?
month
+
"/"
+
date
:
date
}
<
/span
>
{
renderScheduleItems
()}
{
schedules
&&
schedules
.
map
((
sche
,
index
)
=>
(
<
ScheduleItem
key
=
{
index
}
schedule
=
{
sche
}
/
>
))}
<
/div
>
);
};
...
...
src/components/ScheduleItem.js
View file @
ef6f895
import
{
useContext
}
from
"react"
;
import
{
CalendarStateContext
}
from
"../pages/Calendar"
;
import
zoomSymbol
from
"../assets/zoom.png"
;
import
ecampusSymbol
from
"../assets/e-Campus.png"
;
const
ScheduleItem
=
({
schedule
})
=>
{
const
{
type
,
category
,
label
,
start
,
end
}
=
schedule
;
const
{
subCode
,
type
,
category
,
label
,
start
,
end
}
=
schedule
;
const
{
subsObj
}
=
useContext
(
CalendarStateContext
);
const
subject
=
subsObj
[
subCode
];
if
(
!
subject
)
{
console
.
log
(
"can't find "
+
subCode
);
return
;
}
if
(
!
subject
.
selected
)
return
;
const
selectSymbol
=
()
=>
{
let
symbol
;
switch
(
type
)
{
...
...
@@ -18,7 +29,7 @@ const ScheduleItem = ({ schedule }) => {
};
return
(
<
div
className
=
"ScheduleItem"
>
<
div
className
=
"ScheduleItem"
style
=
{{
borderColor
:
subject
.
color
}}
>
<
img
className
=
"s_symbol"
src
=
{
selectSymbol
()}
alt
=
"404"
/>
{
start
&&
<
span
className
=
"s_start"
>
{
start
[
0
]
+
":"
+
start
[
1
]}
<
/span>
}
{
end
&&
<
span
className
=
"s_end"
>
{
end
[
0
]
+
":"
+
end
[
1
]}
<
/span>
}
...
...
src/pages/Calendar.js
View file @
ef6f895
...
...
@@ -35,11 +35,9 @@ const Calendar = () => {
const
navigate
=
useNavigate
();
useEffect
(()
=>
{
async
function
checkSession
()
{
if
(
!
(
await
dataForage
.
getItem
(
"session"
)))
navigate
(
"/login"
);
}
async
function
onMount
()
{
if
(
!
(
await
dataForage
.
getItem
(
"session"
)))
return
navigate
(
"/login"
);
async
function
initSubsObj
()
{
if
(
!
(
await
dataForage
.
getItem
(
"Subjects"
)))
await
initTempSubjects
();
let
tsubsObj
=
{};
for
(
const
code
of
await
dataForage
.
getItem
(
"Subjects"
))
{
...
...
@@ -47,9 +45,7 @@ const Calendar = () => {
}
dispatch
({
type
:
"INIT"
,
subsObj
:
tsubsObj
});
}
checkSession
();
initSubsObj
();
onMount
();
},
[
navigate
]);
return
(
...
...
src/utils/Dates.js
View file @
ef6f895
...
...
@@ -6,6 +6,14 @@ function toYMD(dateObj) {
return
{
year
,
month
,
date
};
}
function
toYMDStr
(
dateObj
)
{
return
[
dateObj
.
getFullYear
(),
dateObj
.
getMonth
()
+
1
,
dateObj
.
getDate
(),
].
join
(
"/"
);
}
function
toSunday
(
dateObj
)
{
const
day
=
dateObj
.
getDay
();
moveDate
(
dateObj
,
"day"
,
-
day
);
...
...
@@ -26,4 +34,4 @@ function moveDate(dateObj, scope, distance) {
}
}
export
{
toYMD
,
toSunday
,
moveDate
};
export
{
toYMD
,
to
YMDStr
,
to
Sunday
,
moveDate
};
...
...
src/utils/Test.js
View file @
ef6f895
import
{
subForage
,
scheForage
,
dataForage
}
from
"./LocalForage"
;
import
{
toYMDStr
}
from
"./Dates"
;
const
initTempSubjects
=
async
()
=>
{
scheForage
.
setItem
(
"20220503"
,
[
{
type
:
"zoom"
,
category
:
"과목A"
,
label
:
""
,
start
:
[
9
,
30
]
},
{
type
:
"ecampus"
,
category
:
"과목B"
,
label
:
"과제"
,
end
:
[
23
,
59
]
},
]);
async
function
initTempSubjects
()
{
const
tempsch
=
[
{
subCode
:
"1"
,
type
:
"zoom"
,
category
:
"과목A"
,
label
:
""
,
start
:
[
9
,
30
],
},
{
subCode
:
"2"
,
type
:
"ecampus"
,
category
:
"과목B"
,
label
:
"과제"
,
end
:
[
23
,
59
],
},
];
await
scheForage
.
setItem
(
toYMDStr
(
new
Date
(
"2022-5-20"
)),
tempsch
);
await
scheForage
.
setItem
(
toYMDStr
(
new
Date
(
"2022-5-27"
)),
tempsch
);
await
scheForage
.
setItem
(
toYMDStr
(
new
Date
(
"2022-6-3"
)),
tempsch
);
let
tcolors
=
[
"red"
,
...
...
@@ -43,6 +60,6 @@ const initTempSubjects = async () => {
await
subForage
.
setItem
(
code
,
tsub
);
}
dataForage
.
setItem
(
"Subjects"
,
subCodeLst
);
}
;
}
export
{
initTempSubjects
};
...
...
Please
register
or
login
to post a comment