Check for chat changed before displaying welcome panel

This commit is contained in:
Cohee
2025-05-19 00:39:19 +03:00
parent 99d473654f
commit d06789b8dc

View File

@ -54,7 +54,14 @@ export async function openWelcomeScreen() {
return; return;
} }
await sendWelcomePanel(); const recentChats = await getRecentChats();
const chatAfterFetch = getCurrentChatId();
if (chatAfterFetch !== currentChatId) {
console.debug('Chat changed while fetching recent chats.');
return;
}
await sendWelcomePanel(recentChats);
sendAssistantMessage(); sendAssistantMessage();
sendWelcomePrompt(); sendWelcomePrompt();
} }
@ -86,7 +93,11 @@ function sendWelcomePrompt() {
addOneMessage(message, { scroll: false }); addOneMessage(message, { scroll: false });
} }
async function sendWelcomePanel() { /**
* Sends the welcome panel to the chat.
* @param {RecentChat[]} chats List of recent chats
*/
async function sendWelcomePanel(chats) {
try { try {
const chatElement = document.getElementById('chat'); const chatElement = document.getElementById('chat');
const sendTextArea = document.getElementById('send_textarea'); const sendTextArea = document.getElementById('send_textarea');
@ -94,7 +105,6 @@ async function sendWelcomePanel() {
console.error('Chat element not found'); console.error('Chat element not found');
return; return;
} }
const chats = await getRecentChats();
const templateData = { const templateData = {
chats, chats,
empty: !chats.length, empty: !chats.length,