From e1503bf9b5b6428854beef6d2af153518dea4f16 Mon Sep 17 00:00:00 2001 From: Jicheng Lu Date: Tue, 1 Oct 2024 18:51:59 -0500 Subject: [PATCH] refine code --- .../[conversationId]/chat-box.svelte | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte index f8694fd..24b771a 100644 --- a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte @@ -198,11 +198,11 @@ refresh(); autoScrollLog = false; - window.addEventListener('message', async e => { + window.addEventListener('message', e => { if (e.data.action === ChatAction.Logout) { handleLogoutAction(); } else if (e.data.action === ChatAction.NewChat) { - await handleNewChatAction(e); + handleNewChatAction(e); } else if (e.data.action === ChatAction.Chat) { handleChatAction(e); } @@ -214,23 +214,25 @@ } /** @param {any} e */ - async function handleNewChatAction(e) { + function handleNewChatAction(e) { if (!isCreatingNewConv && !isThinking && !isSendingMsg) { isCreatingNewConv = true; - const conv = await createNewConversation(); - isCreatingNewConv = false; - - if (conv && !!e.data.text) { - isLoading = true; - sendChatMessage(e.data.text, e.data.data || null, conv.id).then(() => { - redirectToNewConversation(conv); - isLoading = false; - openFrame(); - }).catch(() => { - isLoading = false; - openFrame(); - }); - } + createNewConversation().then(conv => { + isCreatingNewConv = false; + if (conv && !!e.data.text) { + isLoading = true; + sendChatMessage(e.data.text, e.data.data || null, conv.id).then(() => { + redirectToNewConversation(conv); + isLoading = false; + openFrame(); + }).catch(() => { + isLoading = false; + openFrame(); + }); + } + }).catch(() => { + isCreatingNewConv = false; + }); } }