Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / shared / lib / drawer / calendar.ts
blob4dbf17635365585f583131858c27d28774c12c84
1 import type { Dispatch, SetStateAction } from 'react';
3 import { getAppHref } from '../apps/helper';
4 import { getLinkToCalendarEvent } from '../calendar/helper';
5 import type { APP_NAMES } from '../constants';
6 import { APPS } from '../constants';
7 import { addParentAppToUrl, postMessageToIframe } from './helpers';
8 import type { DrawerApp, IframeSrcMap } from './interfaces';
9 import { DRAWER_EVENTS } from './interfaces';
11 const { PROTONCALENDAR: calendarApp } = APPS;
13 interface OpenCalendarEventProps {
14     currentApp: APP_NAMES;
15     setAppInView: Dispatch<SetStateAction<DrawerApp | undefined>>;
16     iframeSrcMap: IframeSrcMap;
17     setIframeSrcMap: Dispatch<SetStateAction<IframeSrcMap>>;
18     localID?: number;
19     calendarID: string;
20     eventID: string;
21     recurrenceID?: number;
24 export const openCalendarEventInDrawer = ({
25     currentApp,
26     setAppInView,
27     iframeSrcMap,
28     setIframeSrcMap,
29     localID,
30     calendarID,
31     eventID,
32     recurrenceID,
33 }: OpenCalendarEventProps) => {
34     if (!iframeSrcMap[calendarApp]) {
35         const linkTo = getLinkToCalendarEvent({ calendarID, eventID, recurrenceID });
36         const appHref = getAppHref(linkTo, calendarApp, localID);
38         setAppInView(calendarApp);
39         setIframeSrcMap((map) => ({
40             ...map,
41             [calendarApp]: addParentAppToUrl(appHref, currentApp, false),
42         }));
43     } else {
44         postMessageToIframe(
45             {
46                 type: DRAWER_EVENTS.CALENDAR_OPEN_EVENT,
47                 payload: { calendarID, eventID, recurrenceID },
48             },
49             calendarApp
50         );
51     }
53     setAppInView(calendarApp);