@@ -12,7 +12,7 @@ import TextField from '@mui/material/TextField'
1212
1313import { omit , sortBy } from 'lodash'
1414import { useEffect , useState } from 'react'
15- import { useLocation , useNavigate } from 'react-router'
15+ import { useNavigate } from 'react-router'
1616
1717import { validateInputLength } from '@/common'
1818import { useLanguage } from '@/components/LanguagePicker/useLanguage'
@@ -23,10 +23,8 @@ import { useDebouncedState } from '@/hooks/debouncedState'
2323import { useSearchHistory } from '@/hooks/searchHistory'
2424import { useToggle } from '@/hooks/toggle'
2525import { useGetCourseSearchResultQuery } from '@/redux/courseSearch'
26- import { getCourseStats , clearCourseStats } from '@/redux/courseStats'
27- import { useAppDispatch , useAppSelector } from '@/redux/hooks'
2826import { SearchHistoryItem } from '@/types/searchHistory'
29- import { parseQueryParams , queryParamsToString } from '@/util/queryparams'
27+ import { queryParamsToString } from '@/util/queryparams'
3028import { MemoizedCourseTable as CourseTable } from './CourseTable'
3129import { FetchStatisticsButton } from './FetchStatisticsButton'
3230import { MultipleCoursesAlert } from './MultipleCoursesAlert'
@@ -35,12 +33,9 @@ import { MultipleCoursesAlert } from './MultipleCoursesAlert'
3533// fail if the courses have small populations (this used to be limited to 40)
3634const MAX_SELECTED_COURSES = 99999
3735
38- export const SearchForm = ( { onProgress , progress } ) => {
36+ export const SearchForm = ( { progress , isPending } ) => {
3937 const { getTextIn } = useLanguage ( )
40- const dispatch = useAppDispatch ( )
41- const location = useLocation ( )
4238 const navigate = useNavigate ( )
43- const isLoadingCourseStats = useAppSelector ( state => state . courseStats . pending )
4439 const [ combineSubstitutions , toggleCombineSubstitutions ] = useToggle ( true )
4540 const [ selectMultipleCourses , toggleSelectMultipleCourses ] = useToggle ( false )
4641 const [ courseName , setCourseName ] = useState ( '' )
@@ -71,33 +66,6 @@ export const SearchForm = ({ onProgress, progress }) => {
7166 setDebouncedCourseCode ( event . target . value )
7267 }
7368
74- const parseQueryFromUrl = ( ) => {
75- const search = parseQueryParams ( location . search )
76- const query = {
77- courseCodes : JSON . parse ( search . courseCodes as string ) ,
78- separate : JSON . parse ( search . separate as string ) ,
79- combineSubstitutions : search . combineSubstitutionsFrom ?? JSON . parse ( combineSubstitutions . toString ( ) ) ,
80- }
81- return query
82- }
83-
84- const fetchStatisticsFromUrlParams = ( ) => {
85- const query = parseQueryFromUrl ( )
86- dispatch ( getCourseStats ( query , onProgress ) )
87- }
88-
89- useEffect ( ( ) => {
90- if ( ! location . search ) {
91- dispatch ( clearCourseStats ( ) )
92- }
93- } , [ ] )
94-
95- useEffect ( ( ) => {
96- if ( location . search && location . search !== '?tab=0' ) {
97- fetchStatisticsFromUrlParams ( )
98- }
99- } , [ location . search ] )
100-
10169 const onSelectCourse = course => {
10270 const isSelected = ! ! selectedCourses [ course . code ]
10371
@@ -166,8 +134,8 @@ export const SearchForm = ({ onProgress, progress }) => {
166134 const courses = matchingCourses . filter ( course => ! selectedCourses [ course . code ] )
167135
168136 const selected = Object . values ( selectedCourses )
169- const noSelectedCourses = selected . length === 0
170- const disabled = isLoadingCourseStats || noSelectedCourses || selected . length > MAX_SELECTED_COURSES
137+ const noSelectedCourses = ! selected . length
138+ const disabled = isPending ?? noSelectedCourses ?? selected . length > MAX_SELECTED_COURSES
171139
172140 const addAllCourses = ( ) => {
173141 const newSelectedCourses = courses . reduce ( ( newSelected , course ) => {
@@ -183,7 +151,7 @@ export const SearchForm = ({ onProgress, progress }) => {
183151
184152 return (
185153 < Stack gap = { 2 } >
186- < Backdrop open = { isLoadingCourseStats } sx = { { color : '#fff' , zIndex : theme => theme . zIndex . drawer + 1 } } >
154+ < Backdrop open = { isPending } sx = { { color : '#fff' , zIndex : theme => theme . zIndex . drawer + 1 } } >
187155 < CircularProgress color = "inherit" value = { progress } variant = "determinate" />
188156 </ Backdrop >
189157 < Section title = "Search for courses" >
@@ -279,10 +247,7 @@ export const SearchForm = ({ onProgress, progress }) => {
279247 ) }
280248 < CourseTable
281249 courses = { courses }
282- hidden = {
283- isLoadingCourseStats ||
284- ( Object . keys ( courses ) . length === 0 && Object . keys ( selectedCourses ) . length > 0 )
285- }
250+ hidden = { isPending ?? ( ! Object . keys ( courses ) . length && ! Object . keys ( selectedCourses ) . length ) }
286251 onSelectCourse = { onSelectCourse }
287252 title = "Searched courses"
288253 />
0 commit comments