Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions src/app/components/Copilot/Copilot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

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>; }; }) => {
Expand All @@ -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]);
Copy link
Contributor

Choose a reason for hiding this comment

The 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 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK,I'll look into that

Copy link
Contributor

Choose a reason for hiding this comment

The 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();
}, []);

Expand All @@ -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">
Expand All @@ -186,4 +189,4 @@ export function CopilotChat(): React.JSX.Element {
</div>
</div>
);
}
}