1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/dock/logs/use-stick-to-bottom-on-logs-load.ts
alexfront d951f3a017 Move all side effects to hooks
Signed-off-by: alexfront <alex.andreev.email@gmail.com>
2022-09-08 16:00:01 +03:00

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]);
}