Skip to content

Commit

Permalink
refactored custom event map load
Browse files Browse the repository at this point in the history
  • Loading branch information
adcockdalton committed Jan 17, 2024
1 parent c6cb5a8 commit 22163e2
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions apps/antalmanac/src/components/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,34 +152,21 @@ export default function CourseMap() {
const [calendarEvents, setCalendarEvents] = useState(AppStore.getCourseEventsInCalendar());

useEffect(() => {
const updateMarkers = () => {
const updateAllMarkers = () => {
setMarkers(getCoursesPerBuilding());
};

AppStore.on('addedCoursesChange', updateMarkers);
AppStore.on('currentScheduleIndexChange', updateMarkers);
AppStore.on('colorChange', updateMarkers);

return () => {
AppStore.removeListener('addedCoursesChange', updateMarkers);
AppStore.removeListener('currentScheduleIndexChange', updateMarkers);
AppStore.removeListener('colorChange', updateMarkers);
};
}, []);

useEffect(() => {
const updateCustomEventMarkers = () => {
setCustomEventMarkers(getCustomEventPerBuilding());
};

AppStore.on('customEventsChange', updateCustomEventMarkers);
AppStore.on('currentScheduleIndexChange', updateCustomEventMarkers);
AppStore.on('colorChange', updateCustomEventMarkers);
AppStore.on('addedCoursesChange', updateAllMarkers);
AppStore.on('customEventsChange', updateAllMarkers);
AppStore.on('currentScheduleIndexChange', updateAllMarkers);
AppStore.on('colorChange', updateAllMarkers);

return () => {
AppStore.removeListener('customEventsChange', updateCustomEventMarkers);
AppStore.removeListener('currentScheduleIndexChange', updateCustomEventMarkers);
AppStore.removeListener('colorChange', updateCustomEventMarkers);
AppStore.removeListener('addedCoursesChange', updateAllMarkers);
AppStore.removeListener('customEventsChange', updateAllMarkers);
AppStore.removeListener('currentScheduleIndexChange', updateAllMarkers);
AppStore.removeListener('colorChange', updateAllMarkers);
};
}, []);

Expand Down

0 comments on commit 22163e2

Please sign in to comment.