Skip to content

Commit

Permalink
add calendar event loading logs
Browse files Browse the repository at this point in the history
  • Loading branch information
lucia-gomez committed Sep 17, 2024
1 parent 89779e9 commit 9412856
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,36 @@ export default function fetchCalendarEvents(allRooms: RoomSetting[]) {
const [events, setEvents] = useState<CalendarEvent[]>([]);

const loadEvents = useCallback(() => {
//TODO: Fix this after getting title from prodcalendars
Promise.all(allRooms.map(fetchRoomCalendarEvents)).then((results) =>
setEvents(
[...results.flat()].filter(
Promise.all(allRooms.map(fetchRoomCalendarEvents)).then(
(results) => {
const flatResults = results.flat();
console.log(
"FETCHED CALENDAR RESULTS FOR EACH ROOM (flat)",
flatResults
);
const filtered = flatResults.filter(
(event) =>
!CALENDAR_HIDE_STATUS.some((status) =>
event?.title?.includes(status)
!CALENDAR_HIDE_STATUS.some((hideStatus) =>
event.title?.includes(hideStatus)
)
)
)
);
console.log("FILTERED", filtered);
setEvents(filtered);
}
// setEvents(
// [...results.flat()].filter(
// (event) =>
// !CALENDAR_HIDE_STATUS.some((status) =>
// event?.title?.includes(status)
// )
// )
// )
);
}, [allRooms]);

useEffect(() => {
loadEvents();
}, [loadEvents]);
}, [allRooms]);

const fetchRoomCalendarEvents = async (room: RoomSetting) => {
const calendarId = room.calendarId;
Expand All @@ -48,22 +62,22 @@ export default function fetchCalendarEvents(allRooms: RoomSetting[]) {
};

// TODO add this back or delete it
const getFakeEvents: () => CalendarEvent[] = () => {
const existingFakeData = localStorage.getItem(STORAGE_KEY_BOOKING);
if (existingFakeData != null && process.env.BRANCH_NAME === "development") {
const json = JSON.parse(existingFakeData);
return json.bookingRows.map((booking: Booking) => ({
title: `[${getBookingStatus(booking, json.bookingStatusRows)}] ${
booking.title
}`,
start: booking.startDate,
end: booking.endDate,
id: booking.roomId,
resourceId: booking.roomId,
}));
}
return [];
};
// const getFakeEvents: () => CalendarEvent[] = () => {
// const existingFakeData = localStorage.getItem(STORAGE_KEY_BOOKING);
// if (existingFakeData != null && process.env.BRANCH_NAME === "development") {
// const json = JSON.parse(existingFakeData);
// return json.bookingRows.map((booking: Booking) => ({
// title: `[${getBookingStatus(booking, json.bookingStatusRows)}] ${
// booking.title
// }`,
// start: booking.startDate,
// end: booking.endDate,
// id: booking.roomId,
// resourceId: booking.roomId,
// }));
// }
// return [];
// };

return {
existingCalendarEvents: events,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export const DatabaseProvider = ({
fetchBannedUsers();
fetchLiaisonUsers();
fetchDepartmentNames();
fetchRoomSettings();
fetchSettings();
} else {
fetchBookings();
Expand All @@ -132,6 +131,7 @@ export const DatabaseProvider = ({
fetchActiveUserEmail();
fetchAdminUsers();
fetchPaUsers();
fetchRoomSettings();
}, [user]);

const fetchActiveUserEmail = () => {
Expand Down

0 comments on commit 9412856

Please sign in to comment.