-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 #37 from AndrewGable/tgolen-add-comment
Have the ability to add comments now
- Loading branch information
Showing
8 changed files
with
202 additions
and
55 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
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {View, TextInput, Button} from 'react-native'; | ||
import styles from '../../../style/StyleSheet'; | ||
|
||
const propTypes = { | ||
// A method to call when the form is submitted | ||
onSubmit: PropTypes.func.isRequired, | ||
}; | ||
|
||
class ReportHistoryCompose extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.updateComment = this.updateComment.bind(this); | ||
this.submitForm = this.submitForm.bind(this); | ||
this.triggerSubmitShortcut = this.triggerSubmitShortcut.bind(this); | ||
|
||
this.state = { | ||
comment: '', | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
this.textInput.focus(); | ||
} | ||
|
||
componentDidUpdate() { | ||
this.textInput.focus(); | ||
} | ||
|
||
/** | ||
* Update the value of the comment input in the state | ||
* | ||
* @param {string} newComment | ||
*/ | ||
updateComment(newComment) { | ||
this.setState({ | ||
comment: newComment, | ||
}); | ||
} | ||
|
||
/** | ||
* Listens for the keyboard shortcut and submits | ||
* the form when we have enter | ||
* | ||
* @param {Object} e | ||
*/ | ||
triggerSubmitShortcut(e) { | ||
if (e && e.key === 'Enter' && !e.shiftKey) { | ||
e.preventDefault(); | ||
this.submitForm(); | ||
} | ||
} | ||
|
||
/** | ||
* Add a new comment to this chat | ||
* | ||
* @param {SyntheticEvent} [e] | ||
*/ | ||
submitForm(e) { | ||
if (e) { | ||
e.preventDefault(); | ||
} | ||
|
||
// Don't submit empty commentes | ||
// @TODO show an error in the UI | ||
if (!this.state.comment) { | ||
return; | ||
} | ||
|
||
this.props.onSubmit(this.state.comment); | ||
this.setState({ | ||
comment: '', | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<View style={[styles.mt2]}> | ||
<TextInput | ||
ref={el => this.textInput = el} | ||
multiline | ||
textAlignVertical | ||
numberOfLines={3} | ||
minHeight={60} | ||
maxHeight={60} | ||
onChangeText={this.updateComment} | ||
onKeyPress={this.triggerSubmitShortcut} | ||
style={[styles.textInput]} | ||
value={this.state.comment} | ||
/> | ||
<View style={[styles.mt1, styles.flexRow]}> | ||
<Button title="Send" onPress={this.submitForm} /> | ||
</View> | ||
</View> | ||
); | ||
} | ||
} | ||
ReportHistoryCompose.propTypes = propTypes; | ||
|
||
export default ReportHistoryCompose; |
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
Oops, something went wrong.