From b1f3a6d020a58ca4cd20cfa57375d89f4b425e75 Mon Sep 17 00:00:00 2001 From: Daniel Xue Date: Thu, 25 Apr 2024 03:40:24 -0400 Subject: [PATCH] lint --- .../Course/Calendar/InstructorCalendar.tsx | 4 +- .../Calendar/InstructorCalendarModals.tsx | 3 +- .../Home/Dashboard/EventSidebar.tsx | 57 ++++++++++--------- frontend/hooks/data-fetching/calendar.ts | 4 +- frontend/types.tsx | 5 +- 5 files changed, 36 insertions(+), 37 deletions(-) diff --git a/frontend/components/Course/Calendar/InstructorCalendar.tsx b/frontend/components/Course/Calendar/InstructorCalendar.tsx index 558037f2..4aa3166b 100644 --- a/frontend/components/Course/Calendar/InstructorCalendar.tsx +++ b/frontend/components/Course/Calendar/InstructorCalendar.tsx @@ -44,8 +44,8 @@ export default function InstructorCalendar(props: CalendarProps) { const handleSelectSlot = useCallback(async ({ start, end }) => { setNewEvent(true); - setStartField(new Date(start)); - setEndField(new Date(end)); + setStartField(start); + setEndField(end); }, []); return ( diff --git a/frontend/components/Course/Calendar/InstructorCalendarModals.tsx b/frontend/components/Course/Calendar/InstructorCalendarModals.tsx index a5da1cec..23b6cb9b 100644 --- a/frontend/components/Course/Calendar/InstructorCalendarModals.tsx +++ b/frontend/components/Course/Calendar/InstructorCalendarModals.tsx @@ -390,7 +390,6 @@ export const NewEventModal = (props: NewEventProps) => { size="small" open={show} as={Form} - onSubmit={handleCreateEvent} onClose={() => setModalState(false)} > New Event @@ -420,7 +419,7 @@ export const NewEventModal = (props: NewEventProps) => { - diff --git a/frontend/components/Home/Dashboard/EventSidebar.tsx b/frontend/components/Home/Dashboard/EventSidebar.tsx index 51cb0e9e..63b8356e 100644 --- a/frontend/components/Home/Dashboard/EventSidebar.tsx +++ b/frontend/components/Home/Dashboard/EventSidebar.tsx @@ -88,12 +88,39 @@ const EventSidebar = (props: EventSidebarProps) => { ); const occurrences = (data || []).map(apiOccurrenceToOccurrence); + const startOfHour = moment().startOf("hour").toISOString(); useEffect(() => { setFilter({ start: new Date(), end: moment().endOf("day").toDate(), }); - }, [moment().startOf("hour").toISOString()]); + }, [startOfHour]); + + const eventCards = occurrences + .filter((o) => !o.cancelled) + .sort((a, b) => a.start.getTime() - b.start.getTime()) + .map((o) => { + const courseIndex = getMembershipIndex( + memberships, + o.event.course_id + ); + if (courseIndex === -1) return undefined; + + return ( + + ); + }); + + const sidebarContent = + eventCards.length > 0 ? ( + eventCards + ) : ( +
You have no events today!
+ ); return ( @@ -109,33 +136,7 @@ const EventSidebar = (props: EventSidebarProps) => { ) : ( - occurrences - .sort( - (a, b) => - a.start.getTime() - b.start.getTime() - ) - .map((o) => { - const courseIndex = getMembershipIndex( - memberships, - o.event.course_id - ); - if (courseIndex === -1) return undefined; - - return ( - - ); - }) + sidebarContent )} diff --git a/frontend/hooks/data-fetching/calendar.ts b/frontend/hooks/data-fetching/calendar.ts index 4cf1705e..02489942 100644 --- a/frontend/hooks/data-fetching/calendar.ts +++ b/frontend/hooks/data-fetching/calendar.ts @@ -87,9 +87,11 @@ export const useOccurrences = (courseIds: number[], start: Date, end: Date) => { } ); + const filterStartString = filter.start.toISOString(); + const filterEndString = filter.end.toISOString(); useEffect(() => { mutate(undefined, undefined, { sendRequest: false }); - }, [filter.start.toISOString(), filter.end.toISOString()]); + }, [filterStartString, filterEndString]); return { data, diff --git a/frontend/types.tsx b/frontend/types.tsx index 0db706b3..3b064726 100644 --- a/frontend/types.tsx +++ b/frontend/types.tsx @@ -4,7 +4,7 @@ export interface Course { id: number; courseCode: string; department: string; - courseIdQueries: string; + courseTitle: string; description: string; semester: number; semesterPretty: string; @@ -233,9 +233,6 @@ export interface ApiOccurrence { event: ApiEvent; } -// export interface ApiOccurrence extends ApiPartialOccurrence { -// } - export interface Occurrence { id: number; title: string;