@@ -7,6 +7,7 @@ import { AlertItem } from "./AlertItem";
7
7
import { maxWidth , PHONE } from "../../constants" ;
8
8
import { Alert , AlertAction , SectionStatus , TAlertSel } from "../../types" ;
9
9
import { AlertHeader } from "./AlertHeader" ;
10
+ import { groupByProperty } from "../../util" ;
10
11
11
12
const Container = styled . div `
12
13
background: #ffffff;
@@ -91,90 +92,7 @@ export const ManageAlert = ({
91
92
const [ searchTimeout , setSearchTimeout ] = useState < number > ( ) ;
92
93
const [ numSelected , setNumSelected ] = useState ( 0 ) ;
93
94
94
- // Alerts for testing
95
- var alert1 : Alert = {
96
- id : 1 ,
97
- originalCreatedAt : "2023-09-11T12:00:00Z" ,
98
- section : "cis-1100-001" ,
99
- alertLastSent : "2023-09-11T12:00:00Z" ,
100
- status : SectionStatus . OPEN ,
101
- actions : AlertAction . ONALERT ,
102
- closedNotif : AlertAction . ONCLOSED ,
103
- } ;
104
- var alert2 : Alert = {
105
- id : 2 ,
106
- originalCreatedAt : "2023-09-11T12:00:00Z" ,
107
- section : "cis-1100-002" ,
108
- alertLastSent : "2023-09-11T12:00:00Z" ,
109
- status : SectionStatus . OPEN ,
110
- actions : AlertAction . ONALERT ,
111
- closedNotif : AlertAction . ONCLOSED ,
112
- } ;
113
- var alert3 : Alert = {
114
- id : 3 ,
115
- originalCreatedAt : "2023-09-11T12:00:00Z" ,
116
- section : "cis-1200-001" ,
117
- alertLastSent : "2023-09-11T12:00:00Z" ,
118
- status : SectionStatus . OPEN ,
119
- actions : AlertAction . ONALERT ,
120
- closedNotif : AlertAction . ONCLOSED ,
121
- } ;
122
- var alert4 : Alert = {
123
- id : 4 ,
124
- originalCreatedAt : "2023-09-11T12:00:00Z" ,
125
- section : "stat-4300-002" ,
126
- alertLastSent : "2023-09-11T12:00:00Z" ,
127
- status : SectionStatus . OPEN ,
128
- actions : AlertAction . ONALERT ,
129
- closedNotif : AlertAction . ONCLOSED ,
130
- } ;
131
- var alert5 : Alert = {
132
- id : 5 ,
133
- originalCreatedAt : "2023-09-11T12:00:00Z" ,
134
- section : "stat-4300-001" ,
135
- alertLastSent : "2023-09-11T12:00:00Z" ,
136
- status : SectionStatus . OPEN ,
137
- actions : AlertAction . ONALERT ,
138
- closedNotif : AlertAction . ONCLOSED ,
139
- } ;
140
- var alert6 : Alert = {
141
- id : 6 ,
142
- originalCreatedAt : "2023-09-11T12:00:00Z" ,
143
- section : "math-1400-001" ,
144
- alertLastSent : "2023-09-11T12:00:00Z" ,
145
- status : SectionStatus . OPEN ,
146
- actions : AlertAction . ONALERT ,
147
- closedNotif : AlertAction . ONCLOSED ,
148
- } ;
149
- var alert7 : Alert = {
150
- id : 7 ,
151
- originalCreatedAt : "2023-09-11T12:00:00Z" ,
152
- section : "math-1410-002" ,
153
- alertLastSent : "2023-09-11T12:00:00Z" ,
154
- status : SectionStatus . OPEN ,
155
- actions : AlertAction . ONALERT ,
156
- closedNotif : AlertAction . ONCLOSED ,
157
- } ;
158
- var alert8 : Alert = {
159
- id : 8 ,
160
- originalCreatedAt : "2023-09-11T12:00:00Z" ,
161
- section : "stat-4100-001" ,
162
- alertLastSent : "2023-09-11T12:00:00Z" ,
163
- status : SectionStatus . OPEN ,
164
- actions : AlertAction . ONALERT ,
165
- closedNotif : AlertAction . ONCLOSED ,
166
- } ;
167
- var testAlerts : Alert [ ] ;
168
- testAlerts = [
169
- alert1 ,
170
- alert2 ,
171
- alert3 ,
172
- alert4 ,
173
- alert5 ,
174
- alert6 ,
175
- alert7 ,
176
- alert8 ,
177
- ] ;
95
+ let rowNum = 0 ;
178
96
179
97
useEffect ( ( ) => {
180
98
setNumSelected (
@@ -195,24 +113,16 @@ export const ManageAlert = ({
195
113
) ;
196
114
} ;
197
115
198
- let rowNum = 0 ;
199
-
200
116
/**
201
117
* Returns alerts grouped by course
202
118
* @return grouped alerts
203
119
*/
204
- const groupedAlerts = testAlerts
205
- . sort ( ( a , b ) => a . section . localeCompare ( b . section ) )
206
- . reduce ( ( res , obj ) => {
207
- const [ courseName , midNum , endNum ] = obj . section . split ( "-" ) ;
208
- if ( res [ `${ courseName } -${ midNum } ` ] ) {
209
- res [ `${ courseName } -${ midNum } ` ] . push ( obj ) ;
210
- } else {
211
- res [ `${ courseName } -${ midNum } ` ] = [ obj ] ;
212
- }
213
-
214
- return res ;
215
- } , { } ) ;
120
+ const groupedAlerts = groupByProperty (
121
+ alerts ,
122
+ ( a , b ) => a . section . localeCompare ( b . section ) ,
123
+ "-" ,
124
+ ( obj ) => obj . section
125
+ ) ;
216
126
217
127
return (
218
128
< Container >
@@ -229,18 +139,15 @@ export const ManageAlert = ({
229
139
/>
230
140
< AlertGrid >
231
141
{ Object . keys ( groupedAlerts ) . map ( ( key ) => {
232
- rowNum ++ ;
233
142
return (
234
143
< >
235
- < AlertHeader course = { key } rownum = { rowNum } />
144
+ < AlertHeader courseCode = { key } rowNum = { ++ rowNum } />
236
145
{ groupedAlerts [ key ] ?. map ?.( ( alert ) => {
237
- console . log ( alert ) ;
238
- rowNum ++ ;
239
146
return (
240
147
< AlertItem
241
148
key = { alert . id }
242
149
checked = { alertSel [ alert . id ] }
243
- rownum = { rowNum }
150
+ rowNum = { ++ rowNum }
244
151
alertLastSent = { alert . alertLastSent }
245
152
course = { alert . section }
246
153
status = { alert . status }
0 commit comments