Skip to content

Commit

Permalink
fix: reset to instant-scroll when
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Hopper-Lowe <[email protected]>
  • Loading branch information
ryanhopperlowe committed Mar 6, 2025
1 parent c2508f1 commit 3edbda8
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions ui/user/src/lib/components/Thread.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import { Thread } from '$lib/services/chat/thread.svelte';
import { ChatService, EditorService, type Messages, type Project } from '$lib/services';
import { fade } from 'svelte/transition';
import { onDestroy } from 'svelte';
import { onDestroy, tick } from 'svelte';

Check failure on line 8 in ui/user/src/lib/components/Thread.svelte

View workflow job for this annotation

GitHub Actions / lint

'tick' is defined but never used
import { toHTMLFromMarkdown } from '$lib/markdown';
import type { EditorItem } from '$lib/services/editor/index.svelte';
import { getLayout } from '$lib/context/layout.svelte';
import type { UIEventHandler } from 'svelte/elements';
interface Props {
id?: string;
Expand All @@ -24,15 +25,6 @@
let messagesDiv = $state<HTMLDivElement>();
let scrollSmooth = $state(false);
$effect(() => {
const update = () => (scrollSmooth = true);
container?.addEventListener('scroll', update);
return () => {
container?.removeEventListener('scroll', update);
scrollSmooth = false;
};
});
$effect(() => {
// Close and recreate thread if id changes
if (thread && thread.threadID !== id) {
Expand All @@ -44,6 +36,8 @@
};
}
scrollSmooth = false;
if (id && !thread) {
constructThread();
}
Expand Down Expand Up @@ -89,6 +83,15 @@
thread = newThread;
}
const onScrollEnd: UIEventHandler<HTMLDivElement> = (e) => {
const isAtBottom =
e.currentTarget.scrollHeight - e.currentTarget.scrollTop - e.currentTarget.clientHeight <= 0;
if (isAtBottom) {
scrollSmooth = true;
}
};
function onSendCredentials(id: string, credentials: Record<string, string>) {
thread?.sendCredentials(id, credentials);
}
Expand All @@ -103,6 +106,7 @@
contentEl: messagesDiv,
setControls: (controls) => (scrollControls = controls)
}}
onscrollend={onScrollEnd}
>
<div
in:fade|global
Expand Down

0 comments on commit 3edbda8

Please sign in to comment.