-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15501 from redstar504/Brayden-MarkdownLength
- Loading branch information
Showing
5 changed files
with
91 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,62 @@ | ||
import React from 'react'; | ||
import React, {PureComponent} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {debounce} from 'lodash'; | ||
import CONST from '../CONST'; | ||
import * as ReportUtils from '../libs/ReportUtils'; | ||
import Text from './Text'; | ||
import styles from '../styles/styles'; | ||
|
||
const propTypes = { | ||
/** The current length of the comment */ | ||
commentLength: PropTypes.number.isRequired, | ||
/** Text Comment */ | ||
comment: PropTypes.string.isRequired, | ||
|
||
/** Update UI on parent when comment length is exceeded */ | ||
onExceededMaxCommentLength: PropTypes.func.isRequired, | ||
}; | ||
|
||
const ExceededCommentLength = (props) => { | ||
if (props.commentLength <= CONST.MAX_COMMENT_LENGTH) { | ||
return null; | ||
class ExceededCommentLength extends PureComponent { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
commentLength: 0, | ||
}; | ||
|
||
// By debouncing, we defer the calculation until there is a break in typing | ||
this.updateCommentLength = debounce(this.updateCommentLength.bind(this), CONST.TIMING.COMMENT_LENGTH_DEBOUNCE_TIME); | ||
} | ||
|
||
return ( | ||
<Text style={[styles.textMicro, styles.textDanger, styles.chatItemComposeSecondaryRow, styles.mlAuto, styles.pl2]}> | ||
{`${props.commentLength}/${CONST.MAX_COMMENT_LENGTH}`} | ||
</Text> | ||
); | ||
}; | ||
componentDidMount() { | ||
this.updateCommentLength(); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if (prevProps.comment === this.props.comment) { | ||
return; | ||
} | ||
|
||
this.updateCommentLength(); | ||
} | ||
|
||
updateCommentLength() { | ||
const commentLength = ReportUtils.getCommentLength(this.props.comment); | ||
this.setState({commentLength}); | ||
this.props.onExceededMaxCommentLength(commentLength > CONST.MAX_COMMENT_LENGTH); | ||
} | ||
|
||
render() { | ||
if (this.state.commentLength <= CONST.MAX_COMMENT_LENGTH) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Text style={[styles.textMicro, styles.textDanger, styles.chatItemComposeSecondaryRow, styles.mlAuto, styles.pl2]}> | ||
{`${this.state.commentLength}/${CONST.MAX_COMMENT_LENGTH}`} | ||
</Text> | ||
); | ||
} | ||
} | ||
|
||
ExceededCommentLength.propTypes = propTypes; | ||
ExceededCommentLength.displayName = 'ExceededCommentLength'; | ||
|
||
export default ExceededCommentLength; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters