Consolidate Themes into ThemeController. Remove hardcoded themes in view

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2019-08-11 03:43:34 +01:00
parent a9afdec24a
commit 916af736ad
2 changed files with 12 additions and 7 deletions

View file

@ -1,6 +1,7 @@
/* /*
Copyright 2019 New Vector Ltd Copyright 2019 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C. Copyright 2019 The Matrix.org Foundation C.I.C.
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -26,6 +27,7 @@ import LanguageDropdown from "../../../elements/LanguageDropdown";
import AccessibleButton from "../../../elements/AccessibleButton"; import AccessibleButton from "../../../elements/AccessibleButton";
import DeactivateAccountDialog from "../../../dialogs/DeactivateAccountDialog"; import DeactivateAccountDialog from "../../../dialogs/DeactivateAccountDialog";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import {SUPPORTED_THEMES} from "../../../../../settings/controllers/ThemeController";
const PlatformPeg = require("../../../../../PlatformPeg"); const PlatformPeg = require("../../../../../PlatformPeg");
const MatrixClientPeg = require("../../../../../MatrixClientPeg"); const MatrixClientPeg = require("../../../../../MatrixClientPeg");
const sdk = require('../../../../..'); const sdk = require('../../../../..');
@ -160,8 +162,9 @@ export default class GeneralUserSettingsTab extends React.Component {
<span className="mx_SettingsTab_subheading">{_t("Theme")}</span> <span className="mx_SettingsTab_subheading">{_t("Theme")}</span>
<Field id="theme" label={_t("Theme")} element="select" <Field id="theme" label={_t("Theme")} element="select"
value={this.state.theme} onChange={this._onThemeChange}> value={this.state.theme} onChange={this._onThemeChange}>
<option value="light">{_t("Light theme")}</option> {Object.entries(SUPPORTED_THEMES).map(([theme, text]) => {
<option value="dark">{_t("Dark theme")}</option> return <option key={theme} value={theme}>{_t(text)}</option>;
})}
</Field> </Field>
<SettingsFlag name="useCompactLayout" level={SettingLevel.ACCOUNT} /> <SettingsFlag name="useCompactLayout" level={SettingLevel.ACCOUNT} />
</div> </div>

View file

@ -1,5 +1,6 @@
/* /*
Copyright 2019 New Vector Ltd Copyright 2019 New Vector Ltd
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -15,16 +16,17 @@ limitations under the License.
*/ */
import SettingController from "./SettingController"; import SettingController from "./SettingController";
import {_td} from "../../languageHandler";
const SUPPORTED_THEMES = [ export const SUPPORTED_THEMES = {
"light", "light": _td("Light theme"),
"dark", "dark": _td("Dark theme"),
]; };
export default class ThemeController extends SettingController { export default class ThemeController extends SettingController {
getValueOverride(level, roomId, calculatedValue, calculatedAtLevel) { getValueOverride(level, roomId, calculatedValue, calculatedAtLevel) {
// Override in case some no longer supported theme is stored here // Override in case some no longer supported theme is stored here
if (!SUPPORTED_THEMES.includes(calculatedValue)) { if (!SUPPORTED_THEMES[calculatedValue]) {
return "light"; return "light";
} }