Add global refresh interval for all SWR calls
This commit is contained in:
parent
0e1e2bde22
commit
9995f2ab6c
@ -11,8 +11,9 @@ function Widget({ options }) {
|
|||||||
const { t, i18n } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
|
|
||||||
const { data, error } = useSWR(
|
const { data, error } = useSWR(
|
||||||
`/api/widgets/openweathermap?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`
|
`/api/widgets/openweathermap?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`, {
|
||||||
);
|
refreshInterval: null
|
||||||
|
});
|
||||||
|
|
||||||
if (error || data?.cod === 401 || data?.error) {
|
if (error || data?.cod === 401 || data?.error) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -8,9 +8,7 @@ import UsageBar from "./usage-bar";
|
|||||||
export default function Cpu({ expanded }) {
|
export default function Cpu({ expanded }) {
|
||||||
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,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (error || data?.error) {
|
if (error || data?.error) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -8,9 +8,7 @@ import UsageBar from "./usage-bar";
|
|||||||
export default function Disk({ options, expanded }) {
|
export default function Disk({ options, expanded }) {
|
||||||
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,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (error || data?.error) {
|
if (error || data?.error) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -8,9 +8,7 @@ import UsageBar from "./usage-bar";
|
|||||||
export default function Memory({ expanded }) {
|
export default function Memory({ expanded }) {
|
||||||
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,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (error || data?.error) {
|
if (error || data?.error) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -11,8 +11,9 @@ function Widget({ options }) {
|
|||||||
const { t, i18n } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
|
|
||||||
const { data, error } = useSWR(
|
const { data, error } = useSWR(
|
||||||
`/api/widgets/weather?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`
|
`/api/widgets/weather?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`, {
|
||||||
);
|
refreshInterval: null
|
||||||
|
});
|
||||||
|
|
||||||
if (error || data?.error) {
|
if (error || data?.error) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -14,6 +14,7 @@ function MyApp({ Component, pageProps }) {
|
|||||||
return (
|
return (
|
||||||
<SWRConfig
|
<SWRConfig
|
||||||
value={{
|
value={{
|
||||||
|
refreshInterval: 1500,
|
||||||
fetcher: (resource, init) => fetch(resource, init).then((res) => res.json()),
|
fetcher: (resource, init) => fetch(resource, init).then((res) => res.json()),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user