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:
parent
af8f39f83a
commit
62cc0d7689
@ -27,18 +27,17 @@ export const LogList = observer(({ model }: LogListProps) => {
|
||||
});
|
||||
|
||||
const onScroll = (event: React.UIEvent<HTMLDivElement>) => {
|
||||
console.log("scrolling", toBottomVisible)
|
||||
if (!parentRef.current) return;
|
||||
|
||||
setToBottomVisibility();
|
||||
setLastLineVisibility();
|
||||
checkLoadIntent();
|
||||
onScrollToTop();
|
||||
}
|
||||
|
||||
// TODO: Move to its own hook
|
||||
const setToBottomVisibility = () => {
|
||||
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) {
|
||||
setToBottomVisible(true);
|
||||
} else {
|
||||
@ -59,11 +58,23 @@ export const LogList = observer(({ model }: LogListProps) => {
|
||||
/**
|
||||
* Check if user scrolled to top and new logs should be loaded
|
||||
*/
|
||||
const checkLoadIntent = () => {
|
||||
const onScrollToTop = async () => {
|
||||
const { scrollTop } = parentRef.current as HTMLDivElement;
|
||||
|
||||
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 });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user