Skip to content

Instantly share code, notes, and snippets.

@bretth18
Created May 22, 2016 05:24
Show Gist options
  • Save bretth18/36fe8a3e0111b42274e3a37f6d7eb7ea to your computer and use it in GitHub Desktop.
Save bretth18/36fe8a3e0111b42274e3a37f6d7eb7ea to your computer and use it in GitHub Desktop.
class ListComment extends Component {
constructor(props){
super(props);
this.state = {
// prop is an init value, legal baby
commentId: this.props.comment.id,
};
}
// handle time precision
handleTime() {
if (this.props.comment.time === undefined){
return console.log('time empty');
}
else if (this.props.comment.time !== undefined){
return moment(this.props.comment.time).format('dddd, MMMM Do YYYY, h:mm:ss a');
} else {
console.log('neither cases pass');
Alert.alert('fuck please call a developer');
}
}
// function that generates random icon based on UID
generateIcon() {
var commentId = this.props.comment.id;
// does this shit work
console.log('commentID',commentId);
var chopped = commentId.substring(0,4);
console.log('CHOPPED',chopped);
// set state
this.setState({
commentId: chopped
});
}
componentWillMount(){
this.generateIcon();
}
render(){
return(
<TouchableHighlight onPress={this.props.onPress}>
<View style={styles.li}>
<Text style={styles.liText}>{this.props.comment.comment}</Text>
<Text style={{fontWeight:'bold'}}>{this.state.commentId}</Text>
<Text style={styles.liText}>{this.handleTime()}</Text>
</View>
</TouchableHighlight>
);
}
}
module.exports = ListComment;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment