import { useEmbeddingsReindexProgress } from "@/api/ws"; import { StatusBarMessagesContext, StatusMessage, } from "@/context/statusbar-provider"; import useStats, { useAutoFrigateStats } from "@/hooks/use-stats"; import { useContext, useEffect, useMemo } from "react"; import { FaCheck } from "react-icons/fa"; import { IoIosWarning } from "react-icons/io"; import { MdCircle } from "react-icons/md"; import { Link } from "react-router-dom"; export default function Statusbar() { const { messages, addMessage, clearMessages } = useContext( StatusBarMessagesContext, )!; const stats = useAutoFrigateStats(); const cpuPercent = useMemo(() => { const systemCpu = stats?.cpu_usages["frigate.full_system"]?.cpu; if (!systemCpu || systemCpu == "0.0") { return null; } return parseInt(systemCpu); }, [stats]); const { potentialProblems } = useStats(stats); useEffect(() => { clearMessages("stats"); potentialProblems.forEach((problem) => { addMessage( "stats", problem.text, problem.color, undefined, problem.relevantLink, ); }); }, [potentialProblems, addMessage, clearMessages]); const { payload: reindexState } = useEmbeddingsReindexProgress(); useEffect(() => { if (reindexState) { if (reindexState.status == "indexing") { clearMessages("embeddings-reindex"); addMessage( "embeddings-reindex", `Reindexing embeddings (${Math.floor((reindexState.processed_objects / reindexState.total_objects) * 100)}% complete)`, ); } if (reindexState.status === "completed") { clearMessages("embeddings-reindex"); } } }, [reindexState, addMessage, clearMessages]); return (