fix: history follow latest

This commit is contained in:
Shibo Lyu 2024-08-31 05:12:12 +08:00
parent 13bd2e31e7
commit 38c08ec8d9

View file

@ -3,13 +3,19 @@
import type { Message } from '$lib/types'; import type { Message } from '$lib/types';
import ChatMessage from './ChatMessage.svelte'; import ChatMessage from './ChatMessage.svelte';
import { tick } from 'svelte';
export let messages: Message[] = []; export let messages: Message[] = [];
export let mySenderId: string; export let mySenderId: string;
let ref: VList<Message>; let ref: VList<Message> | undefined;
$: ref?.scrollToIndex(messages.length - 1, { align: 'end', smooth: true }); async function scrollToIndex(index: number, smooth = true) {
await tick();
ref?.scrollToIndex(index, { align: 'end', smooth });
}
$: scrollToIndex(messages.length - 1);
</script> </script>
<VList data={messages} let:item={message} class="size-full pt-2" bind:this={ref}> <VList data={messages} let:item={message} class="size-full pt-2" bind:this={ref}>