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