fix JS error when saving a custom theme vector (#6734)
Этот коммит содержится в:
коммит произвёл
enahum
родитель
33eb77b757
Коммит
fe7e9d95b3
@@ -383,21 +383,18 @@ export function loadProfilesForDM() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveTheme(teamId, theme, onSuccess, onError) {
|
export function saveTheme(teamId, theme, cb) {
|
||||||
const currentUserId = UserStore.getCurrentId();
|
const currentUserId = UserStore.getCurrentId();
|
||||||
savePreferences(currentUserId, [{
|
const preference = [{
|
||||||
user_id: currentUserId,
|
user_id: currentUserId,
|
||||||
category: Preferences.CATEGORY_THEME,
|
category: Preferences.CATEGORY_THEME,
|
||||||
name: teamId,
|
name: teamId,
|
||||||
value: JSON.stringify(theme)
|
value: JSON.stringify(theme)
|
||||||
}])(dispatch, getState).then(
|
}];
|
||||||
(data) => {
|
|
||||||
if (data && onSuccess) {
|
savePreferences(currentUserId, preference)(dispatch, getState).then(
|
||||||
onThemeSaved(teamId, theme, onSuccess);
|
() => {
|
||||||
} else if (data == null && onError) {
|
onThemeSaved(teamId, theme, cb);
|
||||||
const serverError = getState().requests.users.savePreferences.error;
|
|
||||||
onError({id: serverError.server_error_id, ...serverError});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,6 +106,19 @@ const messages = defineMessages({
|
|||||||
const HEX_CODE_LENGTH = 7;
|
const HEX_CODE_LENGTH = 7;
|
||||||
|
|
||||||
class CustomThemeChooser extends React.Component {
|
class CustomThemeChooser extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.selectTheme = this.selectTheme.bind(this);
|
||||||
|
|
||||||
|
const copyTheme = Object.assign({}, this.props.theme);
|
||||||
|
delete copyTheme.type;
|
||||||
|
delete copyTheme.image;
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
copyTheme: JSON.stringify(copyTheme)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
$('.color-picker').colorpicker({
|
$('.color-picker').colorpicker({
|
||||||
format: 'hex'
|
format: 'hex'
|
||||||
@@ -144,9 +157,11 @@ class CustomThemeChooser extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const theme = this.props.theme;
|
const theme = this.props.theme;
|
||||||
theme[e.target.id] = e.color.toHex();
|
if (theme[e.target.id] !== e.color.toHex()) {
|
||||||
theme.type = 'custom';
|
theme[e.target.id] = e.color.toHex();
|
||||||
this.props.updateTheme(theme);
|
theme.type = 'custom';
|
||||||
|
this.props.updateTheme(theme);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pasteBoxChange = (e) => {
|
pasteBoxChange = (e) => {
|
||||||
@@ -169,6 +184,10 @@ class CustomThemeChooser extends React.Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
copyTheme: JSON.stringify(theme)
|
||||||
|
});
|
||||||
|
|
||||||
theme.type = 'custom';
|
theme.type = 'custom';
|
||||||
this.props.updateTheme(theme);
|
this.props.updateTheme(theme);
|
||||||
}
|
}
|
||||||
@@ -177,6 +196,12 @@ class CustomThemeChooser extends React.Component {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectTheme() {
|
||||||
|
const textarea = this.refs.textarea;
|
||||||
|
textarea.focus();
|
||||||
|
textarea.setSelectionRange(0, this.state.copyTheme.length);
|
||||||
|
}
|
||||||
|
|
||||||
toggleSidebarStyles = (e) => {
|
toggleSidebarStyles = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@@ -346,10 +371,6 @@ class CustomThemeChooser extends React.Component {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const copyTheme = Object.assign({}, theme);
|
|
||||||
delete copyTheme.type;
|
|
||||||
delete copyTheme.image;
|
|
||||||
|
|
||||||
const pasteBox = (
|
const pasteBox = (
|
||||||
<div className='col-sm-12'>
|
<div className='col-sm-12'>
|
||||||
<label className='custom-label'>
|
<label className='custom-label'>
|
||||||
@@ -359,10 +380,12 @@ class CustomThemeChooser extends React.Component {
|
|||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<textarea
|
<textarea
|
||||||
|
ref='textarea'
|
||||||
className='form-control'
|
className='form-control'
|
||||||
value={JSON.stringify(copyTheme)}
|
value={this.state.copyTheme}
|
||||||
onPaste={this.pasteBoxChange}
|
onPaste={this.pasteBoxChange}
|
||||||
onChange={this.onChangeHandle}
|
onChange={this.onChangeHandle}
|
||||||
|
onClick={this.selectTheme}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -125,11 +125,6 @@ export default class ThemeSetting extends React.Component {
|
|||||||
this.originalTheme = Object.assign({}, this.state.theme);
|
this.originalTheme = Object.assign({}, this.state.theme);
|
||||||
this.scrollToTop();
|
this.scrollToTop();
|
||||||
this.props.updateSection('');
|
this.props.updateSection('');
|
||||||
},
|
|
||||||
(err) => {
|
|
||||||
var state = this.getStateFromStores();
|
|
||||||
state.serverError = err;
|
|
||||||
this.setState(state);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user