@@ -9,15 +9,21 @@ import { useNavigate, useParams } from "react-router-dom";
9
9
import { ScheduleLecture , AttendanceData , Empty } from "../../types/common" ;
10
10
import { backend_post , useAxiosRequest } from "../../utils" ;
11
11
import moment from "moment" ;
12
- import { Button } from "@mui/material" ;
12
+ import { Button , Divider , capitalize } from "@mui/material" ;
13
13
import ArrowBackIcon from '@mui/icons-material/ArrowBack' ;
14
14
import ArrowForwardIcon from '@mui/icons-material/ArrowForward' ;
15
+ import "./schedule.css" ;
15
16
16
17
const AttendancePage : React . FC = ( ) => {
17
18
const navigate = useNavigate ( ) ;
18
19
const { response, error, loading, sendRequest } = useAxiosRequest < Empty , ScheduleLecture [ ] > ( ) ;
19
20
const [ lectures , setLectures ] = useState < ScheduleLecture [ ] [ ] > ( ) ;
20
21
const [ schedule_date , setScheduleDate ] = useState < moment . Moment > ( moment ( ) ) ;
22
+ const alternatingColor = [
23
+ "#424242" ,
24
+ "#595959"
25
+ ] ;
26
+
21
27
22
28
const updateSchedule = ( ) => {
23
29
sendRequest ( {
@@ -27,9 +33,7 @@ const AttendancePage: React.FC = () => {
27
33
} ) ;
28
34
}
29
35
30
- useEffect ( ( ) => {
31
- updateSchedule ( )
32
- } , [ sendRequest ] ) ;
36
+ useEffect ( ( ) => { updateSchedule ( ) } , [ sendRequest ] ) ;
33
37
34
38
useEffect ( ( ) => {
35
39
if ( response ) {
@@ -76,50 +80,71 @@ const AttendancePage: React.FC = () => {
76
80
const dayConvert = [ "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday" ]
77
81
const monthConvert = [ "January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "Octobor" , "November" , "December" ]
78
82
83
+ const convertToScheduleTime = ( time : string ) => {
84
+ return moment ( Date . parse ( time ) ) . format ( "HH:mm" )
85
+ }
86
+
79
87
return (
80
88
< RootPage >
81
89
< Container
82
90
component = "main"
83
- maxWidth = "xs "
91
+ maxWidth = "md "
84
92
sx = { { marginBottom : "5%" } }
93
+ className = "mainComponent"
85
94
>
86
- < div style = { { display : "flex" , justifyContent : "space-between" , alignItems : "center" , marginBottom : "10px" } } >
87
- < div >
88
- < h2 > { `Week ${ schedule_date . week ( ) } overview` } </ h2 >
89
- < h3 > { `${ monthConvert [ schedule_date . month ( ) ] } ${ schedule_date . year ( ) } ` } </ h3 >
90
- </ div >
91
- < div >
92
- < Button variant = "contained" style = { { minWidth : "1em" , width : "auto" , height : "2.5em" } } onClick = { goBackWeek } >
93
- < ArrowBackIcon />
94
- </ Button >
95
- < Button variant = "contained" style = { { minWidth : "1em" , width : "auto" , height : "2.5em" } } onClick = { goForwardWeek } >
96
- < ArrowForwardIcon />
97
- </ Button >
95
+ < div style = { { marginLeft : "2%" , marginRight : "2%" } } >
96
+ < div style = { { display : "flex" , justifyContent : "space-between" , alignItems : "center" , marginBottom : "10px" } } >
97
+ < div >
98
+ < h2 > { `Week ${ schedule_date . week ( ) } overview` } </ h2 >
99
+ < h3 > { `${ monthConvert [ schedule_date . month ( ) ] } ${ schedule_date . year ( ) } ` } </ h3 >
100
+ </ div >
101
+ < div >
102
+ < Button variant = "contained" style = { { minWidth : "1em" , width : "auto" , height : "2.5em" } } onClick = { goBackWeek } >
103
+ < ArrowBackIcon />
104
+ </ Button >
105
+ < Button variant = "contained" style = { { minWidth : "1em" , width : "auto" , height : "2.5em" } } onClick = { goForwardWeek } >
106
+ < ArrowForwardIcon />
107
+ </ Button >
108
+ </ div >
98
109
</ div >
99
- </ div >
100
110
101
- { lectures ?. map ( ( day , index ) => (
102
- < div key = { dayConvert [ index ] } >
103
- < h2 > { dayConvert [ index ] } </ h2 >
104
- < List >
105
- { day . map ( ( lecture ) => (
106
- < ListItem key = { lecture . id } >
107
- < ListItemText primary = { lecture . course } />
108
- < Checkbox
109
- checked = { lecture . attended_student }
110
- onChange = { handleAttendanceChange ( lecture . id ) }
111
- sx = { { "& .MuiSvgIcon-root" : { color : "white" } } }
112
- />
113
- < Checkbox
114
- checked = { lecture . attended_teacher }
115
- disabled = { true }
116
- sx = { { "& .MuiSvgIcon-root" : { color : "white" } } }
117
- />
118
- </ ListItem >
119
- ) ) }
120
- </ List >
121
- </ div >
122
- ) ) }
111
+ < Divider style = { { marginBottom : "3%" } } />
112
+
113
+ { lectures ?. map ( ( day : ScheduleLecture [ ] , dayIndex ) => (
114
+ < div key = { dayConvert [ dayIndex ] } style = { { background : alternatingColor [ dayIndex % 2 ] , paddingTop : "0" , marginTop : "0" } } >
115
+ < h2 style = { { paddingLeft : "2%" , paddingTop : "1%" , paddingBottom : "0" , marginBottom : "0" , marginTop : "0" } } >
116
+ { dayConvert [ dayIndex ] }
117
+ </ h2 >
118
+
119
+ { ( day . length != 0 ) ? < Divider variant = "middle" style = { { marginTop : "1.5%" } } /> : null }
120
+
121
+ < List >
122
+ { day . map ( ( lecture , lectureIndex ) => (
123
+ < ListItem key = { lecture . id } style = { { marginTop : "-0.5%" , marginBottom : "-1%" } } >
124
+ < div style = { { marginRight : "3%" } } >
125
+ < ListItemText primary = { convertToScheduleTime ( lecture . start_time ) } />
126
+ < ListItemText primary = { convertToScheduleTime ( lecture . end_time ) } />
127
+ </ div >
128
+ < ListItemText primary = { lecture . course } secondary = { capitalize ( lecture . lecture_type ) } />
129
+
130
+ < Checkbox
131
+ checked = { lecture . attended_student }
132
+ onChange = { handleAttendanceChange ( lecture . id ) }
133
+ sx = { { "& .MuiSvgIcon-root" : { color : "white" } } }
134
+ />
135
+ < Checkbox
136
+ checked = { lecture . attended_teacher }
137
+ disabled = { true }
138
+ sx = { { "& .MuiSvgIcon-root" : { color : "white" } } }
139
+ />
140
+ </ ListItem >
141
+ ) )
142
+ }
143
+ </ List >
144
+ < Divider />
145
+ </ div >
146
+ ) ) }
147
+ </ div >
123
148
</ Container >
124
149
</ RootPage >
125
150
) ;
0 commit comments