mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-08-01 06:22:54 +02:00
Add new message sending scroll-to-bottom when near
This commit is contained in:
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
@@ -13,7 +13,7 @@
|
||||
<link rel="shortcut icon" href="/favicon.ico" />
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
|
||||
<link rel="manifest" href="/site.webmanifest" />
|
||||
<script type="module" crossorigin src="/assets/index-CvVcf00q.js"></script>
|
||||
<script type="module" crossorigin src="/assets/index-DVwayj9K.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-DaLCXB8p.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -80,7 +80,9 @@ export function MessageList({
|
||||
const scrollStateRef = useRef({
|
||||
scrollTop: 0,
|
||||
scrollHeight: 0,
|
||||
clientHeight: 0,
|
||||
wasNearTop: false,
|
||||
wasNearBottom: true, // Default to true so initial messages scroll to bottom
|
||||
});
|
||||
|
||||
// Handle scroll position AFTER render
|
||||
@@ -101,8 +103,8 @@ export function MessageList({
|
||||
if (scrollStateRef.current.wasNearTop && scrollHeightDiff > 0) {
|
||||
// User was near top (loading older) - preserve position by adding the height diff
|
||||
list.scrollTop = scrollStateRef.current.scrollTop + scrollHeightDiff;
|
||||
} else if (!scrollStateRef.current.wasNearTop) {
|
||||
// User was at bottom - scroll to bottom for new messages
|
||||
} else if (scrollStateRef.current.wasNearBottom) {
|
||||
// User was near bottom - scroll to bottom for new messages (including sent)
|
||||
list.scrollTop = list.scrollHeight;
|
||||
}
|
||||
}
|
||||
@@ -115,7 +117,7 @@ export function MessageList({
|
||||
if (messages.length === 0) {
|
||||
isInitialLoadRef.current = true;
|
||||
prevMessagesLengthRef.current = 0;
|
||||
scrollStateRef.current = { scrollTop: 0, scrollHeight: 0, wasNearTop: false };
|
||||
scrollStateRef.current = { scrollTop: 0, scrollHeight: 0, clientHeight: 0, wasNearTop: false, wasNearBottom: true };
|
||||
}
|
||||
}, [messages.length]);
|
||||
|
||||
@@ -124,16 +126,18 @@ export function MessageList({
|
||||
if (!listRef.current) return;
|
||||
|
||||
const { scrollTop, scrollHeight, clientHeight } = listRef.current;
|
||||
const distanceFromBottom = scrollHeight - scrollTop - clientHeight;
|
||||
|
||||
// Always capture current scroll state (needed for scroll preservation)
|
||||
scrollStateRef.current = {
|
||||
scrollTop,
|
||||
scrollHeight,
|
||||
clientHeight,
|
||||
wasNearTop: scrollTop < 150,
|
||||
wasNearBottom: distanceFromBottom < 100,
|
||||
};
|
||||
|
||||
// Show scroll-to-bottom button when not near the bottom (more than 100px away)
|
||||
const distanceFromBottom = scrollHeight - scrollTop - clientHeight;
|
||||
setShowScrollToBottom(distanceFromBottom > 100);
|
||||
|
||||
if (!onLoadOlder || loadingOlder || !hasOlderMessages) return;
|
||||
|
||||
Reference in New Issue
Block a user