RightPaneStore.updateFormValue(field, value)}
+ changeTerm={(field: string, value: string) => RightPaneStore.updateFormValue(field, value)}
fieldName={'term'}
/>
diff --git a/apps/antalmanac/src/components/RightPane/CoursePane/SearchForm/TermSelector.tsx b/apps/antalmanac/src/components/RightPane/CoursePane/SearchForm/TermSelector.tsx
index 344839614..0efc8ed68 100644
--- a/apps/antalmanac/src/components/RightPane/CoursePane/SearchForm/TermSelector.tsx
+++ b/apps/antalmanac/src/components/RightPane/CoursePane/SearchForm/TermSelector.tsx
@@ -1,71 +1,64 @@
-import FormControl from '@material-ui/core/FormControl';
-import InputLabel from '@material-ui/core/InputLabel';
-import MenuItem from '@material-ui/core/MenuItem';
-import Select from '@material-ui/core/Select';
-import { ChangeEvent, PureComponent } from 'react';
+import { FormControl, InputLabel, MenuItem, Select } from '@material-ui/core';
+import { ChangeEvent, useEffect, useState } from 'react';
import RightPaneStore from '../../RightPaneStore';
import { termData } from '$lib/termData';
interface TermSelectorProps {
- changeState: (field: string, value: string) => void;
+ changeTerm: (field: string, value: string) => void;
fieldName: string;
}
-class TermSelector extends PureComponent {
- updateTermAndGetFormData() {
- RightPaneStore.updateFormValue('term', RightPaneStore.getUrlTermValue());
- return RightPaneStore.getFormData().term;
- }
+function TermSelector(props: TermSelectorProps) {
+ const { changeTerm, fieldName } = props;
- getTerm() {
- return RightPaneStore.getUrlTermValue() ? this.updateTermAndGetFormData() : RightPaneStore.getFormData().term;
- }
+ const getTerm = () => {
+ const urlTerm = RightPaneStore.getUrlTermValue();
- state = {
- term: this.getTerm(),
- };
+ if (urlTerm) {
+ RightPaneStore.updateFormValue('term', urlTerm);
+ }
- resetField = () => {
- this.setState({ term: RightPaneStore.getFormData().term });
+ return RightPaneStore.getFormData().term;
};
- componentDidMount = () => {
- RightPaneStore.on('formReset', this.resetField);
- };
+ const [term, setTerm] = useState(getTerm());
- componentWillUnmount() {
- RightPaneStore.removeListener('formReset', this.resetField);
- }
+ const handleChange = (event: ChangeEvent<{ name?: string | undefined; value: unknown }>) => {
+ const newValue = event.target.value as string;
- handleChange = (event: ChangeEvent<{ name?: string | undefined; value: unknown }>) => {
- this.setState({ term: event.target.value });
- this.props.changeState(this.props.fieldName, event.target.value as string);
+ setTerm(newValue);
+ changeTerm(fieldName, newValue);
- const stateObj = { url: 'url' };
- const url = new URL(window.location.href);
- const urlParam = new URLSearchParams(url.search);
- urlParam.delete('term');
- urlParam.append('term', event.target.value as string);
- const param = urlParam.toString();
- const new_url = `${param && param !== 'null' ? '?' : ''}${param}`;
- history.replaceState(stateObj, 'url', '/' + new_url);
+ const urlParams = new URLSearchParams(window.location.search);
+ urlParams.set('term', newValue);
+ history.replaceState({ url: 'url' }, 'url', `/?${urlParams}`);
};
- render() {
- return (
-
- Term
-
-
- );
- }
+ const resetField = () => {
+ setTerm(RightPaneStore.getFormData().term);
+ };
+
+ useEffect(() => {
+ RightPaneStore.on('formReset', resetField);
+
+ return () => {
+ RightPaneStore.off('formReset', resetField);
+ };
+ });
+
+ return (
+
+ Term
+
+
+ );
}
export default TermSelector;
diff --git a/apps/antalmanac/src/lib/websoc.ts b/apps/antalmanac/src/lib/websoc.ts
index 5bed3e793..c79b1c3a1 100644
--- a/apps/antalmanac/src/lib/websoc.ts
+++ b/apps/antalmanac/src/lib/websoc.ts
@@ -58,6 +58,7 @@ class _WebSOC {
async getCourseInfo(websoc_params: Record) {
const SOCObject = await this.query(websoc_params);
+
const courseInfo: { [sectionCode: string]: CourseInfo } = {};
for (const school of SOCObject.schools) {
for (const department of school.departments) {