Add global refresh interval for all SWR calls

This commit is contained in:
Carlos Jiménez Delgado 2022-09-23 10:19:17 +02:00
parent 0e1e2bde22
commit 9995f2ab6c
6 changed files with 10 additions and 13 deletions

View file

@ -11,8 +11,9 @@ function Widget({ options }) {
const { t, i18n } = useTranslation();
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) {
return (

View file

@ -8,9 +8,7 @@ import UsageBar from "./usage-bar";
export default function Cpu({ expanded }) {
const { t } = useTranslation();
const { data, error } = useSWR(`/api/widgets/resources?type=cpu`, {
refreshInterval: 1500,
});
const { data, error } = useSWR(`/api/widgets/resources?type=cpu`);
if (error || data?.error) {
return (

View file

@ -8,9 +8,7 @@ import UsageBar from "./usage-bar";
export default function Disk({ options, expanded }) {
const { t } = useTranslation();
const { data, error } = useSWR(`/api/widgets/resources?type=disk&target=${options.disk}`, {
refreshInterval: 1500,
});
const { data, error } = useSWR(`/api/widgets/resources?type=disk&target=${options.disk}`);
if (error || data?.error) {
return (

View file

@ -8,9 +8,7 @@ import UsageBar from "./usage-bar";
export default function Memory({ expanded }) {
const { t } = useTranslation();
const { data, error } = useSWR(`/api/widgets/resources?type=memory`, {
refreshInterval: 1500,
});
const { data, error } = useSWR(`/api/widgets/resources?type=memory`);
if (error || data?.error) {
return (

View file

@ -11,8 +11,9 @@ function Widget({ options }) {
const { t, i18n } = useTranslation();
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) {
return (

View file

@ -14,6 +14,7 @@ function MyApp({ Component, pageProps }) {
return (
<SWRConfig
value={{
refreshInterval: 1500,
fetcher: (resource, init) => fetch(resource, init).then((res) => res.json()),
}}
>