Created
May 22, 2016 05:24
-
-
Save bretth18/36fe8a3e0111b42274e3a37f6d7eb7ea to your computer and use it in GitHub Desktop.
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
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