import { useState, useEffect, useRef } from "react"; import { api } from "../api"; const LOG_FILES = ["poller", "liquidsoap", "icecast_access", "icecast_error"]; export default function LogsPanel() { const [logFile, setLogFile] = useState("poller"); const [lines, setLines] = useState([]); const [lineCount, setLineCount] = useState(100); const [autoRefresh, setAutoRefresh] = useState(false); const [exists, setExists] = useState(true); const bottomRef = useRef(null); const fetchLogs = () => { api.getLogs({ file: logFile, lines: lineCount }) .then((data) => { setLines(data.lines); setExists(data.exists); }) .catch(() => {}); }; useEffect(fetchLogs, [logFile, lineCount]); useEffect(() => { if (!autoRefresh) return; const id = setInterval(fetchLogs, 5000); return () => clearInterval(id); }, [autoRefresh, logFile, lineCount]); useEffect(() => { bottomRef.current?.scrollIntoView({ behavior: "smooth" }); }, [lines]); return (

Logs

{!exists ? (
Log file {logFile}.log does not exist yet
) : lines.length === 0 ? (
Log file is empty
) : (
            {lines.map((line, i) => (
              
{line}
))}
)}
); }