Skip to content

Commit

Permalink
Fixed type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
“xavilien” committed May 18, 2024
1 parent 1ef9dd5 commit 03a4b34
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion frontend/src/app/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] };
});

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/fce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/app/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<T extends Session>(sessions: T[]): T[] {
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/components/CourseDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="m-auto space-y-4 p-6">
<CourseCard info={info} showFCEs={false} showCourseInfo={true} />
{fces && <FCECard fces={fces} />}
{schedules && <SchedulesCard scheduleInfos={sortedSchedules} />}
{schedules && <SchedulesCard scheduleInfos={filterSessions([...schedules]).sort(compareSessions)} />}
</div>
);
};
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/FCETable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const FCETable = ({
columnVisibility: Record<string, boolean>;
aggregationOptions: AggregateFCEsOptions;
}) => {
let aggregateData: AggregatedFCEs;
let aggregateData: AggregatedFCEs | undefined = undefined;
let filteredFCEs = fces;

if (fces) {
Expand All @@ -160,7 +160,7 @@ export const FCETable = ({
return (
<>
{
aggregateData.fcesCounted !== 0 && (
aggregateData && aggregateData.fcesCounted !== 0 && (
<div className="text-md text-gray-700 bg-gray-50 mt-3 rounded p-4">
<div className="flex items-baseline">
<h2 className="text-md mb-2">Aggregate Data</h2>
Expand All @@ -180,7 +180,7 @@ export const FCETable = ({
<div className="bg-white flex-1 rounded p-2">
<div className="flex content-end">
<div className="hidden lg:block">
<StarRating rating={aggregateData.teachingRate} />
<StarRating rating={Number(aggregateData.teachingRate)} />
</div>
<span className="text-xl lg:ml-2">
{aggregateData.teachingRate}
Expand All @@ -193,7 +193,7 @@ export const FCETable = ({
<div className="bg-white flex-1 rounded p-2">
<div className="flex content-end">
<div className="hidden lg:block">
<StarRating rating={aggregateData.courseRate} />
<StarRating rating={Number(aggregateData.courseRate)} />
</div>
<span className="text-xl lg:ml-2">
{aggregateData.courseRate}
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/ScheduleSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -70,14 +70,14 @@ const CourseCombobox = ({
selectedItems,
} = useMultipleSelection<selectedItem>({
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, []),
});

Expand All @@ -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) {
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = {
};

export const Toast = (t: ToastType, { message, title, icon }: Props) => {
const Icon = icon;
const Icon = icon || (() => <div />);

return (
<div
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/filters/CourseFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ const CourseFilter = ({ name } : Props) => {

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[]) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/course/[courseID].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const CourseDetailPage: NextPage = () => {
);

if (info) {
content = <CourseDetail info={info} schedules={schedules} />;
content = <CourseDetail info={info} schedules={schedules || []} />;
}

return (
Expand Down

0 comments on commit 03a4b34

Please sign in to comment.