File size: 3,248 Bytes
18da36c 79f4fcc aa396c5 2eeb8b1 8e222fd ae21b62 1ea3843 6a6f6eb 8e222fd e55650e 18da36c 8e222fd cb33b9e 8e222fd 2eeb8b1 598945f 11e3284 18da36c 058cd84 452020d 414b2e9 7043f18 cb33b9e 1ea3843 11e3284 414b2e9 e55650e cb33b9e ae21b62 e55650e 985fa34 8e222fd 598945f 1ea3843 452020d ae21b62 84f80c5 cb33b9e 84f80c5 cb33b9e 84f80c5 18da36c cb33b9e 84f80c5 ae21b62 2eeb8b1 1ea3843 2eeb8b1 058cd84 ae21b62 452020d 11e3284 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
import MessageItem from '@/components/message-item';
import DocumentPreviewer from '@/components/pdf-previewer';
import { MessageType } from '@/constants/chat';
import { Drawer, Flex, Spin } from 'antd';
import {
useClickDrawer,
useCreateConversationBeforeUploadDocument,
useFetchConversationOnMount,
useGetFileIcon,
useGetSendButtonDisabled,
useSendButtonDisabled,
useSendMessage,
} from '../hooks';
import { buildMessageItemReference } from '../utils';
import MessageInput from '@/components/message-input';
import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
import { memo } from 'react';
import styles from './index.less';
const ChatContainer = () => {
const {
ref,
currentConversation: conversation,
addNewestConversation,
removeLatestMessage,
addNewestAnswer,
conversationId,
loading,
} = useFetchConversationOnMount();
const {
handleInputChange,
handlePressEnter,
value,
loading: sendLoading,
} = useSendMessage(
conversation,
addNewestConversation,
removeLatestMessage,
addNewestAnswer,
);
const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } =
useClickDrawer();
const disabled = useGetSendButtonDisabled();
const sendDisabled = useSendButtonDisabled(value);
useGetFileIcon();
const { data: userInfo } = useFetchUserInfo();
const { createConversationBeforeUploadDocument } =
useCreateConversationBeforeUploadDocument();
return (
<>
<Flex flex={1} className={styles.chatContainer} vertical>
<Flex flex={1} vertical className={styles.messageContainer}>
<div>
<Spin spinning={loading}>
{conversation?.message?.map((message, i) => {
return (
<MessageItem
loading={
message.role === MessageType.Assistant &&
sendLoading &&
conversation?.message.length - 1 === i
}
key={message.id}
item={message}
nickname={userInfo.nickname}
avatar={userInfo.avatar}
reference={buildMessageItemReference(conversation, message)}
clickDocumentButton={clickDocumentButton}
></MessageItem>
);
})}
</Spin>
</div>
<div ref={ref} />
</Flex>
<MessageInput
disabled={disabled}
sendDisabled={sendDisabled}
sendLoading={sendLoading}
value={value}
onInputChange={handleInputChange}
onPressEnter={handlePressEnter}
conversationId={conversationId}
createConversationBeforeUploadDocument={
createConversationBeforeUploadDocument
}
></MessageInput>
</Flex>
<Drawer
title="Document Previewer"
onClose={hideModal}
open={visible}
width={'50vw'}
>
<DocumentPreviewer
documentId={documentId}
chunk={selectedChunk}
visible={visible}
></DocumentPreviewer>
</Drawer>
</>
);
};
export default memo(ChatContainer);
|