save wordlist to the server

This commit is contained in:
Riley Davis
2016-12-19 15:03:18 -07:00
parent 7742dbf9a2
commit 86c74d69c7
5 changed files with 41 additions and 16 deletions
@@ -10,6 +10,8 @@ export const SAVE_SETTINGS_LOADING = 'SAVE_SETTINGS_LOADING';
export const SAVE_SETTINGS_SUCCESS = 'SAVE_SETTINGS_SUCCESS';
export const SAVE_SETTINGS_FAILED = 'SAVE_SETTINGS_FAILED';
export const WORDLIST_UPDATED = 'WORDLIST_UPDATED';
export const fetchSettings = () => dispatch => {
dispatch({type: SETTINGS_LOADING});
coralApi('/settings')
@@ -21,12 +23,19 @@ export const fetchSettings = () => dispatch => {
});
};
// for updating top-level settings
export const updateSettings = settings => {
return {type: SETTINGS_UPDATED, settings};
};
// this is a nested property, so it needs a special action.
export const updateWordlist = (listName, list) => {
return {type: WORDLIST_UPDATED, listName, list};
};
export const saveSettingsToServer = () => (dispatch, getState) => {
let settings = getState().settings.toJS().settings;
console.log('about to save settings to server', settings);
if (settings.charCount) {
settings.charCount = parseInt(settings.charCount);
}
@@ -1,6 +1,11 @@
import React from 'react';
import {connect} from 'react-redux';
import {fetchSettings, updateSettings, saveSettingsToServer} from '../../actions/settings';
import {
fetchSettings,
updateSettings,
saveSettingsToServer,
updateWordlist,
} from '../../actions/settings';
import {
List,
ListItem,
@@ -21,7 +26,8 @@ class Configure extends React.Component {
this.state = {
activeSection: 'comments',
wordlist: [],
banned: [],
suspect: [],
changed: false,
errors: {}
};
@@ -36,8 +42,10 @@ class Configure extends React.Component {
|| !this.props.settings.wordlist)
&& newProps.settings.wordlist
&& newProps.settings.wordlist.length !== 0 ) {
console.log('wordlist?', newProps.settings.wordlist);
this.setState({wordlist: newProps.settings.wordlist.banned.join(', ')});
this.setState({
banned: newProps.settings.wordlist.banned.join(', '),
suspect: newProps.settings.wordlist.suspect.join(', ')
});
}
}
@@ -50,15 +58,11 @@ class Configure extends React.Component {
this.setState({activeSection});
}
onChangeWordlist = (event) => {
onChangeWordlist = (event, list) => {
event.preventDefault();
const newlist = event.target.value;
this.setState({wordlist: newlist.toLowerCase(), changed: true});
this.props.dispatch(updateSettings({
wordlist: newlist.toLowerCase()
.split(',')
.map((word) => word.trim())
}));
const newlist = event.target.value.toLowerCase();
this.setState({[list]: newlist, changed: true});
this.props.dispatch(updateWordlist(list, newlist.split(',').map(word => word.trim()) ));
}
onSettingUpdate = (setting) => {
@@ -90,7 +94,8 @@ class Configure extends React.Component {
return <EmbedLink title={pageTitle} />;
case 'wordlist':
return <Wordlist
bannedWords={this.state.wordlist}
bannedWords={this.state.banned}
suspectWords={this.state.suspect}
onChangeWordlist={this.onChangeWordlist}/>;
}
}
@@ -16,7 +16,7 @@ const Wordlist = ({suspectWords, bannedWords, onChangeWordlist}) => (
rows={5}
type='text'
className={styles.wordlistInput}
onChange={onChangeWordlist}
onChange={e => onChangeWordlist(e, 'banned')}
value={bannedWords} />
</Card>
<h3>{lang.t('configure.suspect-words-title')}</h3>
@@ -27,7 +27,7 @@ const Wordlist = ({suspectWords, bannedWords, onChangeWordlist}) => (
rows={5}
type='text'
className={styles.wordlistInput}
onChange={() => {}}
onChange={e => onChangeWordlist(e, 'suspect')}
value={suspectWords} />
</Card>
</div>
@@ -18,16 +18,27 @@ export default (state = initialState, action) => {
case types.SAVE_SETTINGS_LOADING: return state.set('fetchingSettings', true).set('saveSettingsError', null);
case types.SAVE_SETTINGS_SUCCESS: return saveComplete(state, action);
case types.SAVE_SETTINGS_FAILED: return settingsSaveFailed(state, action);
case types.WORDLIST_UPDATED: return updateWordlist(state, action);
default: return state;
}
};
const updateSettings = (state, action) => {
console.log('updateSettings', state, action);
const s = state.set('fetchingSettings', false).set('fetchSettingsError', null);
const settings = s.get('settings').merge(action.settings);
return s.set('settings', settings);
};
const updateWordlist = (state, action) => {
const wordlist = state
.get('settings')
.get('wordlist')
.merge({[action.listName]: action.list});
const settings = state.get('settings').merge({wordlist});
return state.set('settings', settings);
};
const saveComplete = (state, action) => {
const s = state.set('fetchingSettings', false).set('saveSettingsError', null);
const settings = s.get('settings').merge(action.settings);
+1 -1
View File
@@ -117,7 +117,7 @@
"include-text": "Incluir tu texto aqui.",
"comment-settings": "Configuración de Comentarios",
"embed-comment-stream": "Colocar Hilo de Comentarios",
"wordlist": "Lista de palabras no permitidas",
"wordlist": "Palabras Suspendidas y Suspechosas",
"banned-word-header": "Escribir las palabras no permitidas",
"banned-word-text": "Comentarios que contengan estas palabras o frases, no separadas por comas y en mayusculas o minusuculas, serán automaticamente separadas de los comentarios publicados.",
"suspect-word-header": "",