Update all non-major dependencies
[ProtonMail-WebClient.git] / applications / calendar / src / app / containers / alarms / getCalendarsAlarmsCached.ts
blobb0e17d5b68190e6ed5e7e0b582ff240f8995fd58
1 import type { Api } from '@proton/shared/lib/interfaces';
3 import type { CalendarAlarmCache } from './CacheInterface';
4 import getPaginatedAlarms from './getPaginatedAlarms';
6 const getCalendarsAlarmsCached = (api: Api, cache: CalendarAlarmCache, calendarIDs: string[], dateRange: Date[]) => {
7     const promises = calendarIDs.map((calendarID) => {
8         if (cache[calendarID] && cache[calendarID].promise) {
9             return cache[calendarID].promise;
10         }
11         if (cache[calendarID] && cache[calendarID].result) {
12             return;
13         }
15         const promise = getPaginatedAlarms(api, calendarID, dateRange)
16             .then((result) => {
17                 cache[calendarID] = {
18                     result,
19                 };
20             })
21             .catch(() => {
22                 delete cache[calendarID];
23             });
25         cache[calendarID] = {
26             promise,
27         };
29         return promise;
30     });
31     return Promise.all(promises);
34 export default getCalendarsAlarmsCached;