From f39681596ea7212a3c66c4b98c57fa112314f388 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Sat, 4 Mar 2017 12:53:26 -0500 Subject: Don't allow name-value pairs in theme vector be localized (#5623) --- .../user_settings/custom_theme_chooser.jsx | 48 +++++----------------- 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/webapp/components/user_settings/custom_theme_chooser.jsx b/webapp/components/user_settings/custom_theme_chooser.jsx index a8819f846..a39f9967b 100644 --- a/webapp/components/user_settings/custom_theme_chooser.jsx +++ b/webapp/components/user_settings/custom_theme_chooser.jsx @@ -156,21 +156,6 @@ class CustomThemeChooser extends React.Component { this.props.updateTheme(theme); } - getColors(text) { - const colorsText = text.split(','); - return colorsText.map((colorText) => { - const trimText = colorText.trim(); - const keyValue = trimText.split(':'); - const color = keyValue[1].trim() || trimText; - if (Utils.isHexColor(color)) { - return color; - } else if (keyValue[0] === 'Code Theme') { - return keyValue[1].trim(); - } - return '#FFF'; - }); - } - pasteBoxChange(e) { let text = ''; @@ -184,20 +169,14 @@ class CustomThemeChooser extends React.Component { return; } - // theme vectors are currently represented as a number of hex color codes followed by the code theme - const colors = this.getColors(text); - const theme = {type: 'custom'}; - let index = 0; - Constants.THEME_ELEMENTS.forEach((element) => { - if (index < colors.length - 1) { - if (Utils.isHexColor(colors[index])) { - theme[element.id] = colors[index]; - } - } - index++; - }); - theme.codeTheme = colors[colors.length - 1]; + let theme; + try { + theme = JSON.parse(text); + } catch (err) { + return; + } + theme.type = 'custom'; this.props.updateTheme(theme); } @@ -229,7 +208,6 @@ class CustomThemeChooser extends React.Component { const sidebarElements = []; const centerChannelElements = []; const linkAndButtonElements = []; - let colors = ''; Constants.THEME_ELEMENTS.forEach((element, index) => { if (element.id === 'codeTheme') { const codeThemeOptions = []; @@ -313,8 +291,6 @@ class CustomThemeChooser extends React.Component { ); - - colors += formatMessage(messages[element.id]) + ': ' + theme[element.id] + ', '; } else if (element.group === 'sidebarElements') { sidebarElements.push(
); - - colors += formatMessage(messages[element.id]) + ': ' + theme[element.id] + ', '; } else { linkAndButtonElements.push(
); - - colors += formatMessage(messages[element.id]) + ': ' + theme[element.id] + ', '; } }); - colors += 'Code Theme: ' + theme.codeTheme; + const copyTheme = Object.assign({}, theme); + delete copyTheme.type; + delete copyTheme.image; const pasteBox = (
@@ -374,7 +348,7 @@ class CustomThemeChooser extends React.Component {