vzcode 0.21.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,128 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
- import './style.scss';
3
-
4
- // A presence notification is a message that is displayed when a user joins or leaves a session.
5
- // It has the following properties:
6
- // - `user` is the username of the user who joined or left the session.
7
- // - `join` is a boolean value that indicates whether the user joined or left the session.
8
- // - `true` means user has joined the session.
9
- // - `false` means user has left the session.
10
- type PresenceNotification = {
11
- user: string;
12
- join: boolean;
13
- presenceId: string;
14
- };
15
-
16
- export const PresenceNotifications = ({
17
- docPresence,
18
- }: {
19
- docPresence?: any;
20
- }) => {
21
- const [presenceNotifications, setPresenceNotifications] =
22
- useState<Array<PresenceNotification>>([]);
23
-
24
- // // console.log('docPresence:', docPresence);
25
- // const [visible, setVisible] = useState(true);
26
- // const [user, setUser] = useState('');
27
-
28
- // // `true` means user has joined the session.
29
- // // `false` means user has left the session.
30
- // const [join, setJoin] = useState<boolean>(true);
31
-
32
- useEffect(() => {
33
- // console.log('useEffect triggered.');
34
- if (docPresence) {
35
- // See https://share.github.io/sharedb/presence
36
- docPresence.on('receive', (presenceId, update) => {
37
- // TODO figure out how to get username from `presenceId`.
38
- const user = 'someone';
39
-
40
- // `true` means user has joined the session.
41
- // `false` means user has left the session.
42
- const join = update === null;
43
-
44
- // Add an entry to the presence notifications array.
45
- setPresenceNotifications((prev) => [
46
- ...prev,
47
- { user, join, presenceId },
48
- ]);
49
-
50
- // Remove it after 5 seconds.
51
- setTimeout(() => {
52
- setPresenceNotifications((prev) =>
53
- prev.filter(
54
- (notification) =>
55
- notification.presenceId !== presenceId,
56
- ),
57
- );
58
- }, 5000);
59
- });
60
-
61
- // console.log('inside if of useEffect.');
62
- // docPresence.on('receive', (presence) => {
63
- // console.log('presence', presence);
64
-
65
- // // Add an entry to the presence notifications array.
66
- // setPresenceNotifications((prev) => [
67
- // ...prev,
68
- // { user: presence.username, join: presence === null },
69
- // ]);
70
-
71
- // console.log('receive triggered.');
72
- // if (presence === null) {
73
- // setJoin(false);
74
- // }
75
- // const { username } = presence;
76
- // setUser(username);
77
- // });
78
-
79
- // const timer = setTimeout(() => {
80
- // setVisible(false);
81
- // }, 10000);
82
- return () => {
83
- // clearTimeout(timer);
84
- };
85
- } else {
86
- // setVisible(false);
87
- }
88
- }, [docPresence]);
89
-
90
- console.log(
91
- 'presenceNotifications',
92
- presenceNotifications,
93
- );
94
-
95
- return presenceNotifications.length > 0 ? (
96
- <div className="vz-notification">
97
- {presenceNotifications.map((notification) => {
98
- const { user, join } = notification;
99
- return (
100
- <div
101
- key={notification.presenceId}
102
- className="vz-notification-item"
103
- >
104
- {join
105
- ? `${user} has joined the session.`
106
- : `${user} has left the session.`}
107
- </div>
108
- );
109
- })}
110
- </div>
111
- ) : null;
112
- // return null;
113
-
114
- // return (
115
- // <Modal
116
- // className="vz-notification"
117
- // show={visible}
118
- // onHide={() => setVisible(false)}
119
- // animation={false}
120
- // >
121
- // <Modal.Body>
122
- // {join
123
- // ? `${user} has joined the session.`
124
- // : `${user} has left the session.`}
125
- // </Modal.Body>
126
- // </Modal>
127
- // );
128
- };
@@ -1,17 +0,0 @@
1
- .vz-notification {
2
- position: fixed;
3
- display: flex;
4
- flex-direction: column;
5
- gap: 10px;
6
- bottom: 20px;
7
- right: 20px;
8
-
9
- color: rgb(154, 160, 172);
10
- padding: 15px;
11
-
12
- .vz-notification-item {
13
- background-color: rgb(54, 65, 89);
14
- padding: 5px;
15
- border-radius: 5px;
16
- }
17
- }