diff --git a/apps/antalmanac/src/components/Map/Map.tsx b/apps/antalmanac/src/components/Map/Map.tsx index 569a740ec..f19689575 100644 --- a/apps/antalmanac/src/components/Map/Map.tsx +++ b/apps/antalmanac/src/components/Map/Map.tsx @@ -148,7 +148,7 @@ export default function CourseMap() { const [searchParams] = useSearchParams(); const [selectedDayIndex, setSelectedDay] = useState(0); const [markers, setMarkers] = useState(getCoursesPerBuilding()); - const [customEventMarkers] = useState(getCustomEventPerBuilding()); + const [customEventMarkers, setCustomEventMarkers] = useState(getCustomEventPerBuilding()); const [calendarEvents, setCalendarEvents] = useState(AppStore.getCourseEventsInCalendar()); useEffect(() => { @@ -167,6 +167,22 @@ export default function CourseMap() { }; }, []); + useEffect(() => { + const updateCustomEventMarkers = () => { + setCustomEventMarkers(getCustomEventPerBuilding()); + }; + + AppStore.on('customEventsChange', updateCustomEventMarkers); + AppStore.on('currentScheduleIndexChange', updateCustomEventMarkers); + AppStore.on('colorChange', updateCustomEventMarkers); + + return () => { + AppStore.removeListener('customEventsChange', updateCustomEventMarkers); + AppStore.removeListener('currentScheduleIndexChange', updateCustomEventMarkers); + AppStore.removeListener('colorChange', updateCustomEventMarkers); + }; + }, []); + useEffect(() => { const updateCalendarEvents = () => { setCalendarEvents(AppStore.getCourseEventsInCalendar());