fix chat scroll behaviour
This commit is contained in:
@@ -111,14 +111,9 @@ function AiChatPage() {
|
|||||||
lastScrolledIdRef.current = lastMsg.id;
|
lastScrolledIdRef.current = lastMsg.id;
|
||||||
const area = messagesAreaRef.current;
|
const area = messagesAreaRef.current;
|
||||||
if (!area) return;
|
if (!area) return;
|
||||||
const isOwn = lastMsg.senderId === user?.id;
|
const nearBottom = area.scrollHeight - area.scrollTop - area.clientHeight < 150;
|
||||||
if (isOwn) {
|
if (nearBottom) messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
||||||
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
}, [messages]);
|
||||||
} else {
|
|
||||||
const nearBottom = area.scrollHeight - area.scrollTop - area.clientHeight < 150;
|
|
||||||
if (nearBottom) messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
||||||
}
|
|
||||||
}, [messages, user?.id]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!botTyping) return;
|
if (!botTyping) return;
|
||||||
|
|||||||
@@ -109,14 +109,9 @@ function ChatPage() {
|
|||||||
lastScrolledIdRef.current = lastMsg.id;
|
lastScrolledIdRef.current = lastMsg.id;
|
||||||
const area = messagesAreaRef.current;
|
const area = messagesAreaRef.current;
|
||||||
if (!area) return;
|
if (!area) return;
|
||||||
const isOwn = lastMsg.senderId === user?.id;
|
const nearBottom = area.scrollHeight - area.scrollTop - area.clientHeight < 150;
|
||||||
if (isOwn) {
|
if (nearBottom) area.scrollTop = area.scrollHeight;
|
||||||
area.scrollTop = area.scrollHeight;
|
}, [messages]);
|
||||||
} else {
|
|
||||||
const nearBottom = area.scrollHeight - area.scrollTop - area.clientHeight < 80;
|
|
||||||
if (nearBottom) area.scrollTop = area.scrollHeight;
|
|
||||||
}
|
|
||||||
}, [messages, user?.id]);
|
|
||||||
|
|
||||||
const fetchMessages = useCallback(async (convId) => {
|
const fetchMessages = useCallback(async (convId) => {
|
||||||
if (!token || !convId) return;
|
if (!token || !convId) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user