|
1 | 1 | import HeaderTools from "@/coral/components/Header/HeaderTools"; |
2 | | -import { Send } from "@/coral/imports/bundleicons"; |
| 2 | +import { Copy, Send } from "@/coral/imports/bundleicons"; |
3 | 3 | import ChatInput from "@/coral/modules/ChatInput"; |
4 | 4 | import remarkGfm from "remark-gfm"; |
5 | 5 | import rehypePrism from "rehype-prism"; |
6 | 6 | import { PlanChatProps } from "@/models"; |
7 | | -import { Body1, Button, Tag, ToolbarDivider } from "@fluentui/react-components"; |
8 | | -import { ChatDismiss20Regular, HeartRegular } from "@fluentui/react-icons"; |
| 7 | +import { |
| 8 | + Body1, |
| 9 | + Button, |
| 10 | + Tag, |
| 11 | + ToolbarDivider |
| 12 | +} from "@fluentui/react-components"; |
| 13 | +import { |
| 14 | + HeartRegular, |
| 15 | +} from "@fluentui/react-icons"; |
9 | 16 | import { useRef, useState } from "react"; |
10 | 17 | import ReactMarkdown from "react-markdown"; |
11 | | -import "../../styles/PlanChat.css"; // Assuming you have a CSS file for additional styles |
12 | | -import "../../styles/Chat.css"; // Assuming you have a CSS file for additional styles |
13 | | -import "../../styles/prism-material-oceanic.css" |
14 | | -import InlineToaster from "../toast/InlineToaster"; |
| 18 | +import "../../styles/PlanChat.css"; |
| 19 | +import "../../styles/Chat.css"; |
| 20 | +import "../../styles/prism-material-oceanic.css"; |
| 21 | + |
15 | 22 | const PlanChat: React.FC<PlanChatProps> = ({ |
16 | | - planData, |
17 | | - loading, |
18 | | - OnChatSubmit |
| 23 | + planData, |
| 24 | + OnChatSubmit |
19 | 25 | }) => { |
20 | | - // const [messages, setMessages] = useState<{ role: string; content: string }[]>([]); |
21 | | - const [input, setInput] = useState(""); |
22 | | - const [isTyping, setIsTyping] = useState(false); |
23 | | - const [showScrollButton, setShowScrollButton] = useState(false); |
24 | | - const [inputHeight, setInputHeight] = useState(0); |
25 | | - const [currentConversationId, setCurrentConversationId] = useState<string | undefined>(undefined); |
| 26 | + const messages = planData?.messages || []; |
| 27 | + const [input, setInput] = useState(""); |
| 28 | + const [isTyping, setIsTyping] = useState(false); |
| 29 | + const [showScrollButton, setShowScrollButton] = useState(false); |
| 30 | + const [inputHeight, setInputHeight] = useState(0); |
| 31 | + const [currentConversationId, setCurrentConversationId] = useState<string | undefined>(undefined); |
| 32 | + |
| 33 | + const messagesContainerRef = useRef<HTMLDivElement>(null); |
| 34 | + const inputContainerRef = useRef<HTMLDivElement>(null); |
| 35 | + |
| 36 | + const sendMessage = async () => {}; |
26 | 37 |
|
27 | | - const messagesContainerRef = useRef<HTMLDivElement>(null); |
28 | | - const inputContainerRef = useRef<HTMLDivElement>(null); |
29 | | - const messages = planData?.messages || []; |
30 | | - const scrollToBottom = () => { |
31 | | - }; |
32 | | - const clearChat = async () => { |
33 | | - setInput(""); |
34 | | - setCurrentConversationId(undefined); |
35 | | - }; |
36 | | - return ( |
37 | | - <div className="chat-container"> |
38 | | - {planData && ( |
39 | | - <> |
40 | | - <div className="messages" ref={messagesContainerRef}> |
41 | | - <div className="message-wrapper"> |
| 38 | + const scrollToBottom = () => {}; |
42 | 39 |
|
43 | | - {messages.map((msg, index) => (<div key={index} className={`message ${msg.source !== "human" ? "assistant" : "user"}`}> |
44 | | - <Body1> |
45 | | - <div className="plan-chat-message-content"> |
46 | | - <ReactMarkdown remarkPlugins={[remarkGfm]} rehypePlugins={[rehypePrism]}> |
47 | | - {msg.content} |
48 | | - </ReactMarkdown> |
49 | | - {/* {msg.role === "assistant" && ( |
50 | | - <div className="assistant-footer"> |
51 | | - <div className="assistant-actions"> |
52 | | - <Button |
53 | | - onClick={() => handleCopy(msg.content)} |
54 | | - title="Copy Response" |
55 | | - appearance="subtle" |
56 | | - style={{ height: 28, width: 28 }} |
57 | | - icon={<Copy />} |
58 | | - /> |
59 | | - <Button |
60 | | - onClick={() => console.log("Heart clicked for response:", msg.content)} |
61 | | - title="Like" |
62 | | - appearance="subtle" |
63 | | - style={{ height: 28, width: 28 }} |
64 | | - icon={<HeartRegular />} |
65 | | - /> |
66 | | - </div> |
67 | | - </div> |
68 | | - )} */} |
69 | | - </div> |
70 | | - </Body1> |
71 | | - </div> |
72 | | - ))}</div> |
| 40 | + return ( |
| 41 | + <div className="chat-container"> |
| 42 | + <div className="messages" ref={messagesContainerRef}> |
| 43 | + <div className="message-wrapper"> |
| 44 | + {messages.map((msg, index) => { |
| 45 | + const isHuman = msg.role === "user" || msg.role === "human"; |
| 46 | + |
| 47 | + return ( |
| 48 | + <div key={index} className={`message ${msg.role}`}> |
| 49 | + {!isHuman && ( |
| 50 | + <div className="plan-chat-header"> |
| 51 | + <div className="plan-chat-speaker"> |
| 52 | + <span className="speaker-name">HR Agent</span> |
| 53 | + <Tag size="extra-small" shape="rounded" appearance="filled" className="bot-tag">BOT</Tag> |
73 | 54 | </div> |
74 | | - {showScrollButton && ( |
75 | | - <Tag |
76 | | - onClick={scrollToBottom} |
77 | | - className="scroll-to-bottom plan-chat-scroll-button" |
78 | | - shape="circular" |
79 | | - style={{ bottom: inputHeight }} |
80 | | - > |
81 | | - Back to bottom |
82 | | - </Tag> |
83 | | - )} |
| 55 | + </div> |
| 56 | + )} |
84 | 57 |
|
85 | | - <InlineToaster /> |
86 | | - <div ref={inputContainerRef} className="plan-chat-input-container"> |
87 | | - <div className="plan-chat-input-wrapper"> |
88 | | - <ChatInput |
89 | | - value={input} |
90 | | - onChange={setInput} |
91 | | - onEnter={() => OnChatSubmit(input)} |
92 | | - disabledChat={!planData.hasHumanClarificationRequest} |
93 | | - > |
94 | | - <Button |
95 | | - appearance="transparent" |
96 | | - onClick={() => OnChatSubmit(input)} |
97 | | - icon={<Send />} |
98 | | - disabled={!planData?.hasHumanClarificationRequest && (!input.trim())} |
99 | | - /> |
| 58 | + <Body1> |
| 59 | + <div className="plan-chat-message-content"> |
| 60 | + <ReactMarkdown remarkPlugins={[remarkGfm]} rehypePlugins={[rehypePrism]}> |
| 61 | + {msg.content || ""} |
| 62 | + </ReactMarkdown> |
100 | 63 |
|
101 | | - </ChatInput> |
| 64 | + {!isHuman && ( |
| 65 | + <div className="assistant-footer"> |
| 66 | + <div className="assistant-actions"> |
| 67 | + <Button |
| 68 | + onClick={() => msg.content && navigator.clipboard.writeText(msg.content)} |
| 69 | + title="Copy Response" |
| 70 | + appearance="subtle" |
| 71 | + style={{ height: 28, width: 28 }} |
| 72 | + icon={<Copy />} |
| 73 | + /> |
| 74 | + <Tag size="extra-small">Sample data for demonstration purposes only.</Tag> |
102 | 75 | </div> |
| 76 | + </div> |
| 77 | + )} |
| 78 | + </div> |
| 79 | + </Body1> |
| 80 | + </div> |
| 81 | + ); |
| 82 | + })} |
| 83 | + </div> |
103 | 84 |
|
104 | | - </div> |
105 | | - </>)} |
| 85 | + {isTyping && ( |
| 86 | + <div className="typing-indicator"> |
| 87 | + <span>Thinking...</span> |
| 88 | + </div> |
| 89 | + )} |
| 90 | + </div> |
| 91 | + |
| 92 | + {showScrollButton && ( |
| 93 | + <Tag |
| 94 | + onClick={scrollToBottom} |
| 95 | + className="scroll-to-bottom plan-chat-scroll-button" |
| 96 | + shape="circular" |
| 97 | + style={{ bottom: inputHeight }} |
| 98 | + > |
| 99 | + Back to bottom |
| 100 | + </Tag> |
| 101 | + )} |
| 102 | + |
| 103 | + <div ref={inputContainerRef} className="plan-chat-input-container"> |
| 104 | + <div className="plan-chat-input-wrapper"> |
| 105 | + <ChatInput |
| 106 | + value={input} |
| 107 | + onChange={setInput} |
| 108 | + onEnter={sendMessage} |
| 109 | + > |
| 110 | + <Button |
| 111 | + appearance="transparent" |
| 112 | + onClick={sendMessage} |
| 113 | + icon={<Send />} |
| 114 | + disabled={!planData?.hasHumanClarificationRequest || isTyping || !input.trim()} |
| 115 | + /> |
| 116 | + </ChatInput> |
106 | 117 | </div> |
107 | | - ); |
| 118 | + </div> |
| 119 | + </div> |
| 120 | + ); |
108 | 121 | }; |
109 | 122 |
|
110 | 123 | export default PlanChat; |
0 commit comments