Merge pull request #493 from coralproject/143520971-stream-settings

Configure stream settings
This commit is contained in:
Gabriela Rodríguez Berón
2017-04-17 12:45:34 -07:00
committed by GitHub
3 changed files with 25 additions and 20 deletions
@@ -7,7 +7,7 @@ import I18n from 'coral-framework/modules/i18n/i18n';
import translations from '../translations.json'; import translations from '../translations.json';
const lang = new I18n(translations); const lang = new I18n(translations);
export default ({handleChange, handleApply, changed, updateQuestionBoxContent, ...props}) => ( export default ({handleChange, handleApply, changed, ...props}) => (
<form onSubmit={handleApply}> <form onSubmit={handleApply}>
<div className={styles.wrapper}> <div className={styles.wrapper}>
<div className={styles.container}> <div className={styles.container}>
@@ -38,9 +38,9 @@ export default ({handleChange, handleApply, changed, updateQuestionBoxContent, .
<Checkbox <Checkbox
className={styles.checkbox} className={styles.checkbox}
cStyle={changed ? 'green' : 'darkGrey'} cStyle={changed ? 'green' : 'darkGrey'}
name="premodLinks" name="plinksenable"
onChange={handleChange} onChange={handleChange}
defaultChecked={props.premodLinks} defaultChecked={props.premodLinksEnable}
info={{ info={{
title: lang.t('configureCommentStream.enablePremodLinks'), title: lang.t('configureCommentStream.enablePremodLinks'),
description: lang.t('configureCommentStream.enablePremodLinksDescription') description: lang.t('configureCommentStream.enablePremodLinksDescription')
@@ -57,11 +57,10 @@ export default ({handleChange, handleApply, changed, updateQuestionBoxContent, .
title: lang.t('configureCommentStream.enableQuestionBox'), title: lang.t('configureCommentStream.enableQuestionBox'),
description: lang.t('configureCommentStream.enableQuestionBoxDescription') description: lang.t('configureCommentStream.enableQuestionBoxDescription')
}} /> }} />
<div className={`${props.questionBoxEnable ? null : styles.hidden}`} > <div className={`${props.questionBoxEnable ? null : styles.hidden}`} >
<TextField <TextField
id="qboxcontent" id="qboxcontent"
onChange={updateQuestionBoxContent} onChange={handleChange}
rows={3} rows={3}
value={props.questionBoxContent} value={props.questionBoxContent}
label={lang.t('configureCommentStream.includeQuestionHere')} label={lang.t('configureCommentStream.includeQuestionHere')}
@@ -16,13 +16,13 @@ class ConfigureStreamContainer extends Component {
this.state = { this.state = {
changed: false, changed: false,
dirtySettings: props.asset.settings,
closedAt: (props.asset.closedAt === null ? 'open' : 'closed') closedAt: (props.asset.closedAt === null ? 'open' : 'closed')
}; };
this.toggleStatus = this.toggleStatus.bind(this); this.toggleStatus = this.toggleStatus.bind(this);
this.handleChange = this.handleChange.bind(this); this.handleChange = this.handleChange.bind(this);
this.handleApply = this.handleApply.bind(this); this.handleApply = this.handleApply.bind(this);
this.updateQuestionBoxContent = this.updateQuestionBoxContent.bind(this);
} }
handleApply (e) { handleApply (e) {
@@ -32,7 +32,7 @@ class ConfigureStreamContainer extends Component {
const questionBoxEnable = elements.qboxenable.checked; const questionBoxEnable = elements.qboxenable.checked;
const questionBoxContent = elements.qboxcontent.value; const questionBoxContent = elements.qboxcontent.value;
const premodLinksEnable = elements.premodLinks.checked; const premodLinksEnable = elements.plinksenable.checked;
const {changed} = this.state; const {changed} = this.state;
const newConfig = { const newConfig = {
@@ -49,23 +49,29 @@ class ConfigureStreamContainer extends Component {
changed: false changed: false
}); });
}, 300); }, 300);
// this.props.loadAsset(this.props.data.asset);
} }
} }
handleChange (e) { handleChange (e) {
// TODO: Dont directly manipulate state and make state change immutable.
if (e.target && e.target.id === 'qboxenable') { if (e.target && e.target.id === 'qboxenable') {
this.props.asset.settings.questionBoxEnable = e.target.checked; this.state.dirtySettings.questionBoxEnable = e.target.checked;
} }
if (e.target && e.target.id === 'qboxcontent') {
this.state.dirtySettings.questionBoxContent = e.target.value;
}
if (e.target && e.target.id === 'plinksenable') {
this.state.dirtySettings.premodLinksEnable = e.target.value;
}
this.setState({ this.setState({
changed: true changed: true
}); });
} }
updateQuestionBoxContent(e) {
this.props.asset.settings.questionBoxContent = e.target.value;
this.handleChange(e);
}
toggleStatus () { toggleStatus () {
// update the closedAt status for the asset // update the closedAt status for the asset
@@ -85,10 +91,10 @@ class ConfigureStreamContainer extends Component {
} }
render () { render () {
const {settings} = this.props.asset; const {dirtySettings} = this.state;
const premod = dirtySettings.moderation === 'PRE';
const {closedAt} = this.state; const {closedAt} = this.state;
const premod = settings.moderation === 'PRE'; const closedTimeout = dirtySettings.closedTimeout;
const closedTimeout = settings.closedTimeout;
return ( return (
<div> <div>
@@ -96,11 +102,10 @@ class ConfigureStreamContainer extends Component {
handleChange={this.handleChange} handleChange={this.handleChange}
handleApply={this.handleApply} handleApply={this.handleApply}
changed={this.state.changed} changed={this.state.changed}
premodLinks={settings.premodLinks} premodLinksEnable={dirtySettings.premodLinksEnable}
premod={premod} premod={premod}
updateQuestionBoxContent={this.updateQuestionBoxContent} questionBoxEnable={dirtySettings.questionBoxEnable}
questionBoxEnable={settings.questionBoxEnable} questionBoxContent={dirtySettings.questionBoxContent}
questionBoxContent={settings.questionBoxContent}
/> />
<hr /> <hr />
<h3>{closedAt === 'open' ? 'Close' : 'Open'} Comment Stream</h3> <h3>{closedAt === 'open' ? 'Close' : 'Open'} Comment Stream</h3>
@@ -28,6 +28,7 @@ query AssetQuery($asset_id: ID, $asset_url: String, $comment_id: ID!, $has_comme
moderation moderation
infoBoxEnable infoBoxEnable
infoBoxContent infoBoxContent
premodLinksEnable
questionBoxEnable questionBoxEnable
questionBoxContent questionBoxContent
closeTimeout closeTimeout