bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/screenreader-alert/adapter.tsx
Tainan Felipe 3bc40df230
Add: useDeduplicatedSubscription hook (#20376)
* Add: useDeduplicatedSubscription hook

* Fix: TS error

* Add: components using useDeduplicatedSubscription

* Change: Move to useDeduplicatedSubscription

* Change: unsubscribe logic to own useEffect

* Change: remove file import over package

* Fix: TS errors

* Fix: private chat not loading

* Change: revert changes on queries

* Fix: eslint error

* Remove: html-webpack-plugin package

* Fix: external video

* Add: comment about the stringToHash function

* Fix: video player showing tools over presentation
2024-06-04 10:40:54 -03:00

47 lines
1.6 KiB
TypeScript

import { useEffect } from 'react';
import { isEqual } from 'radash';
import { defineMessages, useIntl } from 'react-intl';
import { UNREAD_CHATS_SUBSCRIPTION, UnreadChatsSubscriptionResponse } from './queries';
import usePreviousValue from '/imports/ui/hooks/usePreviousValue';
import { addAlert } from './service';
import useDeduplicatedSubscription from '../../core/hooks/useDeduplicatedSubscription';
const intlMessages = defineMessages({
newMsgAria: {
id: 'app.navBar.toggleUserList.newMsgAria',
description: 'label for new message screen reader alert',
},
publicChatName: {
id: 'app.chat.titlePublic',
description: 'label for public chat name',
},
});
const ScreenReaderAlertAdapter = () => {
const { data, error, loading } = useDeduplicatedSubscription<UnreadChatsSubscriptionResponse>(
UNREAD_CHATS_SUBSCRIPTION,
);
const previousData = usePreviousValue(data);
const intl = useIntl();
useEffect(() => {
if (!loading && !error && data && !isEqual(data, previousData)) {
const { chat: chats } = data;
const { chat: previousChats } = previousData ?? {};
chats.forEach((chat) => {
const previousChat = previousChats && previousChats.find((c) => c.chatId === chat.chatId);
if (!previousChat || chat.totalUnread > previousChat.totalUnread) {
const name = chat.participant?.name ?? intl.formatMessage(intlMessages.publicChatName);
addAlert(`${intl.formatMessage(intlMessages.newMsgAria, { 0: name })}`);
}
});
}
}, [data, previousData, error, loading]);
return null;
};
export default ScreenReaderAlertAdapter;