aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatjaž Črnko <m.crnko@txt.si>2023-11-06 16:27:26 +0100
committerMatjaž Črnko <m.crnko@txt.si>2023-11-06 16:27:26 +0100
commit85d5322a78332175fd870e588469fc9653fa8257 (patch)
tree560ecde1021d6ed99e51dee688ee20cbd529da1a
parent93b8ec8c43bccc010270926658dcd073c6608f38 (diff)
downloadtrackermap-web-85d5322a78332175fd870e588469fc9653fa8257.tar.gz
trackermap-web-85d5322a78332175fd870e588469fc9653fa8257.tar.bz2
trackermap-web-85d5322a78332175fd870e588469fc9653fa8257.zip
PWA: remove useServerAttributePreference and shorten the line/variable a bit
-rw-r--r--modern/src/UpdateController.tsx8
-rw-r--r--modern/src/common/util/preferences.js7
2 files changed, 4 insertions, 11 deletions
diff --git a/modern/src/UpdateController.tsx b/modern/src/UpdateController.tsx
index 991ea346..0b2b7985 100644
--- a/modern/src/UpdateController.tsx
+++ b/modern/src/UpdateController.tsx
@@ -1,22 +1,22 @@
import { Snackbar, IconButton } from '@mui/material';
import RefreshIcon from '@mui/icons-material/Refresh';
import React from 'react'
+import { useSelector } from 'react-redux';
import { useTranslation } from './common/components/LocalizationProvider';
-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 = useServerAttributePreference('serviceWorkerUpdateInterval', 3600000);
+ const swUpdateInterval = useSelector((state) => state.session.server.attributes.serviceWorkerUpdateInterval || 3600000);
const {
needRefresh: [needRefresh],
updateServiceWorker,
} = useRegisterSW({
onRegisteredSW(swUrl, swRegistration) {
- if (serviceWorkerUpdateInterval > 0 && swRegistration) {
+ if (swUpdateInterval > 0 && swRegistration) {
setInterval(async () => {
if (!(!swRegistration.installing && navigator)) {
return;
@@ -37,7 +37,7 @@ function UpdateController() {
if (newSW?.status === 200) {
await swRegistration.update();
}
- }, serviceWorkerUpdateInterval);
+ }, swUpdateInterval);
}
}
});
diff --git a/modern/src/common/util/preferences.js b/modern/src/common/util/preferences.js
index 54dfbada..229b6f17 100644
--- a/modern/src/common/util/preferences.js
+++ b/modern/src/common/util/preferences.js
@@ -39,10 +39,3 @@ 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;
-});