diff --git a/web/app/common/constants.js b/web/app/common/constants.js index c076403c..b22bf9ca 100644 --- a/web/app/common/constants.js +++ b/web/app/common/constants.js @@ -3,7 +3,8 @@ const API_BASE = '/api/v1'; const NODE_ID = 'remark42'; const COUNTER_NODE_CLASSNAME = 'remark42__counter'; const LAST_COMMENTS_NODE_CLASSNAME = 'remark42__last-comments'; -const LAST_COMMENTS_DEFAULT_MAX = 15; +const DEFAULT_LAST_COMMENTS_MAX = 15; +const DEFAULT_MAX_COMMENT_SIZE = 1000; module.exports = { BASE_URL, @@ -11,5 +12,6 @@ module.exports = { NODE_ID, COUNTER_NODE_CLASSNAME, LAST_COMMENTS_NODE_CLASSNAME, - LAST_COMMENTS_DEFAULT_MAX, + DEFAULT_LAST_COMMENTS_MAX, + DEFAULT_MAX_COMMENT_SIZE, }; diff --git a/web/app/components/input/__counter/input__counter.scss b/web/app/components/input/__counter/input__counter.scss new file mode 100644 index 00000000..31b8a7d8 --- /dev/null +++ b/web/app/components/input/__counter/input__counter.scss @@ -0,0 +1,8 @@ +.input__counter { + position: absolute; + right: 4px; + bottom: 4px; + font-size: 10px; + font-weight: 700; + color: #ef0000; +} diff --git a/web/app/components/input/__field-wrapper/input__field-wrapper.scss b/web/app/components/input/__field-wrapper/input__field-wrapper.scss new file mode 100644 index 00000000..1a6cde54 --- /dev/null +++ b/web/app/components/input/__field-wrapper/input__field-wrapper.scss @@ -0,0 +1,3 @@ +.input__field-wrapper { + position: relative; +} diff --git a/web/app/components/input/index.js b/web/app/components/input/index.js index b170442c..b5b8d05e 100644 --- a/web/app/components/input/index.js +++ b/web/app/components/input/index.js @@ -9,6 +9,8 @@ require('./__button/_type/_preview/input__button_type_preview.scss'); require('./__button/_type/_send/input__button_type_send.scss'); require('./__buttons/input__buttons.scss'); +require('./__counter/input__counter.scss'); require('./__error/input__error.scss'); require('./__field/input__field.scss'); +require('./__field-wrapper/input__field-wrapper.scss'); require('./__preview/input__preview.scss'); diff --git a/web/app/components/input/input.jsx b/web/app/components/input/input.jsx index 761734cf..32b663dc 100644 --- a/web/app/components/input/input.jsx +++ b/web/app/components/input/input.jsx @@ -1,14 +1,21 @@ import { h, Component } from 'preact'; +import { DEFAULT_MAX_COMMENT_SIZE } from 'common/constants'; + import api from 'common/api'; +import store from 'common/store'; export default class Input extends Component { constructor(props) { super(props); + const config = store.get('config') || {}; + this.state = { preview: null, isErrorShown: false, + maxLength: config.max_comment_size || DEFAULT_MAX_COMMENT_SIZE, + commentLength: 0, }; this.send = this.send.bind(this); @@ -23,6 +30,10 @@ export default class Input extends Component { } this.fieldNode.value = ''; + + store.onUpdate('config', config => { + this.setState({ maxLength: config && config.max_comment_size || DEFAULT_MAX_COMMENT_SIZE }); + }); } onKeyDown(e) { @@ -43,6 +54,7 @@ export default class Input extends Component { this.setState({ preview: null, isErrorShown: false, + commentLength: this.fieldNode.value.length, }); } @@ -92,20 +104,29 @@ export default class Input extends Component { }); } - render(props, { isFieldDisabled, isErrorShown, preview }) { + render(props, { isFieldDisabled, isErrorShown, preview, maxLength, commentLength }) { + const charactersLeft = maxLength - commentLength; + return (