diff options
Diffstat (limited to 'packages/renderer/src/components/banner/NewWindowBanner.tsx')
-rw-r--r-- | packages/renderer/src/components/banner/NewWindowBanner.tsx | 131 |
1 files changed, 131 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..b9b0e4a --- /dev/null +++ b/packages/renderer/src/components/banner/NewWindowBanner.tsx | |||
@@ -0,0 +1,131 @@ | |||
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 | |||
21 | import ArrowBackIcon from '@mui/icons-material/ArrowBack'; | ||
22 | import ArrowForwardIcon from '@mui/icons-material/ArrowForward'; | ||
23 | import DoNotDisturbOnOutlinedIcon from '@mui/icons-material/DoNotDisturbOnOutlined'; | ||
24 | import OpenInBrowserIcon from '@mui/icons-material/OpenInBrowser'; | ||
25 | import OpenInNewIcon from '@mui/icons-material/OpenInNew'; | ||
26 | import Button from '@mui/material/Button'; | ||
27 | import { useTheme } from '@mui/material/styles'; | ||
28 | import { observer } from 'mobx-react-lite'; | ||
29 | import React from 'react'; | ||
30 | import { Trans, useTranslation } from 'react-i18next'; | ||
31 | |||
32 | import type Service from '../../stores/Service.js'; | ||
33 | |||
34 | import NotificationBanner from './NotificationBanner.js'; | ||
35 | |||
36 | function NewWindowBanner({ | ||
37 | service, | ||
38 | }: { | ||
39 | service: Service; | ||
40 | }): JSX.Element | null { | ||
41 | const { t } = useTranslation(undefined, { | ||
42 | keyPrefix: 'banner.newWindow', | ||
43 | }); | ||
44 | const { direction } = useTheme(); | ||
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={<OpenInNewIcon fontSize="inherit" />} | ||
63 | onClose={() => service.dismissAllPopups()} | ||
64 | buttons={ | ||
65 | <> | ||
66 | <Button | ||
67 | onClick={() => service.followPopup(url)} | ||
68 | color="inherit" | ||
69 | size="small" | ||
70 | startIcon={ | ||
71 | direction === 'ltr' ? ( | ||
72 | <ArrowForwardIcon fontSize="inherit" /> | ||
73 | ) : ( | ||
74 | <ArrowBackIcon fontSize="inherit" /> | ||
75 | ) | ||
76 | } | ||
77 | > | ||
78 | {t('followLink')} | ||
79 | </Button> | ||
80 | <Button | ||
81 | onClick={() => service.openPopupInExternalBrowser(url)} | ||
82 | color="inherit" | ||
83 | size="small" | ||
84 | startIcon={<OpenInBrowserIcon />} | ||
85 | > | ||
86 | {t('openInExternalBrowser')} | ||
87 | </Button> | ||
88 | {count > 1 && ( | ||
89 | <> | ||
90 | <Button | ||
91 | onClick={() => service.openAllPopupsInExternalBrowser()} | ||
92 | color="inherit" | ||
93 | size="small" | ||
94 | startIcon={<OpenInBrowserIcon />} | ||
95 | > | ||
96 | {t('openAllInExternalBrowser')} | ||
97 | </Button> | ||
98 | <Button | ||
99 | onClick={() => service.dismissPopup(url)} | ||
100 | color="inherit" | ||
101 | size="small" | ||
102 | startIcon={<DoNotDisturbOnOutlinedIcon fontSize="inherit" />} | ||
103 | > | ||
104 | {t('dismiss')} | ||
105 | </Button> | ||
106 | </> | ||
107 | )} | ||
108 | </> | ||
109 | } | ||
110 | > | ||
111 | {count === 1 ? ( | ||
112 | <Trans | ||
113 | i18nKey="messageSingleLink" | ||
114 | t={t} | ||
115 | components={[<strong>url</strong>]} | ||
116 | values={{ name, url }} | ||
117 | /> | ||
118 | ) : ( | ||
119 | <Trans | ||
120 | i18nKey="messageMultipleLinks" | ||
121 | count={count - 1} | ||
122 | t={t} | ||
123 | components={[<strong>url</strong>, <strong>count</strong>]} | ||
124 | values={{ name, url, count: count - 1 }} | ||
125 | /> | ||
126 | )} | ||
127 | </NotificationBanner> | ||
128 | ); | ||
129 | } | ||
130 | |||
131 | export default observer(NewWindowBanner); | ||