diff --git a/src/components/search/Filters/filters.tsx b/src/components/search/Filters/filters.tsx index ccc4b707..1c1a49f3 100644 --- a/src/components/search/Filters/filters.tsx +++ b/src/components/search/Filters/filters.tsx @@ -4,21 +4,16 @@ import { InputLabel, ListItemText, MenuItem, + Tooltip, } from '@mui/material'; import Select, { type SelectChangeEvent } from '@mui/material/Select'; import { useRouter } from 'next/router'; import React, { useEffect, useState } from 'react'; import Rating from '@/components/common/Rating/rating'; +import gpaToLetterGrade from '@/modules/gpaToLetterGrade/gpaToLetterGrade'; -const minGPAs = [ - ['3.67', 'A-'], - ['3.33', 'B+'], - ['3', 'B'], - ['2.67', 'B-'], - ['2.33', 'C+'], - ['2', 'C'], -]; +const minGPAs = ['3.67', '3.33', '3', '2.67', '2.33', '2']; const minRatings = ['4.5', '4', '3.5', '3', '2.5', '2', '1.5', '1', '0.5']; interface FiltersProps { @@ -138,166 +133,187 @@ const Filters = ({ return (
- {/* min GPA dropdown*/} - - Min Letter Grade - { + onChange(event.target.value, 'minGPA', setMinGPA); + }} + > + + None - ))} - - + {/* dropdown options*/} + {minGPAs.map((value) => ( + + {gpaToLetterGrade(Number(value))} + + ))} + + + {/* min rating dropdown*/} - - Min Rating - { + onChange(event.target.value, 'minRating', setMinRating); + }} + renderValue={(value) => ( + )} + > + + None - ))} - - + {/* dropdown options*/} + {minRatings.map((value) => ( + + + + ))} + + + {/* semester dropdown */} - - Semesters - ) => { + const { + target: { value }, + } = event; + if (value.includes('select-all')) { + if (chosenSessions.length === academicSessions.length) { + addChosenSessions(() => []); + } else { + addChosenSessions(() => academicSessions); + } + } else if (value.includes('recent')) { + if ( chosenSessions.length === recentSemesters.length && chosenSessions.every((el) => recentSemesters.includes(el)) - ) // select-all is not indeterminate when recent is checked + ) { + addChosenSessions(() => academicSessions); + } else { + addChosenSessions(() => recentSemesters); + } + } else { + addChosenSessions(() => value as string[]); } - disabled={academicSessions.length == 0} - /> - 0 ? '' : 'text-gray-400'} - primary="Select All" - /> - - - {/* recent sessions -- last long-semesters from current semester*/} - - 0 && - chosenSessions.length === recentSemesters.length && - chosenSessions.every((el) => recentSemesters.includes(el)) + }} + renderValue={(selected) => { + if (chosenSessions.length === academicSessions.length) { + return 'All selected'; } - disabled={recentSemesters.length == 0} - /> - 0 ? '' : 'text-gray-400'} - primary="Recent" - /> - + return selected.sort((a, b) => compareSemesters(a, b)).join(', '); + }} + MenuProps={{ autoFocus: false }} + > + {/* select all sessions */} + + 0 && + chosenSessions.length === academicSessions.length + } + indeterminate={ + chosenSessions.length !== academicSessions.length && + chosenSessions.length !== 0 && + !( + chosenSessions.length === recentSemesters.length && + chosenSessions.every((el) => recentSemesters.includes(el)) + ) // select-all is not indeterminate when recent is checked + } + disabled={academicSessions.length == 0} + /> + 0 ? '' : 'text-gray-400'} + primary="Select All" + /> + - {/* indiv options */} - {academicSessions.map((session) => ( - - - + {/* recent sessions -- last long-semesters from current semester*/} + + 0 && + chosenSessions.length === recentSemesters.length && + chosenSessions.every((el) => recentSemesters.includes(el)) + } + disabled={recentSemesters.length == 0} + /> + 0 ? '' : 'text-gray-400'} + primary="Recent" + /> - ))} - - + + {/* indiv options */} + {academicSessions.map((session) => ( + + + + + ))} + + +
); }; diff --git a/src/components/search/SearchResultsTable/searchResultsTable.tsx b/src/components/search/SearchResultsTable/searchResultsTable.tsx index 119deb90..88860d04 100644 --- a/src/components/search/SearchResultsTable/searchResultsTable.tsx +++ b/src/components/search/SearchResultsTable/searchResultsTable.tsx @@ -21,6 +21,7 @@ import SingleGradesInfo from '@/components/common/SingleGradesInfo/singleGradesI import SingleProfInfo from '@/components/common/SingleProfInfo/singleProfInfo'; import TableSortLabel from '@/components/common/TableSortLabel/tableSortLabel'; import { useRainbowColors } from '@/modules/colors/colors'; +import gpaToLetterGrade from '@/modules/gpaToLetterGrade/gpaToLetterGrade'; import { convertToProfOnly, type SearchQuery, @@ -30,21 +31,6 @@ import { import type { RMPInterface } from '@/pages/api/ratemyprofessorScraper'; import type { GenericFetchedData, GradesType } from '@/pages/dashboard/index'; -const gpaToLetterGrade = (gpa: number): string => { - if (gpa >= 4.0) return 'A'; - if (gpa >= 3.67) return 'A-'; - if (gpa >= 3.33) return 'B+'; - if (gpa >= 3.0) return 'B'; - if (gpa >= 2.67) return 'B-'; - if (gpa >= 2.33) return 'C+'; - if (gpa >= 2.0) return 'C'; - if (gpa >= 1.67) return 'C-'; - if (gpa >= 1.33) return 'D+'; - if (gpa >= 1.0) return 'D'; - if (gpa >= 0.67) return 'D-'; - return 'F'; -}; - function LoadingRow() { return ( @@ -475,7 +461,7 @@ const SearchResultsTable = ({
diff --git a/src/modules/gpaToLetterGrade/gpaToLetterGrade.tsx b/src/modules/gpaToLetterGrade/gpaToLetterGrade.tsx new file mode 100644 index 00000000..8a95b777 --- /dev/null +++ b/src/modules/gpaToLetterGrade/gpaToLetterGrade.tsx @@ -0,0 +1,16 @@ +function gpaToLetterGrade(gpa: number): string { + if (gpa >= 4.0) return 'A'; + if (gpa >= 3.67) return 'A-'; + if (gpa >= 3.33) return 'B+'; + if (gpa >= 3.0) return 'B'; + if (gpa >= 2.67) return 'B-'; + if (gpa >= 2.33) return 'C+'; + if (gpa >= 2.0) return 'C'; + if (gpa >= 1.67) return 'C-'; + if (gpa >= 1.33) return 'D+'; + if (gpa >= 1.0) return 'D'; + if (gpa >= 0.67) return 'D-'; + return 'F'; +} + +export default gpaToLetterGrade;