Merge pull request #1729 from Mega-Volti/main

Enable custom refresh rate for resource widget
pull/1735/head
shamoon 10 months ago committed by GitHub
commit 6586af17a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,11 +5,11 @@ import { useTranslation } from "next-i18next";
import Resource from "../widget/resource"; import Resource from "../widget/resource";
import Error from "../widget/error"; import Error from "../widget/error";
export default function Cpu({ expanded }) { export default function Cpu({ expanded, refresh = 1500 }) {
const { t } = useTranslation(); const { t } = useTranslation();
const { data, error } = useSWR(`/api/widgets/resources?type=cpu`, { const { data, error } = useSWR(`/api/widgets/resources?type=cpu`, {
refreshInterval: 1500, refreshInterval: refresh,
}); });
if (error || data?.error) { if (error || data?.error) {

@ -9,11 +9,11 @@ function convertToFahrenheit(t) {
return t * 9/5 + 32 return t * 9/5 + 32
} }
export default function CpuTemp({ expanded, units }) { export default function CpuTemp({ expanded, units, refresh = 1500 }) {
const { t } = useTranslation(); const { t } = useTranslation();
const { data, error } = useSWR(`/api/widgets/resources?type=cputemp`, { const { data, error } = useSWR(`/api/widgets/resources?type=cputemp`, {
refreshInterval: 1500, refreshInterval: refresh,
}); });
if (error || data?.error) { if (error || data?.error) {

@ -5,11 +5,11 @@ import { useTranslation } from "next-i18next";
import Resource from "../widget/resource"; import Resource from "../widget/resource";
import Error from "../widget/error"; import Error from "../widget/error";
export default function Disk({ options, expanded }) { export default function Disk({ options, expanded, refresh = 1500 }) {
const { t } = useTranslation(); const { t } = useTranslation();
const { data, error } = useSWR(`/api/widgets/resources?type=disk&target=${options.disk}`, { const { data, error } = useSWR(`/api/widgets/resources?type=disk&target=${options.disk}`, {
refreshInterval: 1500, refreshInterval: refresh,
}); });
if (error || data?.error) { if (error || data?.error) {

@ -5,11 +5,11 @@ import { useTranslation } from "next-i18next";
import Resource from "../widget/resource"; import Resource from "../widget/resource";
import Error from "../widget/error"; import Error from "../widget/error";
export default function Memory({ expanded }) { export default function Memory({ expanded, refresh = 1500 }) {
const { t } = useTranslation(); const { t } = useTranslation();
const { data, error } = useSWR(`/api/widgets/resources?type=memory`, { const { data, error } = useSWR(`/api/widgets/resources?type=memory`, {
refreshInterval: 1500, refreshInterval: refresh,
}); });
if (error || data?.error) { if (error || data?.error) {

@ -9,16 +9,18 @@ import Uptime from "./uptime";
export default function Resources({ options }) { export default function Resources({ options }) {
const { expanded, units } = options; const { expanded, units } = options;
let { refresh } = options;
refresh = Math.max(refresh, 1000);
return <Container options={options}> return <Container options={options}>
<Raw> <Raw>
<div className="flex flex-row self-center flex-wrap justify-between"> <div className="flex flex-row self-center flex-wrap justify-between">
{options.cpu && <Cpu expanded={expanded} />} {options.cpu && <Cpu expanded={expanded} refresh={refresh} />}
{options.memory && <Memory expanded={expanded} />} {options.memory && <Memory expanded={expanded} refresh={refresh} />}
{Array.isArray(options.disk) {Array.isArray(options.disk)
? options.disk.map((disk) => <Disk key={disk} options={{ disk }} expanded={expanded} />) ? options.disk.map((disk) => <Disk key={disk} options={{ disk }} expanded={expanded} refresh={refresh} />)
: options.disk && <Disk options={options} expanded={expanded} />} : options.disk && <Disk options={options} expanded={expanded} refresh={refresh} />}
{options.cputemp && <CpuTemp expanded={expanded} units={units} />} {options.cputemp && <CpuTemp expanded={expanded} units={units} refresh={refresh} />}
{options.uptime && <Uptime />} {options.uptime && <Uptime refresh={refresh} />}
</div> </div>
{options.label && ( {options.label && (
<div className="ml-6 pt-1 text-center text-theme-800 dark:text-theme-200 text-xs">{options.label}</div> <div className="ml-6 pt-1 text-center text-theme-800 dark:text-theme-200 text-xs">{options.label}</div>

@ -5,11 +5,11 @@ import { useTranslation } from "next-i18next";
import Resource from "../widget/resource"; import Resource from "../widget/resource";
import Error from "../widget/error"; import Error from "../widget/error";
export default function Uptime() { export default function Uptime({ refresh = 1500 }) {
const { t } = useTranslation(); const { t } = useTranslation();
const { data, error } = useSWR(`/api/widgets/resources?type=uptime`, { const { data, error } = useSWR(`/api/widgets/resources?type=uptime`, {
refreshInterval: 1500, refreshInterval: refresh,
}); });
if (error || data?.error) { if (error || data?.error) {

Loading…
Cancel
Save