mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-10-19 22:08:15 +00:00
feat(chat): auto scroll, stop scrolling when scrolled back
This commit is contained in:
@@ -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();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user