From dd09b5c7ed235088d86ba9898261d74228b825ee Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 28 Oct 2022 13:52:49 -0700 Subject: Support default map (fix #1002) --- modern/src/common/util/preferences.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'modern/src/common/util/preferences.js') 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; -- cgit v1.2.3