Check for chat changed before displaying welcome panel
| @@ -54,7 +54,14 @@ export async function openWelcomeScreen() { | |||
| 54 | return; | 54 | return; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | await sendWelcomePanel(); | 57 | const recentChats = await getRecentChats(); |
| 58 | const chatAfterFetch = getCurrentChatId(); | ||
| 59 | if (chatAfterFetch !== currentChatId) { | ||
| 60 | console.debug('Chat changed while fetching recent chats.'); | ||
| 61 | return; | ||
| 62 | } | ||
| 63 | |||
| 64 | await sendWelcomePanel(recentChats); | ||
| 58 | sendAssistantMessage(); | 65 | sendAssistantMessage(); |
| 59 | sendWelcomePrompt(); | 66 | sendWelcomePrompt(); |
| 60 | } | 67 | } |
| @@ -86,7 +93,11 @@ function sendWelcomePrompt() { | |||
| 86 | addOneMessage(message, { scroll: false }); | 93 | addOneMessage(message, { scroll: false }); |
| 87 | } | 94 | } |
| 88 | 95 | ||
| 89 | async function sendWelcomePanel() { | 96 | /** |
| 97 | * Sends the welcome panel to the chat. | ||
| 98 | * @param {RecentChat[]} chats List of recent chats | ||
| 99 | */ | ||
| 100 | async function sendWelcomePanel(chats) { | ||
| 90 | try { | 101 | try { |
| 91 | const chatElement = document.getElementById('chat'); | 102 | const chatElement = document.getElementById('chat'); |
| 92 | const sendTextArea = document.getElementById('send_textarea'); | 103 | const sendTextArea = document.getElementById('send_textarea'); |
| @@ -94,7 +105,6 @@ async function sendWelcomePanel() { | |||
| 94 | console.error('Chat element not found'); | 105 | console.error('Chat element not found'); |
| 95 | return; | 106 | return; |
| 96 | } | 107 | } |
| 97 | const chats = await getRecentChats(); | ||
| 98 | const templateData = { | 108 | const templateData = { |
| 99 | chats, | 109 | chats, |
| 100 | empty: !chats.length, | 110 | empty: !chats.length, |