Skip to content

Commit dc6f789

Browse files
author
k.golikov
committed
Add JS Notifications Test Page
1 parent c851782 commit dc6f789

File tree

11 files changed

+196
-4
lines changed

11 files changed

+196
-4
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
BROWSER=none
2+
HTTPS=true
3+
SSL_CRT_FILE=ssl/cert.pem
4+
SSL_KEY_FILE=ssl/key.pem

src/constants/router/menuItems.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ const menuItems: MenuItem[] = [
5858
{
5959
route: routes.userInfo
6060
},
61+
{
62+
route: routes.notificationsTest
63+
},
6164
{
6265
route: routes.templateTextGenerator,
6366
isGray: true

src/constants/router/routes.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import QrGeneratorPage from '../../pages/qrGeneratorPage/QrGeneratorPage';
2020
import SettingsPage from '../../pages/settingsPage/SettingsPage';
2121
import AboutPage from '../../pages/aboutPage/AboutPage';
2222
import CodeFormatterPage from '../../pages/codeFormatterPage/CodeFormatterPage';
23-
import DiffEditorPage from '../../pages/DiffEditorPage';
23+
import DiffEditorPage from '../../pages/diffEditorPage/DiffEditorPage';
2424
import JsonToTypeScriptPage from '../../pages/jsonToTypeScriptPage/JsonToTypeScriptPage';
25+
import NotificationsTestPage from '../../pages/notificationsTestPage/NotificationsTestPage';
2526

2627
export interface AppRoute extends Omit<RouteProps, 'element'> {
2728
path: string;
@@ -47,6 +48,7 @@ type AppRoutesMap = Readonly<{
4748
diffEditor: AppRoute;
4849
codeFormatter: AppRoute;
4950
jsonToTypescript: AppRoute;
51+
notificationsTest: AppRoute;
5052
settings: AppRoute;
5153
about: AppRoute;
5254
}>;
@@ -137,6 +139,11 @@ export const routes: AppRoutesMap = {
137139
component: JsonToTypeScriptPage,
138140
title: 'JSON to TypeScript'
139141
},
142+
notificationsTest: {
143+
path: '/tools/notifications-test',
144+
component: NotificationsTestPage,
145+
title: 'Notifications Test'
146+
},
140147
settings: {
141148
path: '/settings',
142149
component: SettingsPage,

src/pages/DiffEditorPage.tsx renamed to src/pages/diffEditorPage/DiffEditorPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
2-
import PageContainer from '../components/pageContainer/PageContainer';
2+
import PageContainer from '../../components/pageContainer/PageContainer';
33
import { editor } from 'monaco-editor';
4-
import AppDiffEditor from '../components/appDiffEditor/AppDiffEditor';
4+
import AppDiffEditor from '../../components/appDiffEditor/AppDiffEditor';
55

66
const options: editor.IDiffEditorConstructionOptions = {
77
originalEditable: true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.container {
2+
width: 100%;
3+
display: flex;
4+
flex-direction: column;
5+
align-items: flex-start;
6+
gap: 8px;
7+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import React, { FunctionComponent, useCallback, useState } from 'react';
2+
import PageContainer from '../../components/pageContainer/PageContainer';
3+
import { Button, Col, notification, Tooltip } from 'antd';
4+
import Text from 'antd/lib/typography/Text';
5+
import styles from './NotificationsTestPage.module.scss';
6+
import { ReloadOutlined } from '@ant-design/icons';
7+
import AppEditor from '../../components/appEditor/AppEditor';
8+
import { editor } from 'monaco-editor';
9+
import scopedEval from '../../utils/scopedEval';
10+
import { BaseType } from 'antd/lib/typography/Base';
11+
12+
const editorOptions: editor.IStandaloneEditorConstructionOptions = {
13+
minimap: { enabled: false },
14+
fontFamily: 'JetBrains Mono'
15+
};
16+
17+
const permissionColors: Readonly<Record<NotificationPermission, BaseType | undefined>> = {
18+
default: undefined,
19+
denied: 'danger',
20+
granted: 'success'
21+
};
22+
23+
const NotificationsTestPage: FunctionComponent = () => {
24+
const [permission, setPermission] = useState<NotificationPermission>(Notification.permission);
25+
const [notificationCreationJs, setNotificationCreationJs] = useState<string>("new Notification('Hello world')");
26+
27+
const permissionColor = permissionColors[permission];
28+
29+
const updateNotificationPermission = useCallback(() => {
30+
setPermission(Notification.permission);
31+
}, []);
32+
33+
const handleRequestPermission = useCallback(async () => {
34+
const givenPermission = await Notification.requestPermission();
35+
notification.info({
36+
message: `Given permission: ${givenPermission}`
37+
});
38+
setPermission(givenPermission);
39+
}, []);
40+
41+
const createNotification = useCallback(async () => {
42+
const createdNotification = scopedEval(notificationCreationJs);
43+
if (!(createdNotification instanceof Notification)) {
44+
notification.error({
45+
message: `Created object is not an instance of Notification, got ${
46+
createdNotification?.constructor?.name ?? typeof notification
47+
}`
48+
});
49+
return;
50+
}
51+
52+
console.log(createdNotification);
53+
}, [notificationCreationJs]);
54+
55+
return (
56+
<PageContainer title="JS Notifications Test">
57+
<Col xs={23} md={20} lg={18} className={styles.container}>
58+
<Text>
59+
<Tooltip title="Notification.permission" placement="bottom">
60+
<Text strong>Permission:</Text>
61+
<Text className="ms-1" type={permissionColor}>
62+
{permission}
63+
</Text>
64+
</Tooltip>
65+
<Button
66+
icon={<ReloadOutlined />}
67+
size="small"
68+
type="text"
69+
className="ms-1"
70+
onClick={updateNotificationPermission}
71+
/>
72+
</Text>
73+
<Tooltip title="Notification.requestPermission" placement="bottom">
74+
<Button onClick={handleRequestPermission}>Request permission</Button>
75+
</Tooltip>
76+
<AppEditor
77+
language="javascript"
78+
width="100%"
79+
height={160}
80+
value={notificationCreationJs}
81+
onChange={setNotificationCreationJs}
82+
options={editorOptions}
83+
/>
84+
<Button type="primary" onClick={createNotification}>
85+
Send notification
86+
</Button>
87+
</Col>
88+
</PageContainer>
89+
);
90+
};
91+
92+
export default NotificationsTestPage;

src/styles/main.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ $mediaXXL: 1600px;
4949
}
5050
}
5151

52+
//---/--/---/--/---/--/---/--/---/--/---/--/---/--/---/--/---//
53+
5254
$borderColorLight: #d9d9d9;
5355
$borderColorDark: #434343;
5456

src/utils/scopedEval.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const scopedEval = (expression: string, context: object) => {
1+
const scopedEval = (expression: string, context: object = {}) => {
22
const evaluator = Function.apply(null, [
33
...Object.keys(context),
44
'expression',

ssl/cert.pem

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDazCCAlOgAwIBAgIURIoftaQwmVNAX5TPdyVavQc5pI8wDQYJKoZIhvcNAQEL
3+
BQAwRTELMAkGA1UEBhMCUlUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
4+
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMjA1MDUxMzMwMzRaFw0yMzA1
5+
MDUxMzMwMzRaMEUxCzAJBgNVBAYTAlJVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw
6+
HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggEiMA0GCSqGSIb3DQEB
7+
AQUAA4IBDwAwggEKAoIBAQC9rb5QXrL0qswOGwXKSnLvn2zTiuO7JosIqLgI6EQn
8+
jS3odukfh6c7KG8T6kjydTLbh2GccxcnlQ31y3b70/507jF/9xxP+0/EbQTb7+m0
9+
YqndYQiTM1qfkL6HTdZY4htbC6vw7mZRMKPIBTTYg7sIbue2rMETxChJR0Z8oxuY
10+
gaDGCH7M2cU2RZFk6qdW+LX6WHewpFoukyAR9OLdS8gpl5WB5M4q6p3a5PGunysG
11+
tkLax1crh8DSMVnmHO/YZkoHUcFJ3ulMUAyqd6sbB0iXTE6qOUYMCpxIrFYMWk/l
12+
iT8swZeYG8QCFDa+VBlK2+niGCG3ieL8wVb7unGTfeIXAgMBAAGjUzBRMB0GA1Ud
13+
DgQWBBQXTPGdGSfH9lb9vCfhaSKIPH3BnTAfBgNVHSMEGDAWgBQXTPGdGSfH9lb9
14+
vCfhaSKIPH3BnTAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBE
15+
IX3PUkIRArKmJXmRBy2gTp4IBDaS59xFAgs6b+xEsUGAhEtPpOhOXBOYk/9rodIm
16+
twKCjVoF0FAFuDLS0mGcmWyvTMu+q0sJzuexygK9R6hW+0onbTydXk0EGOXl3tvi
17+
icIwpxevXfG5DwneoiiBlHxq6FHu4YWlIk8aciNa04F5dJQDnYCI9yg5VkHPv3hN
18+
mE7c1i0QXJCU7yVIKpWIW57J8rG+c3JrcTi0wHyKmaS0nAPvynfAaW1/SiAcIFvd
19+
Kpehj16usW9N+LzwHdE5rzxjH2odQfn3TOzUUaLsvPt1WyJgUBgC6/RTqZRKo1bI
20+
vI4jpQWHvHPIfGQ+UPV0
21+
-----END CERTIFICATE-----

ssl/key.pem

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIIEpQIBAAKCAQEAva2+UF6y9KrMDhsFykpy759s04rjuyaLCKi4COhEJ40t6Hbp
3+
H4enOyhvE+pI8nUy24dhnHMXJ5UN9ct2+9P+dO4xf/ccT/tPxG0E2+/ptGKp3WEI
4+
kzNan5C+h03WWOIbWwur8O5mUTCjyAU02IO7CG7ntqzBE8QoSUdGfKMbmIGgxgh+
5+
zNnFNkWRZOqnVvi1+lh3sKRaLpMgEfTi3UvIKZeVgeTOKuqd2uTxrp8rBrZC2sdX
6+
K4fA0jFZ5hzv2GZKB1HBSd7pTFAMqnerGwdIl0xOqjlGDAqcSKxWDFpP5Yk/LMGX
7+
mBvEAhQ2vlQZStvp4hght4ni/MFW+7pxk33iFwIDAQABAoIBACGa1Zvxmy0D0ZEy
8+
Mm1rkT9o9GPqOHyg0IMhOTHCzMhhF+AWqSi/5N3zRPK3UGM8Zl1EeAO61EBcBRQm
9+
DxeAsJVQ2g483pRBBxna4sC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