-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c690f3
commit 75affab
Showing
4 changed files
with
64 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
apps/antalmanac/src/components/Calendar/calendar-event-popover.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Popover } from '@mui/material'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { shallow } from 'zustand/shallow'; | ||
|
||
import CourseCalendarEvent from '$components/Calendar/CourseCalendarEvent'; | ||
import AppStore from '$stores/AppStore'; | ||
import { useSelectedEventStore } from '$stores/SelectedEventStore'; | ||
|
||
export function CalendarEventPopover() { | ||
const [anchorEl, selectedEvent, setSelectedEvent] = useSelectedEventStore( | ||
(state) => [state.selectedEventAnchorEl, state.selectedEvent, state.setSelectedEvent], | ||
shallow | ||
); | ||
|
||
const [scheduleNames, setScheduleNames] = useState(() => AppStore.getScheduleNames()); | ||
|
||
const handleClosePopover = useCallback(() => { | ||
setSelectedEvent(null, null); | ||
}, [setSelectedEvent]); | ||
|
||
useEffect(() => { | ||
const updateScheduleNames = () => { | ||
setScheduleNames(AppStore.getScheduleNames()); | ||
}; | ||
|
||
AppStore.on('scheduleNamesChange', updateScheduleNames); | ||
|
||
return () => { | ||
AppStore.off('scheduleNamesChange', updateScheduleNames); | ||
}; | ||
}, []); | ||
|
||
if (!selectedEvent) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Popover | ||
anchorEl={anchorEl} | ||
open={Boolean(anchorEl) && !!selectedEvent} | ||
onClose={handleClosePopover} | ||
anchorOrigin={{ | ||
vertical: 'bottom', | ||
horizontal: 'left', | ||
}} | ||
transformOrigin={{ | ||
vertical: 'top', | ||
horizontal: 'left', | ||
}} | ||
> | ||
<CourseCalendarEvent | ||
closePopover={handleClosePopover} | ||
selectedEvent={selectedEvent} | ||
scheduleNames={scheduleNames} | ||
/> | ||
</Popover> | ||
); | ||
} |