import useSWR from "swr";
import { FaThermometerHalf } from "react-icons/fa";
import { BiError } from "react-icons/bi";
import { useTranslation } from "next-i18next";
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 (
);
}
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;
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")}
)}
);
}