mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-13 04:45:19 +00:00
Merge pull request #16061 from silentoplayz/fix/autoscrolling-in-FloatingButtons
fix: prevent error when autoscrolling in FloatingButtons
This commit is contained in:
commit
47d86d3c2f
1 changed files with 34 additions and 11 deletions
|
|
@ -4,7 +4,7 @@
|
|||
import DOMPurify from 'dompurify';
|
||||
import { marked } from 'marked';
|
||||
|
||||
import { getContext, tick } from 'svelte';
|
||||
import { getContext, tick, onDestroy } from 'svelte';
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
import { chatCompletion } from '$lib/apis/openai';
|
||||
|
|
@ -27,16 +27,19 @@
|
|||
let prompt = '';
|
||||
let responseContent = null;
|
||||
let responseDone = false;
|
||||
let controller = null;
|
||||
|
||||
const autoScroll = async () => {
|
||||
// Scroll to bottom only if the scroll is at the bottom give 50px buffer
|
||||
const responseContainer = document.getElementById('response-container');
|
||||
if (responseContainer) {
|
||||
// Scroll to bottom only if the scroll is at the bottom give 50px buffer
|
||||
if (
|
||||
responseContainer.scrollHeight - responseContainer.clientHeight <=
|
||||
responseContainer.scrollTop + 50
|
||||
) {
|
||||
responseContainer.scrollTop = responseContainer.scrollHeight;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const askHandler = async () => {
|
||||
|
|
@ -54,7 +57,8 @@
|
|||
floatingInputValue = '';
|
||||
|
||||
responseContent = '';
|
||||
const [res, controller] = await chatCompletion(localStorage.token, {
|
||||
let res;
|
||||
[res, controller] = await chatCompletion(localStorage.token, {
|
||||
model: model,
|
||||
messages: [
|
||||
...messages,
|
||||
|
|
@ -116,7 +120,13 @@
|
|||
};
|
||||
|
||||
// Process the stream in the background
|
||||
try {
|
||||
await processStream();
|
||||
} catch (e) {
|
||||
if (e.name !== 'AbortError') {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toast.error('An error occurred while fetching the explanation');
|
||||
}
|
||||
|
|
@ -134,7 +144,8 @@
|
|||
prompt = `${quotedText}\n\nExplain`;
|
||||
|
||||
responseContent = '';
|
||||
const [res, controller] = await chatCompletion(localStorage.token, {
|
||||
let res;
|
||||
[res, controller] = await chatCompletion(localStorage.token, {
|
||||
model: model,
|
||||
messages: [
|
||||
...messages,
|
||||
|
|
@ -196,7 +207,13 @@
|
|||
};
|
||||
|
||||
// Process the stream in the background
|
||||
try {
|
||||
await processStream();
|
||||
} catch (e) {
|
||||
if (e.name !== 'AbortError') {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toast.error('An error occurred while fetching the explanation');
|
||||
}
|
||||
|
|
@ -227,6 +244,12 @@
|
|||
floatingInput = false;
|
||||
floatingInputValue = '';
|
||||
};
|
||||
|
||||
onDestroy(() => {
|
||||
if (controller) {
|
||||
controller.abort();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<div
|
||||
|
|
|
|||
Loading…
Reference in a new issue