From 6aeca7b8533806c6d859339c1dfd0be0c5eda424 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 6 Mar 2020 17:43:10 -0700 Subject: [PATCH] UX polish for custom themes --- res/css/_common.scss | 7 ++- .../tabs/user/GeneralUserSettingsTab.js | 59 ++++++++++++------- src/i18n/strings/en_EN.json | 1 + 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/res/css/_common.scss b/res/css/_common.scss index e062e0bd73..a4ef603242 100644 --- a/res/css/_common.scss +++ b/res/css/_common.scss @@ -42,10 +42,15 @@ pre, code { font-size: 100% !important; } -.error, .warning { +.error, .warning, +.text-error, .text-warning { color: $warning-color; } +.text-success { + color: $accent-color; +} + b { // On Firefox, the default weight for `` is `bolder` which results in no bold // effect since we only have specific weights of our fonts available. diff --git a/src/components/views/settings/tabs/user/GeneralUserSettingsTab.js b/src/components/views/settings/tabs/user/GeneralUserSettingsTab.js index 7af9aae146..d0509644b5 100644 --- a/src/components/views/settings/tabs/user/GeneralUserSettingsTab.js +++ b/src/components/views/settings/tabs/user/GeneralUserSettingsTab.js @@ -62,7 +62,7 @@ export default class GeneralUserSettingsTab extends React.Component { msisdns: [], ...this._calculateThemeState(), customThemeUrl: "", - customThemeError: "", + customThemeMessage: {isError: false, text: ""}, }; this.dispatcherRef = dis.register(this._onAction); @@ -281,22 +281,30 @@ export default class GeneralUserSettingsTab extends React.Component { if (!currentThemes) currentThemes = []; currentThemes = currentThemes.map(c => c); // cheap clone + if (this._themeTimer) { + clearTimeout(this._themeTimer); + } + try { const r = await fetch(this.state.customThemeUrl); const themeInfo = await r.json(); if (!themeInfo || typeof(themeInfo['name']) !== 'string' || typeof(themeInfo['colors']) !== 'object') { - console.log(themeInfo); - this.setState({customThemeError: _t("Invalid theme schema.")}); + this.setState({customThemeMessage: {text: _t("Invalid theme schema."), isError: true}}); return; } currentThemes.push(themeInfo); } catch (e) { console.error(e); - this.setState({customThemeError: _t("Error downloading theme information.")}); + this.setState({customThemeMessage: {text: _t("Error downloading theme information."), isError: true}}); + return; // Don't continue on error } await SettingsStore.setValue("custom_themes", null, SettingLevel.ACCOUNT, currentThemes); - this.setState({customThemeUrl: "", customThemeError: ""}); + this.setState({customThemeUrl: "", customThemeMessage: {text: _t("Theme added!"), isError: false}}); + + this._themeTimer = setTimeout(() => { + this.setState({customThemeMessage: {text: "", isError: false}}); + }, 3000); }; _onCustomThemeChange = (e) => { @@ -400,22 +408,33 @@ export default class GeneralUserSettingsTab extends React.Component { let customThemeForm; if (SettingsStore.isFeatureEnabled("feature_custom_themes")) { + let messageElement = null; + if (this.state.customThemeMessage.text) { + if (this.state.customThemeMessage.isError) { + messageElement =
{this.state.customThemeMessage.text}
; + } else { + messageElement =
{this.state.customThemeMessage.text}
; + } + } customThemeForm = ( -
- -
{this.state.customThemeError}
- {_t("Add theme")} - +
+
+ + {_t("Add theme")} + {messageElement} + +
); } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 57e4bcb1cc..6463c7474f 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -706,6 +706,7 @@ "Your password was successfully changed. You will not receive push notifications on other sessions until you log back in to them": "Your password was successfully changed. You will not receive push notifications on other sessions until you log back in to them", "Invalid theme schema.": "Invalid theme schema.", "Error downloading theme information.": "Error downloading theme information.", + "Theme added!": "Theme added!", "Profile": "Profile", "Email addresses": "Email addresses", "Phone numbers": "Phone numbers",