Skip to content

Commit 2ab960b

Browse files
author
Jicheng Lu
committed
fix chat box auto focus
1 parent f581257 commit 2ab960b

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/routes/chat/[agentId]/[conversationId]/chat-box.svelte

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@
214214
let isHandlingQueue = $state(false);
215215
let isStopStreamClicked = $state(false);
216216
217-
// let loadEditor = $derived(!isSendingMsg && !isThinking && loadTextEditor && messageQueue.length === 0);
217+
let isWaiting = $derived(isSendingMsg || isThinking || messageQueue.length > 0);
218218
let loadEditor = true;
219219
let disableAction = $derived(!ADMIN_ROLES.includes(currentUser?.role || '')
220220
&& currentUser?.id !== conversationUser?.id
221221
|| !AgentExtensions.chatable(agent));
222222
223223
$effect(() => {
224-
if (loadEditor) {
224+
if (!isWaiting && !disableAction) {
225225
focusChatTextArea();
226226
}
227227
});
@@ -280,8 +280,6 @@
280280
handleChatAction(e);
281281
}
282282
});
283-
284-
await focusChatTextArea();
285283
});
286284
287285
function handleLogoutAction() {

src/routes/chat/[agentId]/[conversationId]/rich-content/rc-embedding.svelte

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<script>
2+
import { getContext } from 'svelte';
23
import collapse from 'svelte-collapse';
34
5+
const collapseDuration = 0.3;
6+
const { autoScrollToBottom } = getContext('chat-window-context');
7+
48
/**
59
* @type {{
610
* url?: string,
@@ -18,6 +22,9 @@
1822
1923
function toggleCollapse() {
2024
open = !open;
25+
if (open) {
26+
setTimeout(() => autoScrollToBottom?.(), collapseDuration * 1000);
27+
}
2128
}
2229
</script>
2330
@@ -31,19 +38,22 @@
3138
<i class="bx bx-link-external"></i>
3239
</a>
3340
</div>
34-
<div use:collapse={{ open, duration: 0.3, easing: 'ease' }} style="width: 100%; margin-top: 8px;">
41+
<div use:collapse={{ open, duration: collapseDuration, easing: 'ease' }} style="width: 100%; margin-top: 8px;">
42+
{#if open}
3543
<div class="rc-embedding-container">
3644
{#if htmlTag === 'iframe'}
3745
<iframe
46+
class="rc-embedding-iframe"
3847
src={url}
3948
title={title || ''}
4049
frameborder="0"
4150
allowfullscreen
51+
referrerpolicy="no-referrer"
4252
sandbox="allow-scripts allow-same-origin allow-popups allow-forms"
43-
class="rc-embedding-iframe"
4453
></iframe>
4554
{/if}
4655
</div>
56+
{/if}
4757
</div>
4858
</div>
4959
{/if}

0 commit comments

Comments
 (0)