diff options
Diffstat (limited to 'modern/src/common/util')
-rw-r--r-- | modern/src/common/util/preferences.js | 18 |
1 files changed, 10 insertions, 8 deletions
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; |