Skip to content

Commit

Permalink
Handing user messages from the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
akhatua2 committed Nov 22, 2024
1 parent c2f4d57 commit 7f7a0c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/experimental/nodes/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const App: React.FC = () => {
</div>
</div>
<div id="chat-container">
<ChatInterface messages={messages} />
<ChatInterface messages={messages} socket={socket}/>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import './ChatInterface.css';
import React, { ReactNode, useState } from 'react';
import { Socket } from 'socket.io-client'; // Import the Socket type


interface ScrollAreaProps {
className?: string;
Expand All @@ -25,9 +27,10 @@ interface ChatInterfaceProps {
text: string;
type: 'message' | 'status';
}>;
socket: Socket;
}

export const ChatInterface: React.FC<ChatInterfaceProps> = ({ messages: initialMessages }) => {
export const ChatInterface: React.FC<ChatInterfaceProps> = ({ messages: initialMessages , socket}) => {
const [messages, setMessages] = useState(initialMessages);
const [input, setInput] = useState('');
const messagesEndRef = React.useRef<HTMLDivElement>(null);
Expand All @@ -53,6 +56,7 @@ export const ChatInterface: React.FC<ChatInterfaceProps> = ({ messages: initialM
text: `User: ${input}`, // Prefix with "User:"
type: 'message'
}]);
socket.emit('chat_message', `User: ${input}`); // Emit the command to the server
setInput('');
}
};
Expand Down

0 comments on commit 7f7a0c2

Please sign in to comment.