1
1
"use client"
2
2
3
3
import React from "react"
4
- import { useChannelCounts } from "api/hooks/channels"
5
- import { useOfferorsList } from "api/hooks/learningResources"
4
+ import { useChannelCounts , useChannelsList } from "api/hooks/channels"
6
5
import {
7
6
Banner ,
8
7
Container ,
@@ -14,23 +13,23 @@ import {
14
13
import { backgroundSrcSetCSS } from "ol-utilities"
15
14
import backgroundSteps from "@/public/images/backgrounds/background_steps.jpg"
16
15
import { RiBookOpenLine , RiSuitcaseLine } from "@remixicon/react"
17
- import type { LearningResourceOfferorDetail } from "api"
16
+ import type { Channel , UnitChannel } from "api/v0 "
18
17
import { HOME } from "@/common/urls"
19
18
import { UnitCards , UnitCardLoading } from "./UnitCard"
20
19
import { aggregateProgramCounts , aggregateCourseCounts } from "@/common/utils"
21
20
22
21
const DESKTOP_WIDTH = "1056px"
23
22
24
- const sortUnits = (
25
- units : Array < LearningResourceOfferorDetail > | undefined ,
23
+ const sortUnitChannels = (
24
+ channels : Array < Channel > | undefined ,
26
25
courseCounts : Record < string , number > ,
27
26
programCounts : Record < string , number > ,
28
27
) => {
29
- return units ?. sort ( ( a , b ) => {
30
- const courseCountA = courseCounts [ a . code ] || 0
31
- const programCountA = programCounts [ a . code ] || 0
32
- const courseCountB = courseCounts [ b . code ] || 0
33
- const programCountB = programCounts [ b . code ] || 0
28
+ return channels ?. sort ( ( a , b ) => {
29
+ const courseCountA = courseCounts [ a . name ] || 0
30
+ const programCountA = programCounts [ a . name ] || 0
31
+ const courseCountB = courseCounts [ b . name ] || 0
32
+ const programCountB = programCounts [ b . name ] || 0
34
33
const totalA = courseCountA + programCountA
35
34
const totalB = courseCountB + programCountB
36
35
return totalB - totalA
@@ -151,7 +150,7 @@ interface UnitSectionProps {
151
150
icon : React . ReactNode
152
151
title : string
153
152
description : string
154
- units : LearningResourceOfferorDetail [ ] | undefined
153
+ channels : UnitChannel [ ] | undefined
155
154
courseCounts : Record < string , number >
156
155
programCounts : Record < string , number >
157
156
isLoading ?: boolean
@@ -163,7 +162,7 @@ const UnitSection: React.FC<UnitSectionProps> = (props) => {
163
162
icon,
164
163
title,
165
164
description,
166
- units ,
165
+ channels ,
167
166
courseCounts,
168
167
programCounts,
169
168
isLoading,
@@ -186,7 +185,7 @@ const UnitSection: React.FC<UnitSectionProps> = (props) => {
186
185
. map ( ( _null , i ) => < UnitCardLoading key = { `irrelevant-${ i } ` } /> )
187
186
) : (
188
187
< UnitCards
189
- units = { units }
188
+ channels = { channels }
190
189
courseCounts = { courseCounts }
191
190
programCounts = { programCounts }
192
191
/>
@@ -197,8 +196,7 @@ const UnitSection: React.FC<UnitSectionProps> = (props) => {
197
196
}
198
197
199
198
const UnitsListingPage : React . FC = ( ) => {
200
- const unitsQuery = useOfferorsList ( )
201
- const units = unitsQuery . data ?. results
199
+ const channelsQuery = useChannelsList ( { channel_type : "unit" } )
202
200
const channelCountQuery = useChannelCounts ( "unit" )
203
201
204
202
const courseCounts = channelCountQuery . data
@@ -207,33 +205,41 @@ const UnitsListingPage: React.FC = () => {
207
205
const programCounts = channelCountQuery . data
208
206
? aggregateProgramCounts ( "name" , channelCountQuery . data )
209
207
: { }
210
- const academicUnits = sortUnits (
211
- units ?. filter ( ( unit ) => unit . professional === false ) ,
208
+
209
+ const channels = channelsQuery . data ?. results
210
+ const academicUnits = sortUnitChannels (
211
+ channels ?. filter (
212
+ ( channel ) =>
213
+ ( channel as UnitChannel ) . unit_detail . unit . professional === false ,
214
+ ) ,
212
215
courseCounts ,
213
216
programCounts ,
214
217
)
215
- const professionalUnits = sortUnits (
216
- units ?. filter ( ( unit ) => unit . professional === true ) ,
218
+ const professionalUnits = sortUnitChannels (
219
+ channels ?. filter (
220
+ ( channel ) =>
221
+ ( channel as UnitChannel ) . unit_detail . unit . professional === true ,
222
+ ) ,
217
223
courseCounts ,
218
224
programCounts ,
219
225
)
220
226
221
- const unitData = [
227
+ const sections = [
222
228
{
223
229
id : "academic" ,
224
230
icon : < AcademicIcon /> ,
225
231
title : "Academic Units" ,
226
232
description :
227
233
"MIT's Academic courses, programs, and materials mirror MIT curriculum and residential programs, making these available to a global audience. Approved by faculty committees, Academic content furnishes a comprehensive foundation of knowledge, skills, and abilities for students pursuing their academic objectives. Renowned for their rigor and challenge, MIT's Academic offerings deliver an experience on par with the campus environment." ,
228
- units : academicUnits ,
234
+ channels : academicUnits as UnitChannel [ ] ,
229
235
} ,
230
236
{
231
237
id : "professional" ,
232
238
icon : < ProfessionalIcon /> ,
233
239
title : "Professional Units" ,
234
240
description :
235
241
"MIT's Professional courses and programs are tailored for working professionals seeking essential practical skills across various industries. Led by MIT faculty and maintaining challenging standards, Professional courses and programs prioritize real-world applications, emphasize practical skills and are directly relevant to today's workforce." ,
236
- units : professionalUnits ,
242
+ channels : professionalUnits as UnitChannel [ ] ,
237
243
} ,
238
244
]
239
245
@@ -266,17 +272,17 @@ const UnitsListingPage: React.FC = () => {
266
272
</ PageHeaderText >
267
273
</ PageHeaderContainerInner >
268
274
</ PageHeaderContainer >
269
- { unitData . map ( ( unit ) => (
275
+ { sections . map ( ( section ) => (
270
276
< UnitSection
271
- key = { unit . id }
272
- id = { unit . id }
273
- icon = { unit . icon }
274
- title = { unit . title }
275
- description = { unit . description }
276
- units = { unit . units }
277
+ key = { section . id }
278
+ id = { section . id }
279
+ icon = { section . icon }
280
+ title = { section . title }
281
+ description = { section . description }
282
+ channels = { section . channels }
277
283
courseCounts = { courseCounts }
278
284
programCounts = { programCounts }
279
- isLoading = { unitsQuery . isLoading }
285
+ isLoading = { channelsQuery . isLoading }
280
286
/>
281
287
) ) }
282
288
</ PageContent >
0 commit comments