victor HF staff commited on
Commit
f61a0be
1 Parent(s): 72938d2

autoscroll and new chat

Browse files
Files changed (1) hide show
  1. src/routes/+page.svelte +9 -1
src/routes/+page.svelte CHANGED
@@ -1,4 +1,5 @@
1
  <script lang="ts">
 
2
  import { fetchEventSource } from '@microsoft/fetch-event-source';
3
  import ChatBox from '$lib/chat/ChatBox.svelte';
4
  import ChatIntroduction from '$lib/chat/ChatIntroduction.svelte';
@@ -12,6 +13,12 @@
12
  let messages: Message[] = [];
13
  let message = '';
14
 
 
 
 
 
 
 
15
  function onWrite() {
16
  messages = [...messages, { from: 'user', content: message }];
17
  message = '';
@@ -74,6 +81,7 @@
74
  >
75
  <div class="flex-none sticky top-0 relative p-3 flex flex-col">
76
  <button
 
77
  class="border px-12 py-2.5 rounded-lg border shadow bg-white dark:bg-gray-700 dark:border-gray-600"
78
  >New Chat</button
79
  >
@@ -104,7 +112,7 @@
104
  </div>
105
  </nav>
106
  <div class="relative h-screen">
107
- <div class="overflow-y-auto h-full">
108
  <div class="max-w-3xl xl:max-w-4xl mx-auto px-5 pt-6 flex flex-col gap-8 h-full">
109
  {#each messages as message}
110
  <ChatBox {message} />
 
1
  <script lang="ts">
2
+ import { afterUpdate } from 'svelte'
3
  import { fetchEventSource } from '@microsoft/fetch-event-source';
4
  import ChatBox from '$lib/chat/ChatBox.svelte';
5
  import ChatIntroduction from '$lib/chat/ChatIntroduction.svelte';
 
13
  let messages: Message[] = [];
14
  let message = '';
15
 
16
+ let messagesContainer: HTMLElement;
17
+
18
+ afterUpdate(() => {
19
+ messagesContainer.scrollTo(0, messagesContainer.scrollHeight);
20
+ });
21
+
22
  function onWrite() {
23
  messages = [...messages, { from: 'user', content: message }];
24
  message = '';
 
81
  >
82
  <div class="flex-none sticky top-0 relative p-3 flex flex-col">
83
  <button
84
+ on:click={() => {location.reload}}
85
  class="border px-12 py-2.5 rounded-lg border shadow bg-white dark:bg-gray-700 dark:border-gray-600"
86
  >New Chat</button
87
  >
 
112
  </div>
113
  </nav>
114
  <div class="relative h-screen">
115
+ <div class="overflow-y-auto h-full" bind:this={messagesContainer}>
116
  <div class="max-w-3xl xl:max-w-4xl mx-auto px-5 pt-6 flex flex-col gap-8 h-full">
117
  {#each messages as message}
118
  <ChatBox {message} />