Skip to content

Commit

Permalink
feat(chat): autoscroll to bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
PleahMaCaka committed Nov 2, 2023
1 parent a71399a commit a795fe1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/routes/chat/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,26 @@
import ChatInput from "$lib/components/share/ChatInput.svelte";
import { stateStore } from "$lib/stores/StateStore"
import { Author } from "$lib/types/Chat"
import { afterUpdate } from "svelte"
$: history = $stateStore.history
let historyElement: HTMLDivElement
afterUpdate(() => {
autoScrollToBottom(historyElement)
})
const autoScrollToBottom = async (node: HTMLElement) => {
node.scroll({
top: node.scrollHeight,
behavior: "smooth"
})
}
</script>

<div id="chat-page">
<div id="chat-history">
<div id="chat-history" bind:this={historyElement}>
{#each history as ctx}
{#if ctx.author === Author.Assistant}
<AssistantMessage message={ctx.message} />
Expand Down Expand Up @@ -38,7 +52,7 @@
flex-direction: column;
height: 100%;
width: 100%;
overflow-y: auto;
overflow: auto;
margin-bottom: 2%;
}
</style>

0 comments on commit a795fe1

Please sign in to comment.