Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset to instant-scroll when switching threads #1937

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions ui/user/src/lib/components/Thread.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import { sticktobottom, type StickToBottomControls } from '$lib/actions/div.svelte';
import Input from '$lib/components/messages/Input.svelte';
import Message from '$lib/components/messages/Message.svelte';
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 { getLayout } from '$lib/context/layout.svelte';
import { toHTMLFromMarkdown } from '$lib/markdown';
import { ChatService, EditorService, type Messages, type Project } from '$lib/services';
import { Thread } from '$lib/services/chat/thread.svelte';
import type { EditorItem } from '$lib/services/editor/index.svelte';
import { getLayout } from '$lib/context/layout.svelte';
import { onDestroy } from 'svelte';
import type { UIEventHandler } from 'svelte/elements';
import { fade } from 'svelte/transition';

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