bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/chat/chat-graphql/component.tsx

75 lines
2.4 KiB
TypeScript
Raw Normal View History

import React from 'react';
import ChatHeader from './chat-header/component';
import { layoutSelect, layoutSelectInput } from '../../layout/context';
import { Input, Layout } from '../../layout/layoutTypes';
import Styled from './styles';
import ChatMessageListContainer from './chat-message-list/component';
import ChatMessageFormContainer from './chat-message-form/component';
import ChatTypingIndicatorContainer from './chat-typing-indicator/component';
import { PANELS, ACTIONS } from '/imports/ui/components/layout/enums';
2023-09-14 00:37:40 +08:00
import { CircularProgress } from '@mui/material';
import usePendingChat from '/imports/ui/core/local-states/usePendingChat';
import useChat from '/imports/ui/core/hooks/useChat';
2023-09-11 21:12:37 +08:00
import { Chat as ChatType } from '/imports/ui/Types/chat';
import { layoutDispatch } from '/imports/ui/components/layout/context';
2023-09-11 21:12:37 +08:00
import browserInfo from '/imports/utils/browserInfo';
import { GraphqlDataHookSubscriptionResponse } from '/imports/ui/Types/hook';
2023-09-14 00:37:40 +08:00
interface ChatProps {
}
const Chat: React.FC<ChatProps> = () => {
2023-09-11 21:12:37 +08:00
const { isChrome } = browserInfo;
return (
2023-09-11 21:12:37 +08:00
<Styled.Chat isChrome={isChrome}>
<ChatHeader />
<ChatMessageListContainer />
<ChatMessageFormContainer />
<ChatTypingIndicatorContainer />
</Styled.Chat>
);
};
const ChatLoading: React.FC = () => {
2023-09-11 21:12:37 +08:00
const { isChrome } = browserInfo;
return (
<Styled.Chat isChrome={isChrome}>
<CircularProgress style={{ alignSelf: 'center' }} />
</Styled.Chat>
);
};
const ChatContainer: React.FC = () => {
const idChatOpen = layoutSelect((i: Layout) => i.idChatOpen);
const sidebarContent = layoutSelectInput((i: Input) => i.sidebarContent);
const layoutContextDispatch = layoutDispatch();
const { data: chats } = useChat((chat) => {
return {
chatId: chat.chatId,
participant: chat.participant,
};
}) as GraphqlDataHookSubscriptionResponse<Partial<ChatType>[]>;
const [pendingChat, setPendingChat] = usePendingChat();
if (pendingChat && chats) {
2023-09-14 00:37:40 +08:00
const chat = chats.find((c) => {
return c.participant?.userId === pendingChat;
});
if (chat) {
setPendingChat('');
layoutContextDispatch({
type: ACTIONS.SET_ID_CHAT_OPEN,
value: chat.chatId,
});
}
}
if (sidebarContent.sidebarContentPanel !== PANELS.CHAT) return null;
if (!idChatOpen) return <ChatLoading />;
return <Chat />;
};
2023-09-14 00:37:40 +08:00
export default ChatContainer;