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-28 03:42:44 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
adbbdbbcca8125601face0b20160cef3e1168caa
adbbdbbc
1 parent
ede7d1e7
[Modify] Save subjects in localStorage
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
21 deletions
src/components/Side.js
src/components/SideSubject.js
src/index.js
src/pages/Calendar.js
src/components/Side.js
View file @
adbbdbb
...
...
@@ -4,14 +4,19 @@ import "../styles/Side.css";
import
SideSubject
from
"./SideSubject"
;
const
Side
=
()
=>
{
const
{
subs
,
setSubs
}
=
useContext
(
CalendarStateContext
);
const
{
subs
Obj
,
dispatch
}
=
useContext
(
CalendarStateContext
);
const
renderSubs
=
()
=>
{
const
sideSubjects
=
[];
for
(
let
i
=
0
;
i
<
subs
.
length
;
i
++
)
{
for
(
const
code
in
subsObj
)
{
sideSubjects
.
push
(
<
SideSubject
key
=
{
i
}
subject
=
{
subs
[
i
]}
setSubs
=
{
setSubs
}
/
>
<
SideSubject
key
=
{
code
}
code
=
{
code
}
subject
=
{
subsObj
[
code
]}
dispatch
=
{
dispatch
}
/
>
);
}
...
...
src/components/SideSubject.js
View file @
adbbdbb
const
SideSubject
=
({
subject
})
=>
{
let
isChecked
=
false
;
const
SideSubject
=
({
code
,
subject
,
dispatch
})
=>
{
const
defaultColor
=
"#EFEFEF"
;
const
bgc
=
"background-color"
;
const
check
=
(
e
)
=>
{
if
(
isChecked
)
e
.
target
.
style
[
"background-color"
]
=
defaultColor
;
dispatch
({
type
:
"CHECKED"
,
code
});
if
(
subject
.
selected
)
e
.
target
.
style
[
"background-color"
]
=
defaultColor
;
else
e
.
target
.
style
[
"background-color"
]
=
subject
.
color
;
isChecked
=
!
isChecked
;
};
return
(
...
...
@@ -15,7 +13,7 @@ const SideSubject = ({ subject }) => {
className
=
"ssc"
onClick
=
{
check
}
style
=
{{
[
bgc
]:
isCheck
ed
?
subject
.
color
:
defaultColor
,
backgroundColor
:
subject
.
select
ed
?
subject
.
color
:
defaultColor
,
}}
><
/div
>
...
...
src/index.js
View file @
adbbdbb
...
...
@@ -5,7 +5,7 @@ import App from "./App";
const
root
=
ReactDOM
.
createRoot
(
document
.
getElementById
(
"root"
));
root
.
render
(
<
React
.
StrictMode
>
<
App
/>
<
/React.StrictMode
>
//
<React.StrictMode>
<
App
/>
//
</React.StrictMode>
);
...
...
src/pages/Calendar.js
View file @
adbbdbb
import
React
,
{
useState
}
from
"react"
;
import
React
,
{
use
Reducer
,
use
State
}
from
"react"
;
import
{
Navigate
,
Route
,
Routes
}
from
"react-router-dom"
;
import
Month
from
"../components/Month"
;
import
Header
from
"../components/Header"
;
import
Side
from
"../components/Side"
;
import
Subject
from
"../utils/Subject"
;
export
const
CalendarStateContext
=
React
.
createContext
();
const
render
=
(
subsObj
,
args
)
=>
{
switch
(
args
.
type
)
{
case
"CHECKED"
:
const
sub
=
subsObj
[
args
.
code
];
sub
.
selected
=
!
sub
.
selected
;
localStorage
.
setItem
(
"S"
+
args
.
code
,
JSON
.
stringify
(
sub
));
return
{
...
subsObj
,
[
args
.
code
]:
sub
};
default
:
return
subsObj
;
}
};
const
Calendar
=
()
=>
{
console
.
log
(
"visit Calendar"
);
...
...
@@ -18,8 +29,9 @@ const Calendar = () => {
date
:
new
Date
(),
});
let
subLst
;
if
(
!
localStorage
.
getItem
(
"Subjects"
))
{
let
tsubs
=
[];
subLst
=
[];
let
tcolors
=
[
"red"
,
"green"
,
...
...
@@ -30,16 +42,26 @@ const Calendar = () => {
"chartreuse"
,
];
for
(
let
i
=
0
;
i
<
7
;
i
++
)
{
tsubs
.
push
(
new
Subject
(
"과목"
+
(
i
+
1
),
tcolors
[
i
],
true
));
let
code
=
i
+
1
;
let
tsub
=
{
name
:
"과목"
+
code
,
color
:
tcolors
[
i
],
selected
:
true
};
subLst
.
push
(
code
);
localStorage
.
setItem
(
"S"
+
code
,
JSON
.
stringify
(
tsub
));
}
localStorage
.
setItem
(
"Subjects"
,
JSON
.
stringify
(
tsubs
));
localStorage
.
setItem
(
"Subjects"
,
JSON
.
stringify
(
subLst
));
}
const
[
subs
,
setSubs
]
=
useState
(
JSON
.
parse
(
localStorage
.
getItem
(
"Subjects"
))
);
subLst
=
JSON
.
parse
(
localStorage
.
getItem
(
"Subjects"
));
let
tsubsObj
=
{};
for
(
const
code
of
subLst
)
{
tsubsObj
[
code
]
=
JSON
.
parse
(
localStorage
.
getItem
(
"S"
+
code
));
}
const
[
subsObj
,
dispatch
]
=
useReducer
(
render
,
tsubsObj
);
return
(
<
CalendarStateContext
.
Provider
value
=
{{
state
,
setState
,
subs
,
setSubs
}}
>
<
CalendarStateContext
.
Provider
value
=
{{
state
,
setState
,
subsObj
,
dispatch
}}
>
{
session
?
(
<
div
className
=
"Calendar"
>
<
Header
/>
...
...
Please
register
or
login
to post a comment