Skip to content

Commit

Permalink
feat: add select chat feature
Browse files Browse the repository at this point in the history
  • Loading branch information
VishalPawar1010 committed Jul 25, 2024
1 parent 914e21d commit c130f4a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"jest-environment-jsdom": "^29.7.0",
"rehype-sanitize": "6.0.0",
"react-markdown": "9.0.1",
"pieces-copilot-sdk": "1.1.9"
"pieces-copilot-sdk": "^1.1.9"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.2.0",
Expand Down
26 changes: 22 additions & 4 deletions src/app/components/Copilot/Copilot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "./Copilot.css";

import Markdown from '../ResponseFormat/Markdown';
import { PiecesClient } from 'pieces-copilot-sdk';

// Replace 'your_base_url' with your actual base URL
export const BASE_URL = 'http://localhost:1000';
export const piecesClient = new PiecesClient({ baseUrl: BASE_URL });
Expand Down Expand Up @@ -48,6 +49,8 @@ export function CopilotChat(): React.JSX.Element {
const [chatSelected, setChatSelected] = useState('no chat selected');
const [chatInputData, setData] = useState('');
const [message, setMessage] = useState<string>('');
const [conversations, setConversations] = useState([]);


// handles the data changes on the chat input.
const handleCopilotChatInputChange = (event: { target: { value: React.SetStateAction<string>; }; }) => {
Expand Down Expand Up @@ -80,6 +83,7 @@ export function CopilotChat(): React.JSX.Element {
const getInitialChat = async () => {
try {
const allConversations = await piecesClient.getConversations();
setConversations(allConversations);
// console.log('allConversations', allConversations);
if (allConversations.length > 0) {
const { id, name } = allConversations[0];
Expand All @@ -93,17 +97,31 @@ export function CopilotChat(): React.JSX.Element {
getInitialChat();
}, []);

const handleConversationChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
const selectedId = event.target.value;
const selectedConversation = conversations.find(convo => convo.id === selectedId);
if (selectedConversation) {
GlobalConversationID = selectedId;
setChatSelected(selectedConversation.name);
}
};

return (
<div className="container">
<div className="header">
<div>
<h1>Copilot Chat</h1>
<button className="button" onClick={handleNewConversation}>Create Fresh Conversation</button>
</div>
<div className="footer">
<button>back</button>
<p>{chatSelected}</p>
<button>forward</button>
<div>
Select your chat:
<select onChange={handleConversationChange} value={GlobalConversationID}>
{conversations.map((conversation) => (
<option key={conversation.id} value={conversation.id}>
{conversation.name}
</option>
))}
</select>
</div>
</div>
<div className="chat-box">
Expand Down

0 comments on commit c130f4a

Please sign in to comment.