Skip to content

Commit

Permalink
refactor: calendar course order
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun969 committed Sep 25, 2024
1 parent 086c0e7 commit 4cc05d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const CalendarCourses = ({ courses: day }: { courses: WeekCourses }) => {
gridRowStart: getGridRow(time.time.start),
gridRowEnd: getGridRow(time.time.end),
height: calcHoursDuration(time.time) * 6 + 'rem',
zIndex: 10 - j, // TODO: Remove zIndex after implementing course conflicts #5
zIndex: j, // TODO: Remove zIndex after implementing course conflicts #5
}}
>
{time.courses.map((course) => (
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const getWeekCourses = (

// TODO: Remove this sorting after implementing course conflicts #5
courses.forEach((dayCourses) => {
// Sort by duration (shortest first) and start time (latest first)
// Sort by duration (longest first) and start time (earliest first)
dayCourses.sort((a, b) => {
const aStart = timeToDayjs(a.time.start);
const aEnd = timeToDayjs(a.time.end);
Expand All @@ -110,12 +110,12 @@ export const getWeekCourses = (
const bDuration = bEnd.diff(bStart, 'minute');

if (aDuration === bDuration) {
if (aStart.isBefore(bStart)) return 1;
if (aStart.isAfter(bStart)) return -1;
if (aStart.isBefore(bStart)) return -1;
if (aStart.isAfter(bStart)) return 1;
return 0;
}

return aDuration - bDuration;
return bDuration - aDuration;
});
});

Expand Down

0 comments on commit 4cc05d6

Please sign in to comment.