import useSWR from "swr"; import { BiError } from "react-icons/bi"; import { FaMemory } from "react-icons/fa"; import { FiCpu } from "react-icons/fi"; import { useTranslation } from "next-i18next"; import UsageBar from "../resources/usage-bar"; export default function Widget({ options }) { const { t, i18n } = useTranslation(); const { data, error } = useSWR( `/api/widgets/glances?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`, { refreshInterval: 1500, } ); if (error || data?.error) { return (
{t("widget.api_error")}
); } if (!data) { return (
{t("glances.wait")}
{t("glances.wait")}
{options.label && (
{options.label}
)}
); } return (
{t("common.number", { value: data.cpu, style: "unit", unit: "percent", maximumFractionDigits: 0, })}
{t("glances.cpu")}
{t("common.number", { value: data.mem, style: "unit", unit: "percent", maximumFractionDigits: 0, })}
{t("glances.mem")}
{options.label && (
{options.label}
)}
); }