Merge pull request #1729 from Mega-Volti/main
Enable custom refresh rate for resource widget
This commit is contained in:
commit
6586af17a3
6 changed files with 18 additions and 16 deletions
|
@ -5,11 +5,11 @@ import { useTranslation } from "next-i18next";
|
|||
import Resource from "../widget/resource";
|
||||
import Error from "../widget/error";
|
||||
|
||||
export default function Cpu({ expanded }) {
|
||||
export default function Cpu({ expanded, refresh = 1500 }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { data, error } = useSWR(`/api/widgets/resources?type=cpu`, {
|
||||
refreshInterval: 1500,
|
||||
refreshInterval: refresh,
|
||||
});
|
||||
|
||||
if (error || data?.error) {
|
||||
|
|
|
@ -9,11 +9,11 @@ function convertToFahrenheit(t) {
|
|||
return t * 9/5 + 32
|
||||
}
|
||||
|
||||
export default function CpuTemp({ expanded, units }) {
|
||||
export default function CpuTemp({ expanded, units, refresh = 1500 }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { data, error } = useSWR(`/api/widgets/resources?type=cputemp`, {
|
||||
refreshInterval: 1500,
|
||||
refreshInterval: refresh,
|
||||
});
|
||||
|
||||
if (error || data?.error) {
|
||||
|
|
|
@ -5,11 +5,11 @@ import { useTranslation } from "next-i18next";
|
|||
import Resource from "../widget/resource";
|
||||
import Error from "../widget/error";
|
||||
|
||||
export default function Disk({ options, expanded }) {
|
||||
export default function Disk({ options, expanded, refresh = 1500 }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { data, error } = useSWR(`/api/widgets/resources?type=disk&target=${options.disk}`, {
|
||||
refreshInterval: 1500,
|
||||
refreshInterval: refresh,
|
||||
});
|
||||
|
||||
if (error || data?.error) {
|
||||
|
|
|
@ -5,11 +5,11 @@ import { useTranslation } from "next-i18next";
|
|||
import Resource from "../widget/resource";
|
||||
import Error from "../widget/error";
|
||||
|
||||
export default function Memory({ expanded }) {
|
||||
export default function Memory({ expanded, refresh = 1500 }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { data, error } = useSWR(`/api/widgets/resources?type=memory`, {
|
||||
refreshInterval: 1500,
|
||||
refreshInterval: refresh,
|
||||
});
|
||||
|
||||
if (error || data?.error) {
|
||||
|
|
|
@ -9,16 +9,18 @@ import Uptime from "./uptime";
|
|||
|
||||
export default function Resources({ options }) {
|
||||
const { expanded, units } = options;
|
||||
let { refresh } = options;
|
||||
refresh = Math.max(refresh, 1000);
|
||||
return <Container options={options}>
|
||||
<Raw>
|
||||
<div className="flex flex-row self-center flex-wrap justify-between">
|
||||
{options.cpu && <Cpu expanded={expanded} />}
|
||||
{options.memory && <Memory expanded={expanded} />}
|
||||
{options.cpu && <Cpu expanded={expanded} refresh={refresh} />}
|
||||
{options.memory && <Memory expanded={expanded} refresh={refresh} />}
|
||||
{Array.isArray(options.disk)
|
||||
? options.disk.map((disk) => <Disk key={disk} options={{ disk }} expanded={expanded} />)
|
||||
: options.disk && <Disk options={options} expanded={expanded} />}
|
||||
{options.cputemp && <CpuTemp expanded={expanded} units={units} />}
|
||||
{options.uptime && <Uptime />}
|
||||
? options.disk.map((disk) => <Disk key={disk} options={{ disk }} expanded={expanded} refresh={refresh} />)
|
||||
: options.disk && <Disk options={options} expanded={expanded} refresh={refresh} />}
|
||||
{options.cputemp && <CpuTemp expanded={expanded} units={units} refresh={refresh} />}
|
||||
{options.uptime && <Uptime refresh={refresh} />}
|
||||
</div>
|
||||
{options.label && (
|
||||
<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 Error from "../widget/error";
|
||||
|
||||
export default function Uptime() {
|
||||
export default function Uptime({ refresh = 1500 }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { data, error } = useSWR(`/api/widgets/resources?type=uptime`, {
|
||||
refreshInterval: 1500,
|
||||
refreshInterval: refresh,
|
||||
});
|
||||
|
||||
if (error || data?.error) {
|
||||
|
|
Loading…
Add table
Reference in a new issue