chore: cleanup useFlattenedCourseSchedule
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { CalendarCourseCellProps } from 'src/views/components/common/CalendarCourseCell/CalendarCourseCell';
|
import { CalendarCourseCellProps } from 'src/views/components/common/CalendarCourseCell/CalendarCourseCell';
|
||||||
import useSchedules from './useSchedules';
|
import useSchedules from './useSchedules';
|
||||||
|
|
||||||
const dayToNumber = {
|
const dayToNumber: { [day: string]: number } = {
|
||||||
Monday: 0,
|
Monday: 0,
|
||||||
Tuesday: 1,
|
Tuesday: 1,
|
||||||
Wednesday: 2,
|
Wednesday: 2,
|
||||||
@@ -15,6 +15,9 @@ interface CalendarGridPoint {
|
|||||||
endIndex: number;
|
endIndex: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return type of useFlattenedCourseSchedule
|
||||||
|
*/
|
||||||
export interface CalendarGridCourse {
|
export interface CalendarGridCourse {
|
||||||
calendarGridPoint?: CalendarGridPoint;
|
calendarGridPoint?: CalendarGridPoint;
|
||||||
componentProps: CalendarCourseCellProps;
|
componentProps: CalendarCourseCellProps;
|
||||||
@@ -22,11 +25,15 @@ export interface CalendarGridCourse {
|
|||||||
|
|
||||||
const convertMinutesToIndex = (minutes: number): number => Math.floor(minutes - 420 / 30);
|
const convertMinutesToIndex = (minutes: number): number => Math.floor(minutes - 420 / 30);
|
||||||
|
|
||||||
export function useFlattenedCourseSchedule() {
|
/**
|
||||||
|
* Get the active schedule, and convert it to be render-able into a calendar.
|
||||||
|
* @returns CalendarGridCourse
|
||||||
|
*/
|
||||||
|
export function useFlattenedCourseSchedule(): CalendarGridCourse[] {
|
||||||
const [activeSchedule] = useSchedules();
|
const [activeSchedule] = useSchedules();
|
||||||
const { courses } = activeSchedule;
|
const { courses } = activeSchedule;
|
||||||
|
|
||||||
const out = courses.flatMap(course => {
|
return courses.flatMap(course => {
|
||||||
const {
|
const {
|
||||||
status,
|
status,
|
||||||
department,
|
department,
|
||||||
@@ -43,6 +50,7 @@ export function useFlattenedCourseSchedule() {
|
|||||||
courseDeptAndInstr,
|
courseDeptAndInstr,
|
||||||
status,
|
status,
|
||||||
colors: {
|
colors: {
|
||||||
|
// TODO: figure out colors - these are defaults
|
||||||
primaryColor: 'ut-gray',
|
primaryColor: 'ut-gray',
|
||||||
secondaryColor: 'ut-gray',
|
secondaryColor: 'ut-gray',
|
||||||
},
|
},
|
||||||
@@ -50,36 +58,30 @@ export function useFlattenedCourseSchedule() {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// in-person
|
||||||
return meetings.flatMap(meeting => {
|
return meetings.flatMap(meeting => {
|
||||||
const { days, startTime, endTime, location } = meeting;
|
const { days, startTime, endTime, location } = meeting;
|
||||||
const time = meeting.getTimeString({ separator: ' - ', capitalize: true });
|
const time = meeting.getTimeString({ separator: ' - ', capitalize: true });
|
||||||
const timeAndLocation = `${time} - ${location ? location.building : 'WB'}`;
|
const timeAndLocation = `${time} - ${location ? location.building : 'WB'}`;
|
||||||
|
|
||||||
return days.map(d => {
|
return days.map(d => ({
|
||||||
const dayIndex = dayToNumber[d];
|
calendarGridPoint: {
|
||||||
const startIndex = convertMinutesToIndex(startTime);
|
dayIndex: dayToNumber[d],
|
||||||
const endIndex = convertMinutesToIndex(endTime);
|
startIndex: convertMinutesToIndex(startTime),
|
||||||
const calendarGridPoint: CalendarGridPoint = {
|
endIndex: convertMinutesToIndex(endTime),
|
||||||
dayIndex,
|
},
|
||||||
startIndex,
|
|
||||||
endIndex,
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
calendarGridPoint,
|
|
||||||
componentProps: {
|
componentProps: {
|
||||||
courseDeptAndInstr,
|
courseDeptAndInstr,
|
||||||
timeAndLocation,
|
timeAndLocation,
|
||||||
status,
|
status,
|
||||||
colors: {
|
colors: {
|
||||||
|
// TODO: figure out colors - these are defaults
|
||||||
primaryColor: 'ut-orange',
|
primaryColor: 'ut-orange',
|
||||||
secondaryColor: 'ut-orange',
|
secondaryColor: 'ut-orange',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user