mirror of
https://github.com/karl0ss/homepage.git
synced 2025-04-29 12:03:41 +01:00
Add custom refresh rate setting to resources
Simplify resources refresh variable, enforce minimum Add custom refresh rate to uptime Add custom refresh rate to memory Add custom refresh rate to disk Add custom refresh rate to cputemp Add custom refresh rate to CPU
This commit is contained in:
parent
1560bb7762
commit
454d8d03c2
@ -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…
x
Reference in New Issue
Block a user