sort the flattened course schedule (#93)
first by dayIndex, then startIndex, then endIndex.
This commit is contained in:
@@ -19,7 +19,7 @@ interface CalendarGridPoint {
|
|||||||
* Return type of useFlattenedCourseSchedule
|
* Return type of useFlattenedCourseSchedule
|
||||||
*/
|
*/
|
||||||
export interface CalendarGridCourse {
|
export interface CalendarGridCourse {
|
||||||
calendarGridPoint?: CalendarGridPoint;
|
calendarGridPoint: CalendarGridPoint;
|
||||||
componentProps: CalendarCourseCellProps;
|
componentProps: CalendarCourseCellProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,55 +33,70 @@ export function useFlattenedCourseSchedule(): CalendarGridCourse[] {
|
|||||||
const [activeSchedule] = useSchedules();
|
const [activeSchedule] = useSchedules();
|
||||||
const { courses } = activeSchedule;
|
const { courses } = activeSchedule;
|
||||||
|
|
||||||
return courses.flatMap(course => {
|
return courses
|
||||||
const {
|
.flatMap(course => {
|
||||||
status,
|
const {
|
||||||
department,
|
status,
|
||||||
instructors,
|
department,
|
||||||
schedule: { meetings },
|
instructors,
|
||||||
} = course;
|
schedule: { meetings },
|
||||||
const courseDeptAndInstr = `${department} ${instructors[0].lastName}`;
|
} = course;
|
||||||
|
const courseDeptAndInstr = `${department} ${instructors[0].lastName}`;
|
||||||
|
|
||||||
if (meetings.length === 0) {
|
if (meetings.length === 0) {
|
||||||
// asynch, online course
|
// asynch, online course
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
calendarGridPoint: {
|
||||||
|
dayIndex: 0,
|
||||||
|
startIndex: 0,
|
||||||
|
endIndex: 0,
|
||||||
|
},
|
||||||
|
componentProps: {
|
||||||
|
courseDeptAndInstr,
|
||||||
|
status,
|
||||||
|
colors: {
|
||||||
|
// TODO: figure out colors - these are defaults
|
||||||
|
primaryColor: 'ut-gray',
|
||||||
|
secondaryColor: 'ut-gray',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// in-person
|
||||||
|
return meetings.flatMap(meeting => {
|
||||||
|
const { days, startTime, endTime, location } = meeting;
|
||||||
|
const time = meeting.getTimeString({ separator: '-', capitalize: true });
|
||||||
|
const timeAndLocation = `${time} - ${location ? location.building : 'WB'}`;
|
||||||
|
|
||||||
|
return days.map(d => ({
|
||||||
|
calendarGridPoint: {
|
||||||
|
dayIndex: dayToNumber[d],
|
||||||
|
startIndex: convertMinutesToIndex(startTime),
|
||||||
|
endIndex: convertMinutesToIndex(endTime),
|
||||||
|
},
|
||||||
componentProps: {
|
componentProps: {
|
||||||
courseDeptAndInstr,
|
courseDeptAndInstr,
|
||||||
|
timeAndLocation,
|
||||||
status,
|
status,
|
||||||
colors: {
|
colors: {
|
||||||
// TODO: figure out colors - these are defaults
|
// TODO: figure out colors - these are defaults
|
||||||
primaryColor: 'ut-gray',
|
primaryColor: 'ut-orange',
|
||||||
secondaryColor: 'ut-gray',
|
secondaryColor: 'ut-orange',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
}));
|
||||||
];
|
});
|
||||||
}
|
})
|
||||||
|
.sort((a: CalendarGridCourse, b: CalendarGridCourse) => {
|
||||||
// in-person
|
if (a.calendarGridPoint.dayIndex !== b.calendarGridPoint.dayIndex) {
|
||||||
return meetings.flatMap(meeting => {
|
return a.calendarGridPoint.dayIndex - b.calendarGridPoint.dayIndex;
|
||||||
const { days, startTime, endTime, location } = meeting;
|
}
|
||||||
const time = meeting.getTimeString({ separator: '-', capitalize: true });
|
if (a.calendarGridPoint.startIndex !== b.calendarGridPoint.startIndex) {
|
||||||
const timeAndLocation = `${time} - ${location ? location.building : 'WB'}`;
|
return a.calendarGridPoint.startIndex - b.calendarGridPoint.startIndex;
|
||||||
|
}
|
||||||
return days.map(d => ({
|
return a.calendarGridPoint.endIndex - b.calendarGridPoint.endIndex;
|
||||||
calendarGridPoint: {
|
|
||||||
dayIndex: dayToNumber[d],
|
|
||||||
startIndex: convertMinutesToIndex(startTime),
|
|
||||||
endIndex: convertMinutesToIndex(endTime),
|
|
||||||
},
|
|
||||||
componentProps: {
|
|
||||||
courseDeptAndInstr,
|
|
||||||
timeAndLocation,
|
|
||||||
status,
|
|
||||||
colors: {
|
|
||||||
// TODO: figure out colors - these are defaults
|
|
||||||
primaryColor: 'ut-orange',
|
|
||||||
secondaryColor: 'ut-orange',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user