Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. renderItem({item}) {
  2. return (
  3. <Post
  4. data={item}
  5. onPressLike={this.onLikePost}
  6. addLike={this.props.addLikesPost}
  7. email={this.props.email}
  8. postComment={this.props.postComment}
  9. removeLike={this.props.removeLikesPost}
  10. fullName={this.props.firstname + ' ' + this.props.lastname}
  11. />
  12. );
  13. }
  14. <AnimatedFlatList
  15. extraData={this.state}
  16. data={_.values(this.props.posts)}
  17. renderItem={this.renderItem.bind(this)}
  18. keyExtractor={(item) => {
  19. // console.log("Item", item.value.id);
  20. return item.value.socialHash + "";
  21. }}
  22. backgroundColor='#edeaea'
  23. style={{ paddingBottom: 7, }}
  24.  
  25. />
  26.  
  27. class Post extends Component {
  28. constructor(props) {
  29. super(props);
  30. this.child = React.createRef();
  31. this.state = {
  32. title: '',
  33. post: '',
  34. likes: 0,
  35. userLiked: 0,
  36. first_name: '',
  37. last_name: '',
  38. timestamp: null,
  39. socialHash: 0,
  40. comments: null,
  41. id: null,
  42. isVisible: false,
  43. displayComments: false,
  44. typedComment: '',
  45. commentsText: '',
  46. };
  47. }
  48.  
  49. onCommentPress() {
  50. this.props.data.value.comments[0].comments.push({
  51. poster: this.props.fullName,
  52. comment: this.state.typedComment,
  53. key: Math.random() * 10 + "",
  54. time_stamp: new Date()
  55. })
  56. this.setState({ commentsText: this.state.typedComment });
  57. }
  58.  
  59.  
  60. render() {
  61. return (
  62. <View >
  63. <Text>{this.state.typedComment}</Text>
  64. <View>
  65. <Input
  66. onChangeText={(typedComment) => {
  67. console.log("Changing Input", typedComment);
  68. this.setState({ typedComment });
  69. }}
  70. placeholder='Write a comment...'
  71. />
  72. <Button
  73. onPress={this.onCommentPress.bind(this)}>
  74. <Icon name={"paper-plane"} size={20} />
  75. </Button>
  76.  
  77. </View>
  78. </View>
  79. );
  80. }
  81. }
  82.  
  83.  
  84. const mapStateToProps = (state) => {
  85. const { commentText } = state.misc;
  86. return {
  87. commentText
  88. };
  89. };
  90.  
  91. // This helps us to bind our dispatch function to props
  92. const mapDispatchToProps = dispatch =>
  93. bindActionCreators(
  94. {
  95. ...Games
  96. },
  97. dispatch
  98. );
  99.  
  100. export default connect(mapStateToProps, mapDispatchToProps)(Post);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement