aboutsummaryrefslogtreecommitdiff
path: root/modern
diff options
context:
space:
mode:
authorMatjaž Črnko <m.crnko@txt.si>2023-11-06 15:48:27 +0100
committerMatjaž Črnko <m.crnko@txt.si>2023-11-06 15:48:27 +0100
commit41b513e0245e5c354508ef26e1a4ec89e67e7598 (patch)
tree322ba944b350e1a5e60e4b57d90a1ee19a54a361 /modern
parentf81bf48cb9cd3541bf8f111770fdd42c4d8e0955 (diff)
downloadtrackermap-web-41b513e0245e5c354508ef26e1a4ec89e67e7598.tar.gz
trackermap-web-41b513e0245e5c354508ef26e1a4ec89e67e7598.tar.bz2
trackermap-web-41b513e0245e5c354508ef26e1a4ec89e67e7598.zip
PWA: use only server attributes for serviceWorkerUpdateInterval
Diffstat (limited to 'modern')
-rw-r--r--modern/src/UpdateController.tsx4
-rw-r--r--modern/src/common/util/preferences.js7
2 files changed, 9 insertions, 2 deletions
diff --git a/modern/src/UpdateController.tsx b/modern/src/UpdateController.tsx
index 0f1b800b..991ea346 100644
--- a/modern/src/UpdateController.tsx
+++ b/modern/src/UpdateController.tsx
@@ -2,14 +2,14 @@ import { Snackbar, IconButton } from '@mui/material';
import RefreshIcon from '@mui/icons-material/Refresh';
import React from 'react'
import { useTranslation } from './common/components/LocalizationProvider';
-import { useAttributePreference } from './common/util/preferences';
+import { useServerAttributePreference } from './common/util/preferences';
import { useRegisterSW } from 'virtual:pwa-register/react'
// Based on https://vite-pwa-org.netlify.app/frameworks/react.html
function UpdateController() {
const t = useTranslation();
- const serviceWorkerUpdateInterval = useAttributePreference('serviceWorkerUpdateInterval', 3600000);
+ const serviceWorkerUpdateInterval = useServerAttributePreference('serviceWorkerUpdateInterval', 3600000);
const {
needRefresh: [needRefresh],
diff --git a/modern/src/common/util/preferences.js b/modern/src/common/util/preferences.js
index 229b6f17..0604d848 100644
--- a/modern/src/common/util/preferences.js
+++ b/modern/src/common/util/preferences.js
@@ -39,3 +39,10 @@ export const useAttributePreference = (key, defaultValue) => useSelector((state)
}
return defaultValue;
});
+
+export const useServerAttributePreference = (key, defaultValue) => useSelector((state) => {
+ if (containsProperty(state.session.server.attributes, key)) {
+ return state.session.server.attributes[key];
+ }
+ return defaultValue;
+}); \ No newline at end of file