aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-10-28 13:52:49 -0700
committerAnton Tananaev <anton@traccar.org>2022-10-28 13:52:49 -0700
commitdd09b5c7ed235088d86ba9898261d74228b825ee (patch)
treea0992db59b7c4d5606ef5327a2692c57ead883e7 /modern/src/common
parentfac80024e0956d543b762296e0ee49cd72035b93 (diff)
downloadtrackermap-web-dd09b5c7ed235088d86ba9898261d74228b825ee.tar.gz
trackermap-web-dd09b5c7ed235088d86ba9898261d74228b825ee.tar.bz2
trackermap-web-dd09b5c7ed235088d86ba9898261d74228b825ee.zip
Support default map (fix #1002)
Diffstat (limited to 'modern/src/common')
-rw-r--r--modern/src/common/attributes/useCommonUserAttributes.js4
-rw-r--r--modern/src/common/util/preferences.js18
2 files changed, 10 insertions, 12 deletions
diff --git a/modern/src/common/attributes/useCommonUserAttributes.js b/modern/src/common/attributes/useCommonUserAttributes.js
index 845ab799..cef6daf8 100644
--- a/modern/src/common/attributes/useCommonUserAttributes.js
+++ b/modern/src/common/attributes/useCommonUserAttributes.js
@@ -25,10 +25,6 @@ export default (t) => useMemo(() => ({
name: t('mapActive'),
type: 'string',
},
- selectedMapStyle: {
- name: t('mapDefault'),
- type: 'string',
- },
devicePrimary: {
name: t('devicePrimaryInfo'),
type: 'string',
diff --git a/modern/src/common/util/preferences.js b/modern/src/common/util/preferences.js
index fb8bb4f2..229b6f17 100644
--- a/modern/src/common/util/preferences.js
+++ b/modern/src/common/util/preferences.js
@@ -1,19 +1,21 @@
import { useSelector } from 'react-redux';
+const containsProperty = (object, key) => object.hasOwnProperty(key) && object[key] !== null;
+
export const usePreference = (key, defaultValue) => useSelector((state) => {
if (state.session.server.forceSettings) {
- if (state.session.server.hasOwnProperty(key)) {
+ if (containsProperty(state.session.server, key)) {
return state.session.server[key];
}
- if (state.session.user.hasOwnProperty(key)) {
+ if (containsProperty(state.session.user, key)) {
return state.session.user[key];
}
return defaultValue;
}
- if (state.session.user.hasOwnProperty(key)) {
+ if (containsProperty(state.session.user, key)) {
return state.session.user[key];
}
- if (state.session.server.hasOwnProperty(key)) {
+ if (containsProperty(state.session.server, key)) {
return state.session.server[key];
}
return defaultValue;
@@ -21,18 +23,18 @@ export const usePreference = (key, defaultValue) => useSelector((state) => {
export const useAttributePreference = (key, defaultValue) => useSelector((state) => {
if (state.session.server.forceSettings) {
- if (state.session.server.attributes.hasOwnProperty(key)) {
+ if (containsProperty(state.session.server.attributes, key)) {
return state.session.server.attributes[key];
}
- if (state.session.user.attributes.hasOwnProperty(key)) {
+ if (containsProperty(state.session.user.attributes, key)) {
return state.session.user.attributes[key];
}
return defaultValue;
}
- if (state.session.user.attributes.hasOwnProperty(key)) {
+ if (containsProperty(state.session.user.attributes, key)) {
return state.session.user.attributes[key];
}
- if (state.session.server.attributes.hasOwnProperty(key)) {
+ if (containsProperty(state.session.server.attributes, key)) {
return state.session.server.attributes[key];
}
return defaultValue;