1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Keep scrolling position when loaded more logs

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2022-09-02 10:28:37 +03:00
parent af8f39f83a
commit 62cc0d7689

View File

@ -27,18 +27,17 @@ export const LogList = observer(({ model }: LogListProps) => {
}); });
const onScroll = (event: React.UIEvent<HTMLDivElement>) => { const onScroll = (event: React.UIEvent<HTMLDivElement>) => {
console.log("scrolling", toBottomVisible)
if (!parentRef.current) return; if (!parentRef.current) return;
setToBottomVisibility(); setToBottomVisibility();
setLastLineVisibility(); setLastLineVisibility();
checkLoadIntent(); onScrollToTop();
} }
// TODO: Move to its own hook // TODO: Move to its own hook
const setToBottomVisibility = () => { const setToBottomVisibility = () => {
const { scrollTop, scrollHeight } = parentRef.current as HTMLDivElement; const { scrollTop, scrollHeight } = parentRef.current as HTMLDivElement;
console.log("scrolling", scrollHeight, scrollTop, rowVirtualizer.getTotalSize()) // console.log("scrolling", scrollHeight, scrollTop, rowVirtualizer.getTotalSize())
if (scrollHeight - scrollTop > 4000) { if (scrollHeight - scrollTop > 4000) {
setToBottomVisible(true); setToBottomVisible(true);
} else { } else {
@ -59,11 +58,23 @@ export const LogList = observer(({ model }: LogListProps) => {
/** /**
* Check if user scrolled to top and new logs should be loaded * Check if user scrolled to top and new logs should be loaded
*/ */
const checkLoadIntent = () => { const onScrollToTop = async () => {
const { scrollTop } = parentRef.current as HTMLDivElement; const { scrollTop } = parentRef.current as HTMLDivElement;
if (scrollTop === 0) { if (scrollTop === 0) {
model.loadLogs(); const oldLogsAmount = visibleLogs.get().length;
await model.loadLogs();
const newLogsAmount = visibleLogs.get().length;
const scrollToIndex = newLogsAmount - oldLogsAmount;
console.log("new logs loaded", oldLogsAmount, newLogsAmount, scrollToIndex);
setTimeout(() => {
rowVirtualizer.scrollToIndex(scrollToIndex, { align: 'start', smoothScroll: false });
}, 1000)
// rowVirtualizer.scrollToIndex(scrollToIndex, { align: 'start', smoothScroll: false });
} }
}; };