fix: Chat scrollt bei User-Wechsel und erstem Laden sofort ans Ende
This commit is contained in:
@@ -208,12 +208,20 @@ export default function Nachrichten({ toast, mobile, nav }) {
|
||||
|
||||
// ── Scroll to bottom ─────────────────────────────────────────────────────────
|
||||
const prevLengthRef = useRef(0);
|
||||
const prevUserRef = useRef(null);
|
||||
useEffect(() => {
|
||||
const isFirstLoad = prevLengthRef.current === 0 && messages.length > 0;
|
||||
prevLengthRef.current = messages.length;
|
||||
if (!bottomRef.current) return;
|
||||
bottomRef.current.scrollIntoView({ behavior: isFirstLoad ? 'instant' : 'smooth' });
|
||||
}, [messages.length]);
|
||||
const userChanged = prevUserRef.current !== activeUser?.id;
|
||||
const isFirstLoad = prevLengthRef.current === 0 && messages.length > 0;
|
||||
prevLengthRef.current = messages.length;
|
||||
prevUserRef.current = activeUser?.id;
|
||||
// Bei User-Wechsel oder erstem Laden: sofort ans Ende springen
|
||||
if (userChanged || isFirstLoad) {
|
||||
bottomRef.current.scrollIntoView({ behavior: 'instant' });
|
||||
} else if (messages.length > 0) {
|
||||
bottomRef.current.scrollIntoView({ behavior: 'smooth' });
|
||||
}
|
||||
}, [messages.length, activeUser?.id]);
|
||||
|
||||
// ── Handlers ─────────────────────────────────────────────────────────────────
|
||||
const loadUsers = async () => {
|
||||
|
||||
Reference in New Issue
Block a user