From ae3d1c1819e674d182d66431854422e79f64a7d1 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Fri, 6 Oct 2017 22:17:51 +0700 Subject: [PATCH] Turn StreamSettings to container --- .../routes/Configure/components/Configure.js | 21 +- .../routes/Configure/components/Domainlist.js | 6 + .../routes/Configure/components/EmbedLink.js | 6 +- .../Configure/components/StreamSettings.js | 385 ++++++++++-------- .../routes/Configure/components/Wordlist.js | 7 + .../routes/Configure/containers/Configure.js | 28 +- .../Configure/containers/StreamSettings.js | 45 ++ 7 files changed, 304 insertions(+), 194 deletions(-) create mode 100644 client/coral-admin/src/routes/Configure/containers/StreamSettings.js diff --git a/client/coral-admin/src/routes/Configure/components/Configure.js b/client/coral-admin/src/routes/Configure/components/Configure.js index 5b5f9a524..4238dbf79 100644 --- a/client/coral-admin/src/routes/Configure/components/Configure.js +++ b/client/coral-admin/src/routes/Configure/components/Configure.js @@ -2,11 +2,12 @@ import React, {Component} from 'react'; import {Button, List, Item} from 'coral-ui'; import styles from './Configure.css'; -import StreamSettings from './StreamSettings'; +import StreamSettings from '../containers/StreamSettings'; import ModerationSettings from './ModerationSettings'; import TechSettings from './TechSettings'; import t from 'coral-framework/services/i18n'; import {can} from 'coral-framework/services/perms'; +import PropTypes from 'prop-types'; export default class Configure extends Component { @@ -23,9 +24,9 @@ export default class Configure extends Component { switch(section){ case 'stream': sectionComponent = ; break; case 'moderation': @@ -105,3 +106,17 @@ export default class Configure extends Component { ); } } + +Configure.propTypes = { + notify: PropTypes.func.isRequired, + updateWordlist: PropTypes.func.isRequired, + updateDomainlist: PropTypes.func.isRequired, + updateSettings: PropTypes.func.isRequired, + errors: PropTypes.object.isRequired, + savePending: PropTypes.func.isRequired, + auth: PropTypes.object.isRequired, + data: PropTypes.object.isRequired, + root: PropTypes.object.isRequired, + settings: PropTypes.object.isRequired, + canSave: PropTypes.bool.isRequired, +}; diff --git a/client/coral-admin/src/routes/Configure/components/Domainlist.js b/client/coral-admin/src/routes/Configure/components/Domainlist.js index 7b7565c5e..890520e8e 100644 --- a/client/coral-admin/src/routes/Configure/components/Domainlist.js +++ b/client/coral-admin/src/routes/Configure/components/Domainlist.js @@ -1,4 +1,5 @@ import React from 'react'; +import PropTypes from 'prop-types'; import {Card} from 'coral-ui'; import styles from './Configure.css'; import TagsInput from 'coral-admin/src/components/TagsInput'; @@ -22,4 +23,9 @@ const Domainlist = ({domains, onChangeDomainlist}) => { ); }; +Domainlist.propTypes = { + domains: PropTypes.array.isRequired, + onChangeDomainlist: PropTypes.func.isRequired, +}; + export default Domainlist; diff --git a/client/coral-admin/src/routes/Configure/components/EmbedLink.js b/client/coral-admin/src/routes/Configure/components/EmbedLink.js index 1ce3d5304..744692092 100644 --- a/client/coral-admin/src/routes/Configure/components/EmbedLink.js +++ b/client/coral-admin/src/routes/Configure/components/EmbedLink.js @@ -7,11 +7,7 @@ import {BASE_URL} from 'coral-framework/constants/url'; class EmbedLink extends Component { - constructor (props) { - super(props); - - this.state = {copied: false}; - } + state = {copied: false}; copyToClipBoard = () => { const copyTextarea = document.querySelector(`.${styles.embedInput}`); diff --git a/client/coral-admin/src/routes/Configure/components/StreamSettings.js b/client/coral-admin/src/routes/Configure/components/StreamSettings.js index dbbd96932..96878c3c8 100644 --- a/client/coral-admin/src/routes/Configure/components/StreamSettings.js +++ b/client/coral-admin/src/routes/Configure/components/StreamSettings.js @@ -4,6 +4,7 @@ import t from 'coral-framework/services/i18n'; import styles from './Configure.css'; import {Checkbox, Textfield} from 'react-mdl'; import {Card, Icon, TextArea} from 'coral-ui'; +import PropTypes from 'prop-types'; import MarkdownEditor from 'coral-framework/components/MarkdownEditor'; const TIMESTAMPS = { @@ -12,187 +13,6 @@ const TIMESTAMPS = { hours: 60 * 60 }; -const updateCharCountEnable = (updateSettings, charCountChecked) => () => { - const charCountEnable = !charCountChecked; - updateSettings({charCountEnable}); -}; - -const updateCharCount = (updateSettings) => (event) => { - let error = null; - const charCount = event.target.value; - if (charCount.match(/[^0-9]/) || charCount.length === 0) { - error = true; - } - updateSettings({charCount: charCount}, {setError: {'charCount': error}}); -}; - -const updateInfoBoxEnable = (updateSettings, infoBox) => () => { - const infoBoxEnable = !infoBox; - updateSettings({infoBoxEnable}); -}; - -const updateInfoBoxContent = (updateSettings) => (value) => { - const infoBoxContent = value; - updateSettings({infoBoxContent}); -}; - -const updateAutoClose = (updateSettings, autoCloseStream) => () => { - updateSettings({autoCloseStream}); -}; - -const updateClosedMessage = (updateSettings) => (event) => { - const closedMessage = event.target.value; - updateSettings({closedMessage}); -}; - -// If we are changing the measure we need to recalculate using the old amount -// Same thing if we are just changing the amount -const updateClosedTimeout = (updateSettings, ts, isMeasure) => (event) => { - if (isMeasure) { - const amount = getTimeoutAmount(ts); - const closedTimeout = amount * TIMESTAMPS[event]; - updateSettings({closedTimeout}); - } else { - const val = event.target.value; - const measure = getTimeoutMeasure(ts); - const closedTimeout = val * TIMESTAMPS[measure]; - updateSettings({closedTimeout}); - } -}; - -const updateEditCommentWindowLength = (updateSettings) => (e) => { - const value = e.target.value; - const valueAsNumber = parseFloat(value); - const milliseconds = (!isNaN(valueAsNumber)) && (valueAsNumber * 1000); - updateSettings({editCommentWindowLength: milliseconds || value}); -}; - -const StreamSettings = ({updateSettings, settings, errors}) => { - - // just putting this here for shorthand below - const on = styles.enabledSetting; - const off = styles.disabledSetting; - - return ( -
-

{t('configure.stream_settings')}

- -
- -
-
-
{t('configure.comment_count_header')}
-

- {t('configure.comment_count_text_pre')} - - {t('configure.comment_count_text_post')} - { - errors.charCount && - -
- - {t('configure.comment_count_error')} -
- } -

-
-
- -
- -
-
-
- {t('configure.include_comment_stream')} -
-

- {t('configure.include_comment_stream_desc')} -

-
- -
-
-
- -
-
{t('configure.closed_stream_settings')}
-

{t('configure.closed_comments_desc')}

-
-