import useSWR from "swr"; import { FaThermometerHalf } from "react-icons/fa"; import { BiError } from "react-icons/bi"; import { useTranslation } from "next-i18next"; import UsageBar from "./usage-bar"; export default function CpuTemp({ expanded, units }) { const { t } = useTranslation(); const { data, error } = useSWR(`/api/widgets/resources?type=cputemp`, { refreshInterval: 1500, }); if (error || data?.error) { return (
{t("widget.api_error")}
); } if (!data) { return (
-
{t("resources.temp")}
{expanded && (
-
{t("resources.max")}
)}
); } const unit = units === "imperial" ? "fahrenheit" : "celsius"; const mainTemp = (unit === "celsius") ? data.cputemp.main : data.cputemp.main * 5/9 + 32; const maxTemp = (unit === "celsius") ? data.cputemp.max : data.cputemp.max * 5/9 + 32; const percent = Math.round((mainTemp / maxTemp) * 100); return (
{t("common.number", { value: mainTemp, maximumFractionDigits: 1, style: "unit", unit })}
{t("resources.temp")}
{expanded && (
{t("common.number", { value: maxTemp, maximumFractionDigits: 1, style: "unit", unit })}
{t("resources.max")}
)}
); }