1 import { c } from 'ttag';
3 import { Button, ButtonLike } from '@proton/atoms';
4 import SimpleDropdown from '@proton/components/components/dropdown/SimpleDropdown';
5 import Icon from '@proton/components/components/icon/Icon';
6 import useConfig from '@proton/components/hooks/useConfig';
7 import type { APP_NAMES } from '@proton/shared/lib/constants';
8 import { APPS, BRAND_NAME, CALENDAR_APP_NAME, MAIL_APP_NAME } from '@proton/shared/lib/constants';
9 import type { CHANGE_VIEW_TARGET } from '@proton/shared/lib/desktop/desktopTypes';
10 import { invokeInboxDesktopIPC } from '@proton/shared/lib/desktop/ipcHelpers';
11 import { isElectronOnMac } from '@proton/shared/lib/helpers/desktop';
12 import clsx from '@proton/utils/clsx';
14 import ProductIcon from '../app/ProductIcon';
17 appToLinkTo?: APP_NAMES;
20 const INBOX_DESKTOP_APPS = [APPS.PROTONMAIL, APPS.PROTONCALENDAR] as const satisfies APP_NAMES[];
22 const APP_TO_VIEW_TARGET: { [key in (typeof INBOX_DESKTOP_APPS)[number]]: CHANGE_VIEW_TARGET } = {
23 'proton-mail': 'mail',
24 'proton-calendar': 'calendar',
27 function InboxDesktopDefaultAppSwitcher({ appToLinkTo: currentApp }: Props) {
28 const handleClick = (target: CHANGE_VIEW_TARGET) => {
29 void invokeInboxDesktopIPC({ type: 'changeView', payload: target });
36 content={<Icon name="app-switch" size={6} className="apps-dropdown-button-icon shrink-0 no-print" />}
37 className="apps-dropdown-button shrink-0"
38 dropdownClassName="apps-dropdown rounded-lg"
39 originalPlacement="bottom-start"
40 title={c('Apps dropdown').t`${BRAND_NAME} applications`}
41 disableDefaultArrowNavigation
44 <ul className="unstyled my-0 p-4" style={{ '--apps-dropdown-repeat': '2' }}>
45 {INBOX_DESKTOP_APPS.map((app) => {
46 const current = app === currentApp;
49 <li className="dropdown-item apps-dropdown-item" data-testid="apps-dropdown-item" key={app}>
51 onClick={() => handleClick(APP_TO_VIEW_TARGET[app])}
52 className="text-center text-no-decoration outline-none--at-all apps-dropdown-link p-0"
53 aria-current={current}
56 <ProductIcon appToLinkTo={app} current={current} />
66 function InboxDesktopMacAppSwitcher({ appToLinkTo }: Props) {
67 const { APP_NAME } = useConfig();
68 const isAppMail = APP_NAME === APPS.PROTONMAIL || APPS.PROTONMAIL === appToLinkTo;
69 const isAppCalendar = APP_NAME === APPS.PROTONCALENDAR || APPS.PROTONCALENDAR === appToLinkTo;
71 const handleClick = (target: CHANGE_VIEW_TARGET) => {
72 void invokeInboxDesktopIPC({ type: 'changeView', payload: target });
76 <div className="flex flex-col gap-0.5">
78 onClick={() => handleClick('mail')}
79 className="flex items-center"
80 shape={isAppMail ? 'solid' : 'ghost'}
81 aria-current={isAppMail}
83 <Icon name="inbox" alt={MAIL_APP_NAME} className={clsx(isAppMail ? 'color-norm' : 'color-weak')} />
86 onClick={() => handleClick('calendar')}
87 className="flex items-center"
88 shape={isAppCalendar ? 'solid' : 'ghost'}
89 aria-current={isAppCalendar}
93 alt={CALENDAR_APP_NAME}
94 className={clsx(isAppCalendar ? 'color-norm' : 'color-weak')}
101 export function InboxDesktopAppSwitcher(props: Props) {
102 if (isElectronOnMac) {
103 return <InboxDesktopMacAppSwitcher {...props} />;
106 return <InboxDesktopDefaultAppSwitcher {...props} />;