From 943d73c687b9dbeb0f45a1d1a75e74471cc14b07 Mon Sep 17 00:00:00 2001 From: Rohan Mishra <315scisyb2020rohanmishra@gmail.com> Date: Thu, 15 Feb 2024 22:45:08 +0530 Subject: [PATCH 1/3] Update Copilot.tsx These enables users to preview and reference previous chat messages easily by fetching the names of previous chats and allowing users to select a chat from the list. Once a chat is selected, the code fetches and displays the messages of the selected chat, allowing users to review and refer to earlier parts of the conversation. --- src/app/components/Copilot/Copilot.tsx | 36 +++++++++++++++++--------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/app/components/Copilot/Copilot.tsx b/src/app/components/Copilot/Copilot.tsx index 0759288..9e2a335 100644 --- a/src/app/components/Copilot/Copilot.tsx +++ b/src/app/components/Copilot/Copilot.tsx @@ -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(''); + const [chats, setChats] = useState([]); // State variable to store chat names + const [currentChatIndex, setCurrentChatIndex] = useState(-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; }; }) => { @@ -136,17 +139,24 @@ export function CopilotChat(): React.JSX.Element { }; // for setting the initial copilot chat that takes place on page load. - useEffect(() => { - const getInitialChat = async () => { - let _name: string; - - await new Pieces.ConversationsApi().conversationsSnapshot({}).then(output => { - _name = output.iterable.at(0).name; - GlobalConversationID = output.iterable.at(0).id; - return output.iterable.at(0).name - }); + 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]); + // Here you can fetch and display the messages of the selected chat based on its index + }; + + useEffect(() => { getInitialChat(); }, []); @@ -159,7 +169,9 @@ export function CopilotChat(): React.JSX.Element {
-

{chatSelected}

+ {chats.map((chat, index) => ( + + ))}
@@ -176,4 +188,4 @@ export function CopilotChat(): React.JSX.Element { ); -} \ No newline at end of file +} From df5dfff3b566bfbda4e11bc44982b1987a909d4f Mon Sep 17 00:00:00 2001 From: Rohan Mishra <315scisyb2020rohanmishra@gmail.com> Date: Sat, 2 Mar 2024 17:30:23 +0530 Subject: [PATCH 2/3] Update Copilot.tsx --- src/app/components/Copilot/Copilot.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/components/Copilot/Copilot.tsx b/src/app/components/Copilot/Copilot.tsx index 9e2a335..50074f6 100644 --- a/src/app/components/Copilot/Copilot.tsx +++ b/src/app/components/Copilot/Copilot.tsx @@ -167,12 +167,13 @@ export function CopilotChat(): React.JSX.Element {

Copilot Chat

-
- +
+
From 9ecf0c00d8404c3227c16ffa6c0e15ee035e31e1 Mon Sep 17 00:00:00 2001 From: Rohan Mishra <315scisyb2020rohanmishra@gmail.com> Date: Sat, 2 Mar 2024 17:45:09 +0530 Subject: [PATCH 3/3] Update Copilot.tsx --- src/app/components/Copilot/Copilot.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/Copilot/Copilot.tsx b/src/app/components/Copilot/Copilot.tsx index 50074f6..c58903e 100644 --- a/src/app/components/Copilot/Copilot.tsx +++ b/src/app/components/Copilot/Copilot.tsx @@ -168,7 +168,7 @@ export function CopilotChat(): React.JSX.Element {
- {chats.map((chat, index) => (