import useSWR from "swr"; import { FrigateStats } from "@/types/stats"; import { useEffect, useState } from "react"; import TimeAgo from "@/components/dynamic/TimeAgo"; import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"; import { isDesktop, isMobile } from "react-device-detect"; import GeneralMetrics from "@/views/system/GeneralMetrics"; import StorageMetrics from "@/views/system/StorageMetrics"; import { LuActivity, LuHardDrive } from "react-icons/lu"; import { FaVideo } from "react-icons/fa"; import Logo from "@/components/Logo"; import useOptimisticState from "@/hooks/use-optimistic-state"; import CameraMetrics from "@/views/system/CameraMetrics"; import { useHashState } from "@/hooks/use-overlay-state"; import { capitalizeFirstLetter } from "@/utils/stringUtil"; const metrics = ["general", "storage", "cameras"] as const; type SystemMetric = (typeof metrics)[number]; function System() { // stats page const [page, setPage] = useHashState(); const [pageToggle, setPageToggle] = useOptimisticState( page ?? "general", setPage, 100, ); const [lastUpdated, setLastUpdated] = useState(Date.now() / 1000); useEffect(() => { if (pageToggle) { document.title = `${capitalizeFirstLetter(pageToggle)} Stats - Frigate`; } }, [pageToggle]); // stats collection const { data: statsSnapshot } = useSWR("stats", { revalidateOnFocus: false, }); return (
{isMobile && ( )} { if (value) { setPageToggle(value); } }} // don't allow the severity to be unselected > {Object.values(metrics).map((item) => ( {item == "general" && } {item == "storage" && } {item == "cameras" && } {isDesktop &&
{item}
}
))}
{lastUpdated && (
Last refreshed:
)}
System
{statsSnapshot && (
{statsSnapshot.service.version}
)}
{page == "general" && ( )} {page == "storage" && } {page == "cameras" && ( )}
); } export default System;