From e8acb0e1025a99d5bd51d24f4ef6b77aa66c212f Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sun, 29 Oct 2017 16:02:51 -0600 Subject: [PATCH] Use getValueAt() Signed-off-by: Travis Ralston --- src/components/structures/UserSettings.js | 30 ++++++++--------------- src/settings/SettingsStore.js | 22 +++++++++++++++++ 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 04b4626668..84b56e8a0f 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -126,16 +126,8 @@ const CRYPTO_SETTINGS_LABELS = [ // packaged up in a single directory, and/or located at the application layer. // But for now for expedience we just hardcode them here. const THEMES = [ - { - id: 'theme', - label: _td('Light theme'), - value: 'light', - }, - { - id: 'theme', - label: _td('Dark theme'), - value: 'dark', - }, + { label: _td('Light theme'), value: 'light' }, + { label: _td('Dark theme'), value: 'dark' }, ]; const IgnoredUser = React.createClass({ @@ -719,12 +711,11 @@ module.exports = React.createClass({ return
; }, @@ -734,23 +725,22 @@ module.exports = React.createClass({ // to rebind the onChange each time we render const onChange = (e) => { if (e.target.checked) { - SettingsStore.setValue(setting.id, null, "account", setting.value); + SettingsStore.setValue("theme", null, "account", setting.value); } dis.dispatch({ action: 'set_theme', value: setting.value, }); }; - return
- + -
; diff --git a/src/settings/SettingsStore.js b/src/settings/SettingsStore.js index 7370dc2a70..804b5df65c 100644 --- a/src/settings/SettingsStore.js +++ b/src/settings/SettingsStore.js @@ -291,6 +291,28 @@ export default class SettingsStore { return null; } + /** + * Gets a setting's value at the given level. + * @param {"device"|"room-device"|"room-account"|"account"|"room"} level The lvel to + * look at. + * @param {string} settingName The name of the setting to read. + * @param {String} roomId The room ID to read the setting value in, may be null. + * @return {*} The value, or null if not found. + */ + static getValueAt(level, settingName, roomId=null) { + // We specifically handle features as they have the possibility of being forced on. + if (SettingsStore.isFeature(settingName)) { + const configValue = SettingsStore._getFeatureState(settingName); + if (configValue === "enable") return true; + if (configValue === "disable") return false; + // else let it fall through the default process + } + + const handler = SettingsStore._getHandler(settingName, level); + if (!handler) return null; + return handler.getValue(settingName, roomId); + } + /** * Sets the value for a setting. The room ID is optional if the setting is not being * set for a particular room, otherwise it should be supplied. The value may be null