summaryrefslogtreecommitdiffstats
path: root/web/react/stores/preference_store.jsx
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-12-16 09:10:24 -0500
committerChristopher Speller <crspeller@gmail.com>2015-12-16 09:10:24 -0500
commit34e0ac00e81f5e8912e341e4fece3b38dbb6cf76 (patch)
tree1e67c2ce24f447e26d4abc63df28a3828c919e60 /web/react/stores/preference_store.jsx
parent3e418a100a3a491ebff7ba72ac003dd06752a30a (diff)
parent23af326af20cffef59ac8859e7def38f744a452b (diff)
downloadchat-34e0ac00e81f5e8912e341e4fece3b38dbb6cf76.tar.gz
chat-34e0ac00e81f5e8912e341e4fece3b38dbb6cf76.tar.bz2
chat-34e0ac00e81f5e8912e341e4fece3b38dbb6cf76.zip
Merge pull request #1733 from hmhealey/plt1437
PLT-1437 PreferenceStore api changes and fixing CreatePost warning
Diffstat (limited to 'web/react/stores/preference_store.jsx')
-rw-r--r--web/react/stores/preference_store.jsx49
1 files changed, 46 insertions, 3 deletions
diff --git a/web/react/stores/preference_store.jsx b/web/react/stores/preference_store.jsx
index 543129aca..79eab4fe1 100644
--- a/web/react/stores/preference_store.jsx
+++ b/web/react/stores/preference_store.jsx
@@ -23,8 +23,11 @@ class PreferenceStoreClass extends EventEmitter {
super();
this.getAllPreferences = this.getAllPreferences.bind(this);
+ this.get = this.get.bind(this);
+ this.getBool = this.getBool.bind(this);
+ this.getInt = this.getInt.bind(this);
this.getPreference = this.getPreference.bind(this);
- this.getPreferences = this.getPreferences.bind(this);
+ this.getCategory = this.getCategory.bind(this);
this.getPreferencesWhere = this.getPreferencesWhere.bind(this);
this.setAllPreferences = this.setAllPreferences.bind(this);
this.setPreference = this.setPreference.bind(this);
@@ -41,11 +44,51 @@ class PreferenceStoreClass extends EventEmitter {
return new Map(BrowserStore.getItem('preferences', []));
}
- getPreference(category, name, defaultValue = '') {
+ get(category, name, defaultValue = '') {
+ const preference = this.getAllPreferences().get(getPreferenceKey(category, name));
+
+ if (!preference) {
+ return defaultValue;
+ }
+
+ return preference.value || defaultValue;
+ }
+
+ getBool(category, name, defaultValue = false) {
+ const preference = this.getAllPreferences().get(getPreferenceKey(category, name));
+
+ if (!preference) {
+ return defaultValue;
+ }
+
+ // prevent a non-false default value from being returned instead of an actual false value
+ if (preference.value === 'false') {
+ return false;
+ }
+
+ return (preference.value !== 'false') || defaultValue;
+ }
+
+ getInt(category, name, defaultValue = 0) {
+ const preference = this.getAllPreferences().get(getPreferenceKey(category, name));
+
+ if (!preference) {
+ return defaultValue;
+ }
+
+ // prevent a non-zero default value from being returned instead of an actual 0 value
+ if (preference.value === '0') {
+ return 0;
+ }
+
+ return parseInt(preference.value, 10) || defaultValue;
+ }
+
+ getPreference(category, name, defaultValue = {}) {
return this.getAllPreferences().get(getPreferenceKey(category, name)) || defaultValue;
}
- getPreferences(category) {
+ getCategory(category) {
return this.getPreferencesWhere((preference) => (preference.category === category));
}