diff --git a/apps/antalmanac/src/components/Calendar/CalendarRoot.tsx b/apps/antalmanac/src/components/Calendar/CalendarRoot.tsx index bd3b20ae3..23c1180ef 100644 --- a/apps/antalmanac/src/components/Calendar/CalendarRoot.tsx +++ b/apps/antalmanac/src/components/Calendar/CalendarRoot.tsx @@ -254,7 +254,6 @@ class ScheduleCalendar extends PureComponent { +function getColors() { + const courseColors = AppStore.schedule.getCurrentCourses().reduce((accumulator, { section }) => { accumulator[section.sectionCode] = section.color; return accumulator; }, {} as { [key: string]: string }); + + return courseColors; +} + +const flattenSOCObject = (SOCObject: WebsocAPIResponse): (WebsocSchool | WebsocDepartment | AACourse)[] => { + const courseColors = getColors(); + return SOCObject.schools.reduce((accumulator: (WebsocSchool | WebsocDepartment | AACourse)[], school) => { accumulator.push(school); @@ -43,7 +49,7 @@ function flattenSOCObject(SOCObject: WebsocAPIResponse): (WebsocSchool | WebsocD }, []); } const RecruitmentBanner = () => { - const [bannerVisibility, setBannerVisibility] = React.useState(true); + const [bannerVisibility, setBannerVisibility] = useState(true); // Display recruitment banner if more than 11 weeks (in ms) has passed since last dismissal const recruitmentDismissalTime = window.localStorage.getItem('recruitmentDismissalTime'); @@ -54,7 +60,7 @@ const RecruitmentBanner = () => { const displayRecruitmentBanner = bannerVisibility && !dismissedRecently && isSearchCS; return ( -
+ {displayRecruitmentBanner ? ( { setBannerVisibility(false); }} > - + } > @@ -85,8 +91,8 @@ const RecruitmentBanner = () => {
We have opportunities for experienced devs and those with zero experience!
- ) : null}{' '} -
+ ) : null} + ); }; @@ -136,33 +142,38 @@ const SectionTableWrapped = ( return
{component}
; }; -export function CourseRenderPane() { +const LoadingMessage = () => { + return ( + + Loading courses + + ); +}; + +const ErrorMessage = () => { + return ( + + No Results Found + + ); +}; + +export default function CourseRenderPane() { + const [websocResp, setWebsocResp] = useState(); + const [courseData, setCourseData] = useState<(WebsocSchool | WebsocDepartment | AACourse)[]>([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(false); const [scheduleNames, setScheduleNames] = useState(AppStore.getScheduleNames()); - const [courseData, setCourseData] = useState<(WebsocSchool | WebsocDepartment | AACourse)[]>([]); const loadCourses = useCallback(async () => { setLoading(true); const formData = RightPaneStore.getFormData(); - const params = { - department: formData.deptValue, - term: formData.term, - ge: formData.ge, - courseNumber: formData.courseNumber, - sectionCodes: formData.sectionCode, - instructorName: formData.instructor, - units: formData.units, - endTime: formData.endTime, - startTime: formData.startTime, - fullCourses: formData.coursesFull, - building: formData.building, - room: formData.room, - division: formData.division, - }; - const websocQueryParams = { department: formData.deptValue, term: formData.term, @@ -194,6 +205,7 @@ export function CourseRenderPane() { ]); setError(false); + setWebsocResp(websocJsonResp); setCourseData(flattenSOCObject(websocJsonResp)); } catch (error) { console.error(error); @@ -204,95 +216,61 @@ export function CourseRenderPane() { } }, []); - useEffect(() => { - loadCourses(); - }, []); + const updateScheduleNames = () => { + setScheduleNames(AppStore.getScheduleNames()); + }; useEffect(() => { - const updateScheduleNames = () => { - setScheduleNames(AppStore.getScheduleNames()); + const changeColors = () => { + if (websocResp == null) { + return; + } + setCourseData(flattenSOCObject(websocResp)); }; - AppStore.on('scheduleNamesChange', updateScheduleNames); + AppStore.on('currentScheduleIndexChange', changeColors); return () => { - AppStore.off('scheduleNamesChange', updateScheduleNames); + AppStore.off('currentScheduleIndexChange', changeColors); }; - }, []); + }, [websocResp]); - if (loading) { - return ( -
- Loading courses -
- ); - } + useEffect(() => { + loadCourses(); + AppStore.on('scheduleNamesChange', updateScheduleNames); - if (error) { - return ( -
-
- No Results Found -
-
- ); - } + return () => { + AppStore.off('scheduleNamesChange', updateScheduleNames); + }; + }, [loadCourses]); return ( <> - -
-
- {courseData.length === 0 ? ( -
- No Results Found -
- ) : ( - courseData.map((_, index: number) => { - let heightEstimate = 200; - if ((courseData[index] as AACourse).sections !== undefined) - heightEstimate = (courseData[index] as AACourse).sections.length * 60 + 20 + 40; - - return ( - - {SectionTableWrapped(index, { courseData, scheduleNames })} - - ); - }) - )} -
+ {loading ? ( + + ) : error || courseData.length === 0 ? ( + + ) : ( + <> + + + + {courseData.map((_: WebsocSchool | WebsocDepartment | AACourse, index: number) => { + let heightEstimate = 200; + if ((courseData[index] as AACourse).sections !== undefined) + heightEstimate = (courseData[index] as AACourse).sections.length * 60 + 20 + 40; + return ( + + {SectionTableWrapped(index, { + courseData: courseData, + scheduleNames: scheduleNames, + })} + + ); + })} + + + )} ); } - -export default CourseRenderPane; diff --git a/apps/antalmanac/src/components/RightPane/SectionTable/SectionTableButtons.tsx b/apps/antalmanac/src/components/RightPane/SectionTable/SectionTableButtons.tsx index 951ae796a..60144ba43 100644 --- a/apps/antalmanac/src/components/RightPane/SectionTable/SectionTableButtons.tsx +++ b/apps/antalmanac/src/components/RightPane/SectionTable/SectionTableButtons.tsx @@ -52,6 +52,7 @@ export const ColorAndDelete = withStyles(styles)((props: ColorAndDeleteProps) =>