Skip to content

Commit 9e38b4e

Browse files
authored
Hot-Fix: Chat Notifications (#1199)
* chore(1133): Handled focused chat * chore(1133): Bumped header version
1 parent 5c70e82 commit 9e38b4e

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

GUI/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"prettier": "prettier --write \"{,!(node_modules)/**/}*.{ts,tsx,js,json,css,less,scss}\""
1212
},
1313
"dependencies": {
14-
"@buerokratt-ria/header": "^0.1.21",
14+
"@buerokratt-ria/header": "^0.1.22",
1515
"@buerokratt-ria/menu": "^0.2.6",
1616
"@buerokratt-ria/styles": "^0.0.1",
1717
"@buerokratt-ria/common-gui-components": "^0.0.4",

GUI/src/components/Chat/index.tsx

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { ChangeEvent, FC, useEffect, useRef, useState } from 'react';
1+
import {
2+
ChangeEvent,
3+
FC,
4+
useEffect,
5+
useLayoutEffect,
6+
useRef,
7+
useState,
8+
} from 'react';
29
import { useTranslation } from 'react-i18next';
310
import { format } from 'date-fns';
411
import { et } from 'date-fns/locale';
@@ -141,6 +148,27 @@ const Chat: FC<ChatProps> = ({
141148
: null
142149
);
143150

151+
const onVisibilityChange = () => {
152+
if (document.visibilityState === 'visible') {
153+
localStorage.setItem('focused_chat', chat.id);
154+
} else if (document.visibilityState === 'hidden') {
155+
localStorage.removeItem('focused_chat');
156+
}
157+
};
158+
159+
useEffect(() => {
160+
localStorage.setItem('focused_chat', chat.id);
161+
return () => {
162+
localStorage.removeItem('focused_chat');
163+
};
164+
}, []);
165+
166+
useLayoutEffect(() => {
167+
document.addEventListener('visibilitychange', onVisibilityChange);
168+
return () =>
169+
document.removeEventListener('visibilitychange', onVisibilityChange);
170+
}, []);
171+
144172
useEffect(() => {
145173
getMessages();
146174
}, []);

0 commit comments

Comments
 (0)