Skip to content

Commit 949617a

Browse files
fix: reset to instant-scroll when
Signed-off-by: Ryan Hopper-Lowe <[email protected]>
1 parent c2508f1 commit 949617a

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

ui/user/src/lib/components/Thread.svelte

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
import { sticktobottom, type StickToBottomControls } from '$lib/actions/div.svelte';
33
import Input from '$lib/components/messages/Input.svelte';
44
import Message from '$lib/components/messages/Message.svelte';
5-
import { Thread } from '$lib/services/chat/thread.svelte';
6-
import { ChatService, EditorService, type Messages, type Project } from '$lib/services';
7-
import { fade } from 'svelte/transition';
8-
import { onDestroy } from 'svelte';
5+
import { getLayout } from '$lib/context/layout.svelte';
96
import { toHTMLFromMarkdown } from '$lib/markdown';
7+
import { ChatService, EditorService, type Messages, type Project } from '$lib/services';
8+
import { Thread } from '$lib/services/chat/thread.svelte';
109
import type { EditorItem } from '$lib/services/editor/index.svelte';
11-
import { getLayout } from '$lib/context/layout.svelte';
10+
import { onDestroy } from 'svelte';
11+
import type { UIEventHandler } from 'svelte/elements';
12+
import { fade } from 'svelte/transition';
1213
1314
interface Props {
1415
id?: string;
@@ -24,15 +25,6 @@
2425
let messagesDiv = $state<HTMLDivElement>();
2526
let scrollSmooth = $state(false);
2627
27-
$effect(() => {
28-
const update = () => (scrollSmooth = true);
29-
container?.addEventListener('scroll', update);
30-
return () => {
31-
container?.removeEventListener('scroll', update);
32-
scrollSmooth = false;
33-
};
34-
});
35-
3628
$effect(() => {
3729
// Close and recreate thread if id changes
3830
if (thread && thread.threadID !== id) {
@@ -44,6 +36,8 @@
4436
};
4537
}
4638
39+
scrollSmooth = false;
40+
4741
if (id && !thread) {
4842
constructThread();
4943
}
@@ -89,6 +83,15 @@
8983
thread = newThread;
9084
}
9185
86+
const onScrollEnd: UIEventHandler<HTMLDivElement> = (e) => {
87+
const isAtBottom =
88+
e.currentTarget.scrollHeight - e.currentTarget.scrollTop - e.currentTarget.clientHeight <= 0;
89+
90+
if (isAtBottom) {
91+
scrollSmooth = true;
92+
}
93+
};
94+
9295
function onSendCredentials(id: string, credentials: Record<string, string>) {
9396
thread?.sendCredentials(id, credentials);
9497
}
@@ -103,6 +106,7 @@
103106
contentEl: messagesDiv,
104107
setControls: (controls) => (scrollControls = controls)
105108
}}
109+
onscrollend={onScrollEnd}
106110
>
107111
<div
108112
in:fade|global

0 commit comments

Comments
 (0)