From c5037bdc0185f8fccd0dafea954fc7e990e9c1d4 Mon Sep 17 00:00:00 2001 From: Govind Kamtamneni Date: Mon, 27 May 2024 08:10:56 -0700 Subject: [PATCH] fix bug to randomly select chat id on initial page load --- ui/typescript/src/components/chat/chat-session-list.tsx | 9 +++++---- ui/typescript/src/layouts/sidebar/chat-blade.tsx | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ui/typescript/src/components/chat/chat-session-list.tsx b/ui/typescript/src/components/chat/chat-session-list.tsx index b3657443..072fac14 100644 --- a/ui/typescript/src/components/chat/chat-session-list.tsx +++ b/ui/typescript/src/components/chat/chat-session-list.tsx @@ -28,12 +28,13 @@ export function ChatSessionList({ className, setSelectedSession: updateSelectedS // Set the first session as selected if (data.length > 0) { - const mostRecentChatSession = data[0]; - setSelectedSession(mostRecentChatSession); - await fetchChatMessages(mostRecentChatSession.id); + const randomIndex = Math.floor(Math.random() * data.length); + const randomChatSession = data[randomIndex]; + setSelectedSession(randomChatSession); + await fetchChatMessages(randomChatSession.id); setUserInfoAtom((prevUserInfo: UserInfoProps) => ({ ...prevUserInfo, - chatId: mostRecentChatSession.id, + chatId: randomChatSession.id, })); } } diff --git a/ui/typescript/src/layouts/sidebar/chat-blade.tsx b/ui/typescript/src/layouts/sidebar/chat-blade.tsx index 4ab710e5..93dbf96f 100644 --- a/ui/typescript/src/layouts/sidebar/chat-blade.tsx +++ b/ui/typescript/src/layouts/sidebar/chat-blade.tsx @@ -199,7 +199,7 @@ export default function Sidebar({ className, setSelectedSession, setUserInfoAtom