Skip to content

Commit 3f6468b

Browse files
committed
refactor: Cleanup
1 parent 10f0559 commit 3f6468b

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

tools/server/webui/src/lib/components/chat/ChatMessages.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import type { Message } from '$lib/types/database';
33
import { updateMessage, regenerateMessage } from '$lib/stores/chat.svelte';
44
import { ChatMessage } from '$lib/components';
5+
56
interface Props {
67
class?: string;
78
messages?: Message[];
8-
isLoading?: boolean;
99
}
1010
11-
let { class: className, messages = [], isLoading = false }: Props = $props();
11+
let { class: className, messages = [] }: Props = $props();
1212
</script>
1313

1414
<div class="flex h-full flex-col space-y-10 pt-16 md:pt-24 {className}" style="height: auto; ">

tools/server/webui/src/lib/components/chat/ChatScreen.svelte

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<script lang="ts">
22
import { afterNavigate } from '$app/navigation';
3-
import { navigating } from '$app/state';
43
import { ChatForm, ChatMessages, ServerInfo } from '$lib/components';
54
import {
65
activeMessages,
76
activeConversation,
87
isLoading,
98
sendMessage,
109
stopGeneration,
11-
12-
chatStore
13-
1410
} from '$lib/stores/chat.svelte';
1511
import { onMount } from 'svelte';
1612
import { fly, slide } from 'svelte/transition';
1713
1814
let { showCenteredEmpty = false } = $props();
1915
16+
let chatScrollContainer: HTMLDivElement | undefined = $state();
17+
let scrollInterval: ReturnType<typeof setInterval> | undefined;
18+
let autoScrollEnabled = $state(true);
19+
2020
const isEmpty = $derived(
2121
showCenteredEmpty && !activeConversation() && activeMessages().length === 0 && !isLoading()
2222
);
@@ -25,7 +25,6 @@
2525
await sendMessage(message);
2626
}
2727
28-
let chatScrollContainer: HTMLDivElement | undefined = $state();
2928
3029
function scrollChatToBottom() {
3130
chatScrollContainer?.scrollTo({top: chatScrollContainer?.scrollHeight, behavior: 'instant'})
@@ -39,42 +38,33 @@
3938
setTimeout(scrollChatToBottom, 10); // This is a dirty workaround, need to find racing conditions
4039
})
4140
42-
let scrollInterval: ReturnType<typeof setInterval> | undefined;
43-
let autoScrollEnabled = $state(true);
4441
4542
function handleScroll() {
4643
if (!chatScrollContainer) return;
4744
4845
const { scrollTop, scrollHeight, clientHeight } = chatScrollContainer;
4946
const distanceFromBottom = scrollHeight - scrollTop - clientHeight;
5047
51-
// Disable auto-scroll when user scrolls up 50px+ from bottom
5248
if (distanceFromBottom > 50) {
5349
autoScrollEnabled = false;
54-
}
55-
// Re-enable auto-scroll when user reaches bottom
56-
else if (distanceFromBottom <= 1) {
50+
} else if (distanceFromBottom <= 1) {
5751
autoScrollEnabled = true;
5852
}
5953
}
6054
6155
$effect(() => {
6256
if (isLoading() && autoScrollEnabled) {
6357
scrollInterval = setInterval(scrollChatToBottom, 100);
64-
} else {
65-
if (scrollInterval) {
66-
clearInterval(scrollInterval);
67-
scrollInterval = undefined;
68-
}
58+
} else if (scrollInterval) {
59+
clearInterval(scrollInterval);
60+
scrollInterval = undefined;
6961
}
7062
})
71-
72-
$inspect(chatStore.isLoading)
7363
</script>
7464

7565
{#if !isEmpty}
7666
<div class="flex h-full flex-col overflow-y-auto" bind:this={chatScrollContainer} onscroll={handleScroll}>
77-
<ChatMessages class="mb-36" messages={activeMessages()} isLoading={isLoading()} />
67+
<ChatMessages class="mb-36" messages={activeMessages()} />
7868

7969
<div
8070
class="z-999 sticky bottom-0 mx-auto mt-auto max-w-[56rem]"

0 commit comments

Comments
 (0)