diff --git a/frontend/src/app/cache.ts b/frontend/src/app/cache.ts index f862aa9..0f24b00 100644 --- a/frontend/src/app/cache.ts +++ b/frontend/src/app/cache.ts @@ -71,7 +71,7 @@ export const selectCourseResult = (courseID: string) => (state: RootState) => export const selectFCEResultsForCourses = (courseIDs: string[]) => (state: RootState) => courseIDs.map((courseID) => { - if (!state.cache.fces[courseID]) return { courseID, fces: null }; + if (!state.cache.fces[courseID]) return { courseID, fces: [] }; return { courseID, fces: state.cache.fces[courseID] }; }); diff --git a/frontend/src/app/fce.ts b/frontend/src/app/fce.ts index 2f72a2a..b3ae4ae 100644 --- a/frontend/src/app/fce.ts +++ b/frontend/src/app/fce.ts @@ -94,8 +94,8 @@ export const aggregateCourses = ( courses: Course[], options: AggregateFCEsOptions ) => { - const messages = []; - const unitsMessage = []; + const messages : string[] = []; + const unitsMessage : string[] = []; const coursesWithoutFCEs = data .filter(({ fces }) => fces === null) diff --git a/frontend/src/app/utils.tsx b/frontend/src/app/utils.tsx index 84bc190..39c5c2d 100644 --- a/frontend/src/app/utils.tsx +++ b/frontend/src/app/utils.tsx @@ -68,7 +68,7 @@ export const sessionToShortString = (sessionInfo: Session | FCE | Schedule) => { export const compareSessions = ( session1: Session | FCE, session2: Session | FCE -) => { +) : number => { if (session1.year != session2.year) return session1.year < session2.year ? 1 : -1; @@ -88,11 +88,16 @@ export const compareSessions = ( } if (session1.session !== session2.session) { + if (!session1.session) return 1; + if (!session2.session) return -1; + return sessionNumbers.indexOf(session1.session) < sessionNumbers.indexOf(session2.session) ? 1 : -1; } + + return 0; }; export function filterSessions(sessions: T[]): T[] { @@ -175,7 +180,7 @@ export function isExactSearch(search: string): boolean { } export function getCourseIDs(search: string): string[] { - return search.match(courseIdRegex); + return search.match(courseIdRegex) || []; } export function classNames(...classes) { diff --git a/frontend/src/components/CourseDetail.tsx b/frontend/src/components/CourseDetail.tsx index f26a69d..e2e900f 100644 --- a/frontend/src/components/CourseDetail.tsx +++ b/frontend/src/components/CourseDetail.tsx @@ -20,17 +20,13 @@ const CourseDetail = ({ info, schedules }: Props) => { void dispatch(fetchFCEInfosByCourse({ courseIDs: [info.courseID] })); }, [dispatch, info.courseID, loggedIn]); - let sortedSchedules: Schedule[]; - if (schedules) - sortedSchedules = filterSessions([...schedules]).sort(compareSessions); - const fces = useAppSelector((state) => state.cache.fces[info.courseID]); return (
{fces && } - {schedules && } + {schedules && }
); }; diff --git a/frontend/src/components/FCETable.tsx b/frontend/src/components/FCETable.tsx index 45f386e..3ebee27 100644 --- a/frontend/src/components/FCETable.tsx +++ b/frontend/src/components/FCETable.tsx @@ -145,7 +145,7 @@ export const FCETable = ({ columnVisibility: Record; aggregationOptions: AggregateFCEsOptions; }) => { - let aggregateData: AggregatedFCEs; + let aggregateData: AggregatedFCEs | undefined = undefined; let filteredFCEs = fces; if (fces) { @@ -160,7 +160,7 @@ export const FCETable = ({ return ( <> { - aggregateData.fcesCounted !== 0 && ( + aggregateData && aggregateData.fcesCounted !== 0 && (

Aggregate Data

@@ -180,7 +180,7 @@ export const FCETable = ({
- +
{aggregateData.teachingRate} @@ -193,7 +193,7 @@ export const FCETable = ({
- +
{aggregateData.courseRate} diff --git a/frontend/src/components/ScheduleSearch.tsx b/frontend/src/components/ScheduleSearch.tsx index 42680dc..b8ad909 100644 --- a/frontend/src/components/ScheduleSearch.tsx +++ b/frontend/src/components/ScheduleSearch.tsx @@ -31,7 +31,7 @@ const CourseCombobox = ({ onSelectedItemsChange: (items: string[]) => void; }) => { const [inputValue, setInputValue] = useState(""); - const listRef = useRef(); + const listRef = useRef(null); const dispatch = useAppDispatch(); const allCourses = useAppSelector((state) => state.cache.allCourses); @@ -70,14 +70,14 @@ const CourseCombobox = ({ selectedItems, } = useMultipleSelection({ onSelectedItemsChange: ({ selectedItems }) => { - onSelectedItemsChange(selectedItems.map(({ courseID }) => courseID)); + onSelectedItemsChange(selectedItems?.map(({ courseID }) => courseID) || []); }, }); const filteredCourses = getCourses(); const rowVirtualizer = useVirtualizer({ count: filteredCourses.length, - getScrollElement: () => listRef.current, + getScrollElement: () => listRef.current || null, estimateSize: useCallback(() => 40, []), }); @@ -99,9 +99,9 @@ const CourseCombobox = ({ selectedItem: null, inputValue, defaultHighlightedIndex: 0, - onInputValueChange: ({ inputValue: newValue }) => setInputValue(newValue), + onInputValueChange: ({ inputValue: newValue }) => setInputValue(newValue || ""), onHighlightedIndexChange: ({ highlightedIndex }) => - rowVirtualizer.scrollToIndex(highlightedIndex), + rowVirtualizer.scrollToIndex(highlightedIndex || 0), stateReducer: (state, actionAndChanges) => { const { changes, type } = actionAndChanges; switch (type) { @@ -117,7 +117,7 @@ const CourseCombobox = ({ onStateChange: ({ inputValue, type, selectedItem }) => { switch (type) { case useCombobox.stateChangeTypes.InputChange: - setInputValue(inputValue); + setInputValue(inputValue || ""); break; case useCombobox.stateChangeTypes.InputKeyDownEnter: case useCombobox.stateChangeTypes.ItemClick: diff --git a/frontend/src/components/SearchBar.tsx b/frontend/src/components/SearchBar.tsx index 2177954..f701133 100644 --- a/frontend/src/components/SearchBar.tsx +++ b/frontend/src/components/SearchBar.tsx @@ -42,7 +42,7 @@ const AppliedFiltersPill = ({ const AppliedFilters = () => { const dispatch = useAppDispatch(); - const badges = []; + const badges : JSX.Element[] = []; const filter = useAppSelector((state) => state.filters); if (filter.departments.active) { diff --git a/frontend/src/components/Toast.tsx b/frontend/src/components/Toast.tsx index d9a2a10..ba94bce 100644 --- a/frontend/src/components/Toast.tsx +++ b/frontend/src/components/Toast.tsx @@ -9,7 +9,7 @@ type Props = { }; export const Toast = (t: ToastType, { message, title, icon }: Props) => { - const Icon = icon; + const Icon = icon || (() =>
); return (
{ const filteredCourses = useAppSelector((state) => state.user.fceAggregation.filters.courses); const fces = useAppSelector(selectFCEResultsForInstructor(name)); - const courses = getUnique(fces?.map((fce) => fce.courseID).sort()); + const courses = getUnique(fces?.map((fce) => fce.courseID).sort() || []); useEffect(() => { dispatch(userSlice.actions.setFilters({ type: "courses", - courses: getUnique(fces?.map((fce) => fce.courseID).sort()), instructors: [] })); + courses: getUnique(fces?.map((fce) => fce.courseID).sort() || []), instructors: [] })); }, [fces, dispatch]); const setCourses = (courses: string[]) => { diff --git a/frontend/src/pages/course/[courseID].tsx b/frontend/src/pages/course/[courseID].tsx index 0c209bd..2eec5cd 100644 --- a/frontend/src/pages/course/[courseID].tsx +++ b/frontend/src/pages/course/[courseID].tsx @@ -29,7 +29,7 @@ const CourseDetailPage: NextPage = () => { ); if (info) { - content = ; + content = ; } return (