Skip to content

Commit

Permalink
Hot-Fix: Chat Notifications (#1199)
Browse files Browse the repository at this point in the history
* chore(1133): Handled focused chat

* chore(1133): Bumped header version
  • Loading branch information
1AhmedYasser authored Mar 5, 2025
1 parent 5c70e82 commit 9e38b4e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion GUI/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"prettier": "prettier --write \"{,!(node_modules)/**/}*.{ts,tsx,js,json,css,less,scss}\""
},
"dependencies": {
"@buerokratt-ria/header": "^0.1.21",
"@buerokratt-ria/header": "^0.1.22",
"@buerokratt-ria/menu": "^0.2.6",
"@buerokratt-ria/styles": "^0.0.1",
"@buerokratt-ria/common-gui-components": "^0.0.4",
Expand Down
30 changes: 29 additions & 1 deletion GUI/src/components/Chat/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { ChangeEvent, FC, useEffect, useRef, useState } from 'react';
import {
ChangeEvent,
FC,
useEffect,
useLayoutEffect,
useRef,
useState,
} from 'react';
import { useTranslation } from 'react-i18next';
import { format } from 'date-fns';
import { et } from 'date-fns/locale';
Expand Down Expand Up @@ -141,6 +148,27 @@ const Chat: FC<ChatProps> = ({
: null
);

const onVisibilityChange = () => {
if (document.visibilityState === 'visible') {
localStorage.setItem('focused_chat', chat.id);
} else if (document.visibilityState === 'hidden') {
localStorage.removeItem('focused_chat');
}
};

useEffect(() => {
localStorage.setItem('focused_chat', chat.id);
return () => {
localStorage.removeItem('focused_chat');
};
}, []);

useLayoutEffect(() => {
document.addEventListener('visibilitychange', onVisibilityChange);
return () =>
document.removeEventListener('visibilitychange', onVisibilityChange);
}, []);

useEffect(() => {
getMessages();
}, []);
Expand Down

0 comments on commit 9e38b4e

Please sign in to comment.