Skip to content

Commit

Permalink
Merge pull request #166 from Azure-Samples/gk/fix-merge-issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thegovind authored Oct 31, 2023
2 parents 9dfc56c + 38bf3ee commit 8dea662
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions ui/typescript/src/components/chat/chat-session-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export function ChatSessionList({ className, setSelectedSession: updateSelectedS

useEffect(() => {
async function fetchChatSessions() {
const chatSessionUrl = `${process.env.NEXT_PUBLIC_COPILOT_CHAT_BASE_URL}/chats/${userInfo.chatId}/messages`;
console.log(chatSessionUrl);
const chatSessionUrl = `${process.env.NEXT_PUBLIC_COPILOT_CHAT_BASE_URL}/chats`;
const response = await fetch(chatSessionUrl, {
method: 'GET',
headers: {
Expand All @@ -26,13 +25,18 @@ export function ChatSessionList({ className, setSelectedSession: updateSelectedS
});
const data = await response.json();
setChatSessions(data);
console.log("Chat sessions");
console.dir(chatSessions);
console.dir(selectedSession);

// Set the first session as selected
if (data.length > 0) {
const firstChatSession = data[0];
setSelectedSession(firstChatSession);
await fetchChatMessages(firstChatSession.id);
}
}
fetchChatSessions().then(r => console.log(r));
}, []);


async function fetchChatMessages(chatId: string) {
const chatMsgEndpoint = `${process.env.NEXT_PUBLIC_COPILOT_CHAT_BASE_URL}/chats/${chatId}/messages?startIdx=0&count=-1`
const response = await fetch(chatMsgEndpoint, {
Expand All @@ -50,11 +54,11 @@ export function ChatSessionList({ className, setSelectedSession: updateSelectedS
setSelectedSession(currentSession);
console.log("Selected current session");
console.dir(currentSession);
await fetchChatMessages(currentSession.chatId || `${process.env.NEXT_PUBLIC_COPILOT_CHAT_BASE_URL}`);
await fetchChatMessages(currentSession.id);

setUserInfoAtom((prevUserInfo: UserInfoProps) => ({ // Add type to prevUserInfo
...prevUserInfo,
chatId: currentSession.chatId || `${process.env.NEXT_PUBLIC_COPILOT_CHAT_BASE_URL}`,
chatId: currentSession.id,
}));
}

Expand Down

0 comments on commit 8dea662

Please sign in to comment.