coze-middleschool/src/components/RoomConversation/index.tsx

106 lines
4.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { useRef, useEffect, useContext } from "react";
import { RealtimeClientContext } from "../Provider/RealtimeClientProvider";
import ReactMarkdown from "react-markdown";
import gfm from "remark-gfm";
import { RoleType } from "@coze/api";
import { Loader } from 'lucide-react';
export default function RoomConversation() {
const { messageList } = useContext(RealtimeClientContext);
const messagesEndRef = useRef<HTMLDivElement>(null);
// 自动滚动到最新消息
const scrollToBottom = () => {
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
};
useEffect(() => {
scrollToBottom();
}, [messageList]);
return (
<div className="flex-1 flex flex-col overflow-y-auto">
<div className="w-full min-h-[120px] h-[120px]">
<div className="relative h-full">
<img
src="/icons/hello.gif"
alt=""
className="absolute top-0 h-[97px] left-[50%] translate-x-[-50%] object-contain"
/>
<div className="text-black text-[14px] absolute bottom-[25px] left-[50%] translate-x-[-50%] z-[10] pt-[3px]">
<img
src="/icons/conversation-bg.png"
alt="background"
className="w-[252px] h-[59px] object-contain absolute top-[-50%] z-[-1] left-[50%] translate-x-[-50%] max-w-[unset]"
/>
HeyAI
</div>
</div>
</div>
<div className="p-4 space-y-4">
{messageList.map((message: any, index: number) => (
<div
key={index}
className={`flex ${
message.role === RoleType.Assistant
? "justify-start"
: "justify-end"
}`}
>
<div
className={`max-w-3/4 p-3 rounded-lg ${
message.role === RoleType.Assistant
? "bg-white text-black rounded-tl-none"
: "bg-blue-500 text-white rounded-tr-none"
}`}
>
{typeof message.fileParseStatus === "undefined" && typeof message.fileInfo === 'undefined' ? (
<ReactMarkdown remarkPlugins={[gfm]}>
{message.content}
</ReactMarkdown>
) : (
<div className="flex items-center justify-center px-[4px] py-[2px]">
<img
src="/icons/wish-list-icon.png"
alt="icon"
className="w-[48px] h-[48px] object-contain"
/>
<div className="flex flex-col items-start ml-[10px]">
<div className="flex items-center">
<span className="text-[15px] text-[#303030] mr-[8px] leading-[1]">
{message?.fileInfo?.tableName}
</span>
<div className="bg-[#F4F6FA] rounded-[4px] w-[48px] h-[16px] px-[4px] py-[2px] text-[10px]">
{message?.fileInfo?.type}
</div>
</div>
<div className="text-[12px] text-[#303030] mt-[6px] flex items-center">
<span className="mr-[10px]">
{message?.fileInfo?.provinceName}·{message?.fileInfo?.score}
</span>
<span>
{message?.fileInfo?.subjectClaim?.split(",").join("/")}
</span>
{
message.fileParseStatus < 2 && (
<Loader className="w-[12px] h-[12px] animate-spin ml-[6px]" />
)
}
</div>
</div>
</div>
)}
</div>
</div>
))}
<div ref={messagesEndRef} />
</div>
<div className="text-[12px] text-[#999] font-[400] text-center mt-auto mb-[7px]">AI</div>
<div className="mx-[8px] rounded-full bg-[#ffeede] py-[7px] pl-[18px] pr-[3px] flex items-center justify-between">
<span className="text-[#FA8E23] text-[12px]">3~</span>
<button className="rounded-full bg-[#FA8E23] py-[6px] px-[13px] text-[13px] text-white font-[500]"></button>
</div>
</div>
);
}