Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom event to the route #853

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions apps/antalmanac/src/components/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -181,6 +181,20 @@ export default function CourseMap() {
};
}, []);

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

AppStore.on('customEventsChange', updateCustomEventMarkers);
AppStore.on('currentScheduleIndexChange', updateCustomEventMarkers);

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

useEffect(() => {
const locationID = Number(searchParams.get('location') ?? 0);
const building = locationID in buildingCatalogue ? buildingCatalogue[locationID] : undefined;
Expand Down Expand Up @@ -274,14 +288,15 @@ export default function CourseMap() {
* Every two markers grouped as [start, destination] tuples for the routes.
*/
const startDestPairs = useMemo(() => {
return markersToDisplay.reduce((acc, cur, index) => {
const allEvents = [...markersToDisplay, ...customEventMarkersToDisplay];
KevinWu098 marked this conversation as resolved.
Show resolved Hide resolved
return allEvents.reduce((acc, cur, index) => {
acc.push([cur]);
if (index > 0) {
acc[index - 1].push(cur);
}
return acc;
}, [] as (typeof markersToDisplay)[]);
}, [markersToDisplay]);
}, [] as (typeof allEvents)[]);
}, [markersToDisplay, customEventMarkersToDisplay]);

return (
<Box sx={{ width: '100%', display: 'flex', flexDirection: 'column', flexGrow: 1, height: '100%' }}>
Expand Down
Loading