scroll to bottom of messages
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { useState } from "preact/hooks";
|
import { createRef } from "preact";
|
||||||
|
import { useEffect, useState } from "preact/hooks";
|
||||||
import type { ChatStore } from "./app";
|
import type { ChatStore } from "./app";
|
||||||
import ChatGPT, { ChunkMessage, FetchResponse } from "./chatgpt";
|
import ChatGPT, { ChunkMessage, FetchResponse } from "./chatgpt";
|
||||||
import Message from "./message";
|
import Message from "./message";
|
||||||
@@ -16,6 +17,12 @@ export default function ChatBOX(props: {
|
|||||||
const [generatingMessage, setGeneratingMessage] = useState("");
|
const [generatingMessage, setGeneratingMessage] = useState("");
|
||||||
const [showRetry, setShowRetry] = useState(false);
|
const [showRetry, setShowRetry] = useState(false);
|
||||||
|
|
||||||
|
const messagesEndRef = createRef();
|
||||||
|
useEffect(() => {
|
||||||
|
console.log("ref", messagesEndRef);
|
||||||
|
messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
|
||||||
|
}, [showRetry, showGenerating]);
|
||||||
|
|
||||||
const client = new ChatGPT(chatStore.apiKey);
|
const client = new ChatGPT(chatStore.apiKey);
|
||||||
|
|
||||||
const _completeWithStreamMode = async (response: Response) => {
|
const _completeWithStreamMode = async (response: Response) => {
|
||||||
@@ -136,7 +143,6 @@ export default function ChatBOX(props: {
|
|||||||
setChatStore({ ...chatStore });
|
setChatStore({ ...chatStore });
|
||||||
setInputMsg("");
|
setInputMsg("");
|
||||||
await complete();
|
await complete();
|
||||||
setChatStore({ ...chatStore });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const [showSettings, setShowSettings] = useState(false);
|
const [showSettings, setShowSettings] = useState(false);
|
||||||
@@ -214,6 +220,7 @@ export default function ChatBOX(props: {
|
|||||||
</button>
|
</button>
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
<div ref={messagesEndRef}></div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<textarea
|
<textarea
|
||||||
|
|||||||
Reference in New Issue
Block a user