Skip to content

Commit

Permalink
Update fetchCalendarEvents.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
lucia-gomez committed Sep 17, 2024
1 parent 31af26a commit 181379e
Showing 1 changed file with 18 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,40 +1,29 @@
import { Booking, CalendarEvent, RoomSetting } from "../../../../types";
import { CALENDAR_HIDE_STATUS, STORAGE_KEY_BOOKING } from "../../../../policy";
import { useCallback, useEffect, useMemo, useState } from "react";
import { CalendarEvent, RoomSetting } from "../../../../types";
import { useCallback, useEffect, useState } from "react";

import { CALENDAR_HIDE_STATUS } from "../../../../policy";
import axios from "axios";
import getBookingStatus from "../../hooks/getBookingStatus";

export default function fetchCalendarEvents(allRooms: RoomSetting[]) {
const [events, setEvents] = useState<CalendarEvent[]>([]);

const loadEvents = useCallback(() => {
Promise.all(allRooms.map(fetchRoomCalendarEvents)).then(
(results) => {
const flatResults = results.flat();
console.log("FETCHED CALENDAR RESULTS:", flatResults.length);
const filtered = flatResults.filter(
(event) =>
!CALENDAR_HIDE_STATUS.some((hideStatus) =>
event.title?.includes(hideStatus)
)
);
if (filtered.length === 0 && events.length > 0) {
console.log("!!! RE-FETCHING CALENDAR EVENTS WAS EMPTY !!!");
} else {
setEvents(filtered);
}
Promise.all(allRooms.map(fetchRoomCalendarEvents)).then((results) => {
const flatResults = results.flat();
console.log("FETCHED CALENDAR RESULTS:", flatResults.length);
const filtered = flatResults.filter(
(event) =>
!CALENDAR_HIDE_STATUS.some((hideStatus) =>
event.title?.includes(hideStatus)
)
);
if (filtered.length === 0 && events.length > 0) {
console.log("!!! RE-FETCHING CALENDAR EVENTS WAS EMPTY !!!");
} else {
setEvents(filtered);
}
// setEvents(
// [...results.flat()].filter(
// (event) =>
// !CALENDAR_HIDE_STATUS.some((status) =>
// event?.title?.includes(status)
// )
// )
// )
);
}, [allRooms]);
});
}, [allRooms, events]);

useEffect(() => {
loadEvents();
Expand Down

0 comments on commit 181379e

Please sign in to comment.