aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer/src/components/NewWindowBanner.tsx
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-03-28 23:37:15 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-05-16 00:54:56 +0200
commit04555cc62c9cded08c3090288fa372d961c50737 (patch)
tree4566893892216446dfe24490c98881316b97cb41 /packages/renderer/src/components/NewWindowBanner.tsx
parentdesign: Increase location bar UI density (diff)
downloadsophie-04555cc62c9cded08c3090288fa372d961c50737.tar.gz
sophie-04555cc62c9cded08c3090288fa372d961c50737.tar.zst
sophie-04555cc62c9cded08c3090288fa372d961c50737.zip
feat: New window banner
* Add renderer code for notification banners with buttons * Handle new window open requests by denying them and displaying a notification Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/renderer/src/components/NewWindowBanner.tsx')
-rw-r--r--packages/renderer/src/components/NewWindowBanner.tsx110
1 files changed, 110 insertions, 0 deletions
diff --git a/packages/renderer/src/components/NewWindowBanner.tsx b/packages/renderer/src/components/NewWindowBanner.tsx
new file mode 100644
index 0000000..a49b4b1
--- /dev/null
+++ b/packages/renderer/src/components/NewWindowBanner.tsx
@@ -0,0 +1,110 @@
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';
26
27import type Service from '../stores/Service';
28
29import NotificationBanner from './NotificationBanner';
30
31function NewWindowBanner({
32 service,
33}: {
34 service: Service | undefined;
35}): JSX.Element | null {
36 if (service === undefined) {
37 // eslint-disable-next-line unicorn/no-null -- React requires `null` to skip rendering.
38 return null;
39 }
40
41 const {
42 popups,
43 settings: { name },
44 } = service;
45 const { length: count } = popups;
46
47 if (count === 0) {
48 // eslint-disable-next-line unicorn/no-null -- React requires `null` to skip rendering.
49 return null;
50 }
51
52 const url = popups[count - 1];
53
54 return (
55 <NotificationBanner
56 severity="warning"
57 icon={<IconOpenInNew fontSize="inherit" />}
58 onClose={() => service.dismissAllPopups()}
59 buttons={
60 <>
61 <Button
62 onClick={() => service.followPopup(url)}
63 color="inherit"
64 size="small"
65 >
66 Follow link in this window
67 </Button>
68 <Button
69 onClick={() => service.openPopupInExternalBrowser(url)}
70 color="inherit"
71 size="small"
72 startIcon={<IconOpenInBrowser />}
73 >
74 Open in browser
75 </Button>
76 {count > 1 && (
77 <>
78 <Button
79 onClick={() => service.openAllPopupsInExternalBrowser()}
80 color="inherit"
81 size="small"
82 startIcon={<IconOpenInBrowser />}
83 >
84 Open all
85 </Button>
86 <Button
87 onClick={() => service.dismissPopup(url)}
88 color="inherit"
89 size="small"
90 >
91 Ignore
92 </Button>
93 </>
94 )}
95 </>
96 }
97 >
98 {name} wants to open <b>{url}</b>{' '}
99 {count === 1 ? (
100 <>in a new window</>
101 ) : (
102 <>
103 and <b>{count}</b> other links in new windows
104 </>
105 )}
106 </NotificationBanner>
107 );
108}
109
110export default observer(NewWindowBanner);