From 066034c62e87412c1e351fd89d98f3ad706d00a3 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Mon, 19 Aug 2019 20:53:28 +0200 Subject: [PATCH] Refactor character counter to match upstream --- .../compose/components/character_counter.js | 25 +++++++++++++++++++ .../features/compose/components/publisher.js | 3 ++- .../compose/components/upload_form.js | 3 ++- .../compose/components/upload_progress.js | 9 ++++--- .../glitch/styles/components/composer.scss | 2 +- 5 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 app/javascript/flavours/glitch/features/compose/components/character_counter.js diff --git a/app/javascript/flavours/glitch/features/compose/components/character_counter.js b/app/javascript/flavours/glitch/features/compose/components/character_counter.js new file mode 100644 index 00000000000..0ecfc9141d8 --- /dev/null +++ b/app/javascript/flavours/glitch/features/compose/components/character_counter.js @@ -0,0 +1,25 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { length } from 'stringz'; + +export default class CharacterCounter extends React.PureComponent { + + static propTypes = { + text: PropTypes.string.isRequired, + max: PropTypes.number.isRequired, + }; + + checkRemainingText (diff) { + if (diff < 0) { + return {diff}; + } + + return {diff}; + } + + render () { + const diff = this.props.max - length(this.props.text); + return this.checkRemainingText(diff); + } + +} diff --git a/app/javascript/flavours/glitch/features/compose/components/publisher.js b/app/javascript/flavours/glitch/features/compose/components/publisher.js index e283b32b937..21400e554ee 100644 --- a/app/javascript/flavours/glitch/features/compose/components/publisher.js +++ b/app/javascript/flavours/glitch/features/compose/components/publisher.js @@ -9,6 +9,7 @@ import ImmutablePureComponent from 'react-immutable-pure-component'; // Components. import Button from 'flavours/glitch/components/button'; import Icon from 'flavours/glitch/components/icon'; +import CharacterCounter from './character_counter'; // Utils. import { maxChars } from 'flavours/glitch/util/initial_state'; @@ -49,7 +50,7 @@ class Publisher extends ImmutablePureComponent { return (
- {diff} + {sideArm && sideArm !== 'none' ? (