From c3448edf558e9f884583131b534260feeaa59ccf Mon Sep 17 00:00:00 2001 From: jsun969 Date: Wed, 25 Sep 2024 13:00:00 +0930 Subject: [PATCH] fix: hide enrolled class time when dragging fix #6 --- src/components/Calendar.tsx | 7 +++++-- src/data/enrolled-courses.ts | 11 +++++++++++ src/helpers/calendar.ts | 14 +++++++++----- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/components/Calendar.tsx b/src/components/Calendar.tsx index e22cca9..9bfb1d9 100644 --- a/src/components/Calendar.tsx +++ b/src/components/Calendar.tsx @@ -224,14 +224,18 @@ const CourseTimePlaceholderCard = ({ return (
+ {/* FIXME: Fix grid width to remove this placeholder, and center the location text */}
{location}
+
+ PLACEHOLDER DO NOT REMOVE ME AND I AM VERY LOOOOOONG +
); }; @@ -246,7 +250,6 @@ const CalendarCourseOtherTimes = ({ courseId: course.id, classTypeId: course.classTypeId, currentWeek, - currentClassNumber: course.classNumber, }); if (times.length === 0) return; diff --git a/src/data/enrolled-courses.ts b/src/data/enrolled-courses.ts index ce4dd41..09a5f9a 100644 --- a/src/data/enrolled-courses.ts +++ b/src/data/enrolled-courses.ts @@ -95,6 +95,17 @@ export const useEnrolledCourse = (id: string) => { return { course, updateClass }; }; +export const useEnrolledCourseClassNumber = ( + courseId: string, + classTypeId: string, +) => { + const course = useEnrolledCourses((s) => + s.courses.find((c) => c.id === courseId), + ); + const classType = course?.classes.find((c) => c.id === classTypeId); + return classType?.classNumber; +}; + export const useDetailedEnrolledCourses = (): Array => { const coursesInfo = useCoursesInfo(); diff --git a/src/helpers/calendar.ts b/src/helpers/calendar.ts index 2351b2f..5a37752 100644 --- a/src/helpers/calendar.ts +++ b/src/helpers/calendar.ts @@ -2,7 +2,10 @@ import { useEffect, useState } from 'react'; import { WEEK_DAYS } from '../constants/week-days'; import { useGetCourseClasses } from '../data/course-info'; -import { useDetailedEnrolledCourses } from '../data/enrolled-courses'; +import { + useDetailedEnrolledCourses, + useEnrolledCourseClassNumber, +} from '../data/enrolled-courses'; import dayjs from '../lib/dayjs'; import type { DateTimeRange, @@ -168,20 +171,21 @@ export const useOtherWeekCourseTimes = ({ courseId, classTypeId, currentWeek, - // currentClassNumber, }: { courseId: string; classTypeId: string; currentWeek: dayjs.Dayjs; - currentClassNumber: string; }) => { const classes = useGetCourseClasses(courseId, classTypeId); + const currentClassNumber = useEnrolledCourseClassNumber( + courseId, + classTypeId, + ); if (!classes) return []; const times: OtherWeekCoursesTimes = [[], [], [], [], []]; classes.forEach((cl) => { cl.meetings.forEach((m) => { - // FIXME: Sometimes this will hide the wrong class #6 - // if (cl.number === currentClassNumber) return; + if (cl.number === currentClassNumber) return; const isMeetingInWeek = checkDateRangeInWeek(currentWeek, m.date); if (!isMeetingInWeek) return; const time = times[WEEK_DAYS.indexOf(m.day)];