You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
homepage/src/components/widgets/resources/disk.jsx

44 lines
1.2 KiB

import useSWR from "swr";
import { FiHardDrive } from "react-icons/fi";
import { useTranslation } from "next-i18next";
2 years ago
import Resource from "../widget/resource";
import Error from "../widget/error";
export default function Disk({ options, expanded, refresh = 1500 }) {
2 years ago
const { t } = useTranslation();
const { data, error } = useSWR(`api/widgets/resources?type=disk&target=${options.disk}`, {
refreshInterval: refresh,
});
if (error || data?.error) {
return <Error options={options} />
}
if (!data || !data.drive) {
return <Resource
icon={FiHardDrive}
value="-"
label={t("resources.free")}
expandedValue="-"
expandedLabel={t("resources.total")}
expanded={expanded}
percentage="0"
/>;
}
// data.drive.used not accurate?
const percent = Math.round(((data.drive.size - data.drive.available) / data.drive.size) * 100);
return <Resource
icon={FiHardDrive}
value={t("common.bytes", { value: data.drive.available })}
label={t("resources.free")}
expandedValue={t("common.bytes", { value: data.drive.size })}
expandedLabel={t("resources.total")}
percentage={percent}
expanded={expanded}
/>;
}