-
Notifications
You must be signed in to change notification settings - Fork 55
Update Copilot.tsx #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,9 @@ export function CopilotChat(): React.JSX.Element { | |
const [chatSelected, setChatSelected] = useState('-- no chat selected --'); | ||
const [chatInputData, setData] = useState(''); | ||
const [message, setMessage] = useState<string>(''); | ||
const [chats, setChats] = useState<string[]>([]); // State variable to store chat names | ||
const [currentChatIndex, setCurrentChatIndex] = useState<number>(-1); // State variable to track the index of the selected chat | ||
|
||
|
||
// handles the data changes on the chat input. | ||
const handleCopilotChatInputChange = (event: { target: { value: React.SetStateAction<string>; }; }) => { | ||
|
@@ -136,27 +139,24 @@ export function CopilotChat(): React.JSX.Element { | |
}; | ||
|
||
// for setting the initial copilot chat that takes place on page load. | ||
const getInitialChat = async () => { | ||
await new Pieces.ConversationsApi().conversationsSnapshot({}).then(output => { | ||
const previousChats = output.iterable.map(conversation => conversation.name); | ||
setChats(previousChats); | ||
const _name = previousChats[0]; | ||
setChatSelected(_name); | ||
GlobalConversationID = output.iterable.at(0).id; | ||
}); | ||
}; | ||
|
||
// Function to handle chat selection | ||
const handleChatSelection = (index: number) => { | ||
setCurrentChatIndex(index); | ||
setChatSelected(chats[index]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like this is working properly, but we need to do a little bit of work to the UI so that all of the other chats are are not showing with buttons as well. let me know what you are able to find 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK,I'll look into that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd recommend just making the top bar that shows all the conversations scrollable. Set a max width and then allow a user to scroll horizontally 👍 |
||
// Here you can fetch and display the messages of the selected chat based on its index | ||
}; | ||
|
||
useEffect(() => { | ||
const getInitialChat = async () => { | ||
let _name: string; | ||
|
||
await new Pieces.ConversationsApi() | ||
.conversationsSnapshot({}) | ||
.then((output) => { | ||
if ( | ||
output.iterable.length > 0 && | ||
output.iterable.at(0).hasOwnProperty("name") | ||
) { | ||
_name = output.iterable.at(0).name; | ||
GlobalConversationID = output.iterable.at(0).id; | ||
} | ||
return _name; | ||
}); | ||
|
||
if (_name) { | ||
setChatSelected(_name); | ||
} | ||
}; | ||
getInitialChat(); | ||
}, []); | ||
|
||
|
@@ -167,10 +167,13 @@ export function CopilotChat(): React.JSX.Element { | |
<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 className="chat-dropdown"> | ||
<select value={chatSelected} onChange={handleChatSelection}> | ||
<option value="">-- Select Chat --</option> | ||
{chats.map((chat, index) => ( | ||
<option key ={index} value={chat}>{chat}</option> | ||
))} | ||
</select> | ||
</div> | ||
</div> | ||
<div className="chat-box"> | ||
|
@@ -186,4 +189,4 @@ export function CopilotChat(): React.JSX.Element { | |
</div> | ||
</div> | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥