aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer/src/components/banner/NewWindowBanner.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/renderer/src/components/banner/NewWindowBanner.tsx')
-rw-r--r--packages/renderer/src/components/banner/NewWindowBanner.tsx117
1 files changed, 117 insertions, 0 deletions
diff --git a/packages/renderer/src/components/banner/NewWindowBanner.tsx b/packages/renderer/src/components/banner/NewWindowBanner.tsx
new file mode 100644
index 0000000..478de8e
--- /dev/null
+++ b/packages/renderer/src/components/banner/NewWindowBanner.tsx
@@ -0,0 +1,117 @@
1/*
2 * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21import IconOpenInBrowser from '@mui/icons-material/OpenInBrowser';
22import IconOpenInNew from '@mui/icons-material/OpenInNew';
23import Button from '@mui/material/Button';
24import { observer } from 'mobx-react-lite';
25import React from 'react';
26import { Trans, useTranslation } from 'react-i18next';
27
28import type Service from '../../stores/Service';
29
30import NotificationBanner from './NotificationBanner';
31
32function NewWindowBanner({
33 service,
34}: {
35 service: Service | undefined;
36}): JSX.Element | null {
37 const { t } = useTranslation(undefined, {
38 keyPrefix: 'banner.newWindow',
39 });
40
41 if (service === undefined) {
42 // eslint-disable-next-line unicorn/no-null -- React requires `null` to skip rendering.
43 return null;
44 }
45
46 const {
47 popups,
48 settings: { name },
49 } = service;
50 const { length: count } = popups;
51
52 if (count === 0) {
53 // eslint-disable-next-line unicorn/no-null -- React requires `null` to skip rendering.
54 return null;
55 }
56
57 const url = popups[count - 1];
58
59 return (
60 <NotificationBanner
61 severity="warning"
62 icon={<IconOpenInNew fontSize="inherit" />}
63 onClose={() => service.dismissAllPopups()}
64 buttons={
65 <>
66 <Button
67 onClick={() => service.followPopup(url)}
68 color="inherit"
69 size="small"
70 >
71 {t('followLink')}
72 </Button>
73 <Button
74 onClick={() => service.openPopupInExternalBrowser(url)}
75 color="inherit"
76 size="small"
77 startIcon={<IconOpenInBrowser />}
78 >
79 {t('openInExternalBrowser')}
80 </Button>
81 {count > 1 && (
82 <>
83 <Button
84 onClick={() => service.openAllPopupsInExternalBrowser()}
85 color="inherit"
86 size="small"
87 startIcon={<IconOpenInBrowser />}
88 >
89 {t('openAllInExternalBrowser')}
90 </Button>
91 <Button
92 onClick={() => service.dismissPopup(url)}
93 color="inherit"
94 size="small"
95 >
96 {t('dismiss')}
97 </Button>
98 </>
99 )}
100 </>
101 }
102 >
103 {count === 1 ? (
104 <Trans i18nKey="messageSingleLink" t={t}>
105 {{ name }} wants to open <strong>{{ url }}</strong> in a new window
106 </Trans>
107 ) : (
108 <Trans i18nKey="messageMultipleLinks" count={count - 1} t={t}>
109 {{ name }} wants to open <strong>{{ url }}</strong> and{' '}
110 <strong>{{ count: count - 1 }}</strong> other links in new windows
111 </Trans>
112 )}
113 </NotificationBanner>
114 );
115}
116
117export default observer(NewWindowBanner);