feat(chat): auto scroll, stop scrolling when scrolled back

This commit is contained in:
ItzCrazyKns
2025-10-19 18:30:21 +05:30
parent 7d71643f42
commit 51629b2cca

View File

@@ -31,13 +31,22 @@ const Chat = () => {
useEffect(() => { useEffect(() => {
const scroll = () => { const scroll = () => {
messageEnd.current?.scrollIntoView({ behavior: 'smooth' }); messageEnd.current?.scrollIntoView({ behavior: 'auto' });
}; };
if (chatTurns.length === 1) { if (chatTurns.length === 1) {
document.title = `${chatTurns[0].content.substring(0, 30)} - Perplexica`; document.title = `${chatTurns[0].content.substring(0, 30)} - Perplexica`;
} }
const messageEndBottom =
messageEnd.current?.getBoundingClientRect().bottom ?? 0;
const distanceFromMessageEnd = window.innerHeight - messageEndBottom;
if (distanceFromMessageEnd >= -100) {
scroll();
}
if (chatTurns[chatTurns.length - 1]?.role === 'user') { if (chatTurns[chatTurns.length - 1]?.role === 'user') {
scroll(); scroll();
} }