mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
26 lines
821 B
TypeScript
26 lines
821 B
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
|
|
import type { RefObject } from "react";
|
|
import { useEffect } from "react";
|
|
import useIntersectionObserver from "../../../hooks/useIntersectionObserver";
|
|
import type { LogTabViewModel } from "./logs-view-model";
|
|
|
|
interface UseStickToBottomProps {
|
|
bottomLineRef: RefObject<HTMLDivElement>;
|
|
model: LogTabViewModel;
|
|
scrollToBottom: () => void;
|
|
}
|
|
|
|
export function useStickToBottomOnLogsLoad({ bottomLineRef, model, scrollToBottom }: UseStickToBottomProps) {
|
|
const bottomLineEntry = useIntersectionObserver(bottomLineRef.current, {});
|
|
|
|
useEffect(() => {
|
|
if (bottomLineEntry?.isIntersecting) {
|
|
scrollToBottom();
|
|
}
|
|
}, [model.visibleLogs.get().length]);
|
|
}
|