mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-01-07 00:06:57 +01:00
Add button to scroll to bottom of logs (#10006)
* Add button to scroll to bottom of logs * Cleanup
This commit is contained in:
parent
74a8fee69c
commit
50ab988d81
@ -10,7 +10,7 @@ import {
|
|||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import Heading from "@/components/ui/heading";
|
import Heading from "@/components/ui/heading";
|
||||||
import copy from "copy-to-clipboard";
|
import copy from "copy-to-clipboard";
|
||||||
import { useCallback, useMemo, useState } from "react";
|
import { useCallback, useMemo, useRef, useState } from "react";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
|
||||||
const logTypes = ["frigate", "go2rtc", "nginx"] as const;
|
const logTypes = ["frigate", "go2rtc", "nginx"] as const;
|
||||||
@ -40,6 +40,26 @@ function Logs() {
|
|||||||
copy(logs);
|
copy(logs);
|
||||||
}, [logs]);
|
}, [logs]);
|
||||||
|
|
||||||
|
// scroll to bottom button
|
||||||
|
|
||||||
|
const contentRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
const [endVisible, setEndVisible] = useState(true);
|
||||||
|
const observer = useRef<IntersectionObserver | null>(null);
|
||||||
|
const endLogRef = useCallback(
|
||||||
|
(node: HTMLElement | null) => {
|
||||||
|
if (observer.current) observer.current.disconnect();
|
||||||
|
try {
|
||||||
|
observer.current = new IntersectionObserver((entries) => {
|
||||||
|
setEndVisible(entries[0].isIntersecting);
|
||||||
|
});
|
||||||
|
if (node) observer.current.observe(node);
|
||||||
|
} catch (e) {
|
||||||
|
// no op
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[setEndVisible]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative w-full h-full overflow-hidden">
|
<div className="relative w-full h-full overflow-hidden">
|
||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center">
|
||||||
@ -76,8 +96,26 @@ function Logs() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="absolute left-0 top-16 bottom-2 right-2 overflow-auto font-mono text-sm bg-secondary rounded p-2 whitespace-pre-wrap">
|
{!endVisible && (
|
||||||
|
<div
|
||||||
|
className="absolute bottom-8 left-[50%] -translate-x-[50%] rounded-xl bg-accent-foreground text-white z-20 p-2"
|
||||||
|
onClick={() =>
|
||||||
|
contentRef.current?.scrollTo({
|
||||||
|
top: contentRef.current?.scrollHeight,
|
||||||
|
behavior: "smooth",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Jump to Bottom
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div
|
||||||
|
ref={contentRef}
|
||||||
|
className="absolute left-0 top-16 bottom-2 right-2 overflow-auto font-mono text-sm bg-secondary rounded p-2 whitespace-pre-wrap"
|
||||||
|
>
|
||||||
{logs}
|
{logs}
|
||||||
|
<div ref={endLogRef} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user