mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Fix: Document Previewer is not working #9606 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
112 lines
3.7 KiB
TypeScript
112 lines
3.7 KiB
TypeScript
import { NextMessageInput } from '@/components/message-input/next';
|
|
import MessageItem from '@/components/message-item';
|
|
import PdfDrawer from '@/components/pdf-drawer';
|
|
import { useClickDrawer } from '@/components/pdf-drawer/hooks';
|
|
import { MessageType } from '@/constants/chat';
|
|
import {
|
|
useFetchConversation,
|
|
useFetchDialog,
|
|
useGetChatSearchParams,
|
|
} from '@/hooks/use-chat-request';
|
|
import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
|
|
import { buildMessageUuidWithRole } from '@/utils/chat';
|
|
import {
|
|
useGetSendButtonDisabled,
|
|
useSendButtonDisabled,
|
|
} from '../../hooks/use-button-disabled';
|
|
import { useCreateConversationBeforeUploadDocument } from '../../hooks/use-create-conversation';
|
|
import { useSendMessage } from '../../hooks/use-send-chat-message';
|
|
import { buildMessageItemReference } from '../../utils';
|
|
|
|
interface IProps {
|
|
controller: AbortController;
|
|
}
|
|
|
|
export function SingleChatBox({ controller }: IProps) {
|
|
const {
|
|
value,
|
|
scrollRef,
|
|
messageContainerRef,
|
|
sendLoading,
|
|
derivedMessages,
|
|
isUploading,
|
|
handleInputChange,
|
|
handlePressEnter,
|
|
regenerateMessage,
|
|
removeMessageById,
|
|
stopOutputMessage,
|
|
handleUploadFile,
|
|
} = useSendMessage(controller);
|
|
const { data: userInfo } = useFetchUserInfo();
|
|
const { data: currentDialog } = useFetchDialog();
|
|
const { createConversationBeforeUploadDocument } =
|
|
useCreateConversationBeforeUploadDocument();
|
|
const { conversationId } = useGetChatSearchParams();
|
|
const { data: conversation } = useFetchConversation();
|
|
const disabled = useGetSendButtonDisabled();
|
|
const sendDisabled = useSendButtonDisabled(value);
|
|
const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } =
|
|
useClickDrawer();
|
|
|
|
return (
|
|
<section className="flex flex-col p-5 h-full">
|
|
<div ref={messageContainerRef} className="flex-1 overflow-auto min-h-0">
|
|
<div className="w-full pr-5">
|
|
{derivedMessages?.map((message, i) => {
|
|
return (
|
|
<MessageItem
|
|
loading={
|
|
message.role === MessageType.Assistant &&
|
|
sendLoading &&
|
|
derivedMessages.length - 1 === i
|
|
}
|
|
key={buildMessageUuidWithRole(message)}
|
|
item={message}
|
|
nickname={userInfo.nickname}
|
|
avatar={userInfo.avatar}
|
|
avatarDialog={currentDialog.icon}
|
|
reference={buildMessageItemReference(
|
|
{
|
|
message: derivedMessages,
|
|
reference: conversation.reference,
|
|
},
|
|
message,
|
|
)}
|
|
clickDocumentButton={clickDocumentButton}
|
|
index={i}
|
|
removeMessageById={removeMessageById}
|
|
regenerateMessage={regenerateMessage}
|
|
sendLoading={sendLoading}
|
|
></MessageItem>
|
|
);
|
|
})}
|
|
</div>
|
|
<div ref={scrollRef} />
|
|
</div>
|
|
<NextMessageInput
|
|
disabled={disabled}
|
|
sendDisabled={sendDisabled}
|
|
sendLoading={sendLoading}
|
|
value={value}
|
|
onInputChange={handleInputChange}
|
|
onPressEnter={handlePressEnter}
|
|
conversationId={conversationId}
|
|
createConversationBeforeUploadDocument={
|
|
createConversationBeforeUploadDocument
|
|
}
|
|
stopOutputMessage={stopOutputMessage}
|
|
onUpload={handleUploadFile}
|
|
isUploading={isUploading}
|
|
/>
|
|
{visible && (
|
|
<PdfDrawer
|
|
visible={visible}
|
|
hideModal={hideModal}
|
|
documentId={documentId}
|
|
chunk={selectedChunk}
|
|
></PdfDrawer>
|
|
)}
|
|
</section>
|
|
);
|
|
}
|