1
1
import React from 'react' ;
2
2
import { connect } from 'react-redux' ;
3
- import { FlatList } from 'react-native' ;
3
+ import { FlatList , TextInput , Button , View , KeyboardAvoidingView } from 'react-native' ;
4
4
import styled from 'styled-components' ;
5
5
import CardView from 'react-native-cardview' ;
6
6
import TimeAgo from 'time-ago' ;
7
7
import { fetchGistComments } from '../gists.actiontype' ;
8
8
import ListEmptyComponent from './components/EmptyListComponent' ;
9
+ import { addComments } from '~/src/api' ;
9
10
10
11
const CardContainer = styled ( CardView ) `
11
12
padding: 3%;
@@ -44,12 +45,33 @@ const CommentDate = styled.Text`
44
45
font-size: 14;
45
46
` ;
46
47
48
+ // const CommentBox = styled.TextInput`
49
+ // `;
50
+
47
51
class GistCommentsScreen extends React . Component {
52
+ state = {
53
+ comment : '' ,
54
+ }
48
55
componentDidMount ( ) {
56
+ console . log ( 'id---------------------------' , this . props . navigation . getParam ( 'gistData' ) . id ) ;
49
57
this . props . fetchComments ( this . props . navigation . getParam ( 'gistData' ) . id ) ;
50
58
}
51
59
52
- renderItem = ( { item } ) => (
60
+ // onEndReachedThreshold = () => {
61
+ // this.setState({
62
+ // i: this.state.i + 6,
63
+ // }, () => {
64
+ // this.props.fetchComments(this.props.navigation.getParam('gistData').id, this.state.i);
65
+ // });
66
+ // }
67
+
68
+
69
+ onPressItem = ( ) => {
70
+ addComments ( this . state . comment , this . props . navigation . getParam ( 'gistData' ) . id , this . props . accessToken ) ;
71
+ }
72
+
73
+ renderItem = ( { item } ) => {
74
+ return (
53
75
< CardContainer
54
76
cardElevation = { 2 }
55
77
cardMaxElevation = { 2 }
@@ -64,25 +86,51 @@ class GistCommentsScreen extends React.Component {
64
86
</ UserProfile >
65
87
< Comment > { item . body } </ Comment >
66
88
</ CardContainer >
67
- )
89
+ ) ;
90
+ }
68
91
69
92
render ( ) {
93
+ const { comments } = this . props ;
94
+
70
95
return (
71
- < FlatList
72
- keyExtractor = { item => item . id }
73
- data = { this . props . comments }
74
- renderItem = { this . renderItem }
75
- ListEmptyComponent = { ( ) => < ListEmptyComponent message = "No comments found" /> }
76
- />
96
+ < React . Fragment >
97
+ < FlatList
98
+ keyExtractor = { item => item . id }
99
+ data = { this . props . comments }
100
+ renderItem = { this . renderItem }
101
+ ListEmptyComponent = { ( ) => < ListEmptyComponent message = "No comments found" /> }
102
+ // onEndReachedThreshold={0.2}
103
+ // onEndReachedThreshold={this.onEndReachedThreshold}
104
+ />
105
+ < View style = { {
106
+ flex : 1 ,
107
+ flexDirection : 'row' ,
108
+ alignItems : 'flex-end' ,
109
+ marginHorizontal : 2 ,
110
+ borderColor : 'red' ,
111
+ borderRadius : 5 ,
112
+ } } >
113
+ < TextInput
114
+ style = { {
115
+ width : '88%' ,
116
+ } }
117
+ placeholder = "Add comment here"
118
+ value = { this . state . comment }
119
+ onChangeText = { comment => this . setState ( { comment } ) }
120
+ />
121
+ < Button title = "Add" onPress = { this . onPressItem } />
122
+ </ View >
123
+ </ React . Fragment >
77
124
) ;
78
125
}
79
126
}
80
-
127
+ // style={{ position: 'absolute', bottom: 0, right: 0 }} />
81
128
const mapDispatchToProps = dispatch => ( {
82
129
fetchComments : id => dispatch ( fetchGistComments . action ( id ) ) ,
83
130
} ) ;
84
- const mapStateToProps = ( { gistComments } ) => ( {
131
+ const mapStateToProps = ( { gistComments, auth } ) => ( {
85
132
comments : gistComments . comments ,
133
+ accessToken : auth . access_token ,
86
134
} ) ;
87
135
88
136
export default connect ( mapStateToProps , mapDispatchToProps ) ( GistCommentsScreen ) ;
0 commit comments