@@ -22,6 +22,8 @@ import { connect } from 'react-redux';
2222import TabShow from '../components/TabShow' ;
2323import connectComponent from '../utils/connectComponent' ;
2424import config from '../config' ;
25+ import * as QrCodeComponent from './QrCode' ;
26+ const QrCode = connectComponent ( QrCodeComponent ) ;
2527
2628let ds = new ListView . DataSource ( { rowHasChanged : ( r1 , r2 ) => r1 !== r2 } )
2729
@@ -33,6 +35,14 @@ class Comment extends Component {
3335 this . keyboardWillHideEvent = DeviceEventEmitter . addListener ( 'keyboardWillHide' , this . keyboardWillHide . bind ( this ) ) ;
3436 }
3537
38+ componentWillMount ( ) {
39+ const { data } = this . props . Detail ;
40+ if ( data && data . id ) {
41+ const { actions } = this . props ;
42+ actions . getTopicDetail ( data . id )
43+ }
44+ }
45+
3646 keyboardWillShow ( e ) {
3747 this . commentView && this . commentView . setNativeProps ( {
3848 style : {
@@ -49,39 +59,80 @@ class Comment extends Component {
4959 } )
5060 }
5161
52- reply ( ) {
53- const { actions , Detail } = this . props ;
62+ reply ( name ) {
63+ const { actions , Detail , User , navigator} = this . props ;
64+ if ( ! User . data ) {
65+ return actions . toast ( '登陆后评论!' , 2000 )
66+ }
67+
5468 if ( ! this . textInputValue ) {
5569 return actions . toast ( '评论不能为空' )
5670 }
57- console . log ( this )
71+
5872 actions . replyTopicById ( {
5973 topicId : Detail . data . id ,
6074 content : this . textInputValue + config . replySuffix ,
6175 // replyId: this.replyId,
6276 user : {
63- loginname : '212 ' ,
64- avatar_url : '2212 '
77+ loginname : 'test ' ,
78+ avatar_url : 'http://test.imgs.wn518.com/upimages/ys-sales/2016-05-05/fc37e0ae1cdc0282019f3d7d25d6fcdf_1_0_0_480_480_0.jpg '
6579 }
6680 } , ( ) => {
6781 this . _resetReplyForm ( )
6882 } )
6983 }
7084
85+ _onAuthorTextPress ( authorName ) {
86+ // if (!this.props.user) return;
87+ const { actions , User} = this . props ;
88+ if ( ! User . data ) {
89+ return actions . toast ( '登陆后评论!' , 2000 )
90+ }
91+
92+ let text = ( this . textInputValue || '' ) + ` @${ authorName } ` ;
93+ this . textInput . setNativeProps ( {
94+ text : text
95+ } ) ;
96+ this . textInputValue = text ;
97+ }
98+
99+ _scrollToTop ( ) {
100+ this . _listView . scrollTo ( {
101+ x : 0 ,
102+ y : 0
103+ } ) ;
104+ }
105+
71106 _resetReplyForm ( ) {
72107 this . replyId = null ;
73108 this . textInput . setNativeProps ( {
74109 text : ''
75110 } ) ;
76111 this . textInputValue = '' ;
77112 this . textInput . blur ( ) ;
113+ this . _scrollToTop ( )
78114 }
79115
116+ _upreply ( id ) {
117+ const { actions } = this . props ;
118+ actions . upReply ( id ) ;
119+ }
120+
121+ goLogin ( ) {
122+ const { navigator } = this . props ;
123+ navigator . push ( {
124+ component : QrCode
125+ } )
126+ }
127+
80128 componentUnMount ( ) {
81129 this . keyboardWillHideEvent . remove ( )
82130 this . keyboardWillShowEvent . remove ( )
83131 }
132+
133+
84134 render ( ) {
135+
85136 const pointContent = ( ( ) => {
86137 return (
87138 < Icon
@@ -92,7 +143,8 @@ class Comment extends Component {
92143 )
93144 } ) ( ) ;
94145
95- const { Detail , navigator} = this . props ;
146+ const { Comment , navigator , User} = this . props ;
147+ console . log ( this )
96148 return (
97149 < View style = { [ styles . container ] } >
98150 < View style = { [ styles . commentHeader ] } >
@@ -104,7 +156,7 @@ class Comment extends Component {
104156 < View >
105157 < TouchableOpacity >
106158 < Text style = { { fontSize :16 , color :'#fff' } } >
107- 评论({ Detail && Detail . data && Detail . data . reply_count } )
159+ 评论({ Comment . topics . data && Comment . topics . data . replies && Comment . topics . data . replies . length } )
108160 </ Text >
109161 </ TouchableOpacity >
110162 </ View >
@@ -114,9 +166,10 @@ class Comment extends Component {
114166 ref = { ( view ) => this . commentView = view }
115167 >
116168 {
117- Detail && Detail . data && Detail . data . reply_count != 0 ?
169+ Comment . topics . data && Comment . topics . data . replies && Comment . topics . data . replies . length != 0 ?
118170 < ListView
119- dataSource = { ds . cloneWithRows ( Detail . data . replies ) }
171+ ref = { ( view ) => this . _listView = view }
172+ dataSource = { ds . cloneWithRows ( Comment . topics . data . replies . reverse ( ) ) }
120173 renderRow = { this . _renderRow . bind ( this ) }
121174 initialListSize = { 10 }
122175 onEndReachedThreshold = { 0 }
@@ -128,45 +181,54 @@ class Comment extends Component {
128181 renderFooter = { null }
129182 /> :
130183 < View style = { { flexDirection :'row' , paddingTop :30 , alignItems : 'center' , justifyContent : 'center' } } >
131- < Text style = { { fontSize :20 , color : '#red' } } > 暂无评论</ Text >
184+ < Text style = { { fontSize :20 } } > 暂无评论</ Text >
132185 </ View >
133186 }
134187 </ View >
135- < View style = { [ styles . commentBox ] } >
136- < Image
137- style = { [ styles . article , styles . authorHeader ] }
138- source = { { uri : 'http://test.imgs.wn518.com/upimages/ys-sales/2016-05-05/fc37e0ae1cdc0282019f3d7d25d6fcdf_1_0_0_480_480_0.jpg' } }
139- />
140- < View style = { { flex :1 } } >
141- < TextInput
142- ref = { ( view ) => this . textInput = view }
143- value = { this . state && this . state . textInput }
144- onChangeText = { ( text ) => {
145- this . textInput . setNativeProps ( {
146- text : text
147- } ) ;
148- this . textInputValue = text ;
149- this . setState ( { textInput :text } )
150- } }
151- style = { { height : 40 , borderWidth :1 , borderColor :'#eee' } }
152- placeholder = "说说我的看法"
153- placeholderTextColor = "#ccc"
154- keyboardType = { "default" }
155- />
156- </ View >
157- < View >
158- < TouchableOpacity
159- style = { [ styles . replyBtn ] }
160- onPress = { ( ) => this . reply ( ) }
161- >
162- < Icon
163- name = 'ios-undo'
164- size = { 30 }
165- color = '#333'
166- />
188+ {
189+ User . data ?
190+ < View style = { [ styles . commentBox ] } >
191+ < Image
192+ style = { [ styles . article , styles . authorHeader ] }
193+ source = { { uri : User . data . avatar_url } }
194+ />
195+ < View style = { { flex :1 } } >
196+ < TextInput
197+ ref = { ( view ) => this . textInput = view }
198+
199+ onChangeText = { ( text ) => {
200+ this . textInput . setNativeProps ( {
201+ text : text
202+ } ) ;
203+ this . textInputValue = text ;
204+ } }
205+ style = { { height : 40 , borderWidth :1 , borderColor :'#eee' } }
206+ placeholder = "说说我的看法"
207+ placeholderTextColor = "#ccc"
208+ keyboardType = { "default" }
209+
210+ />
211+ </ View >
212+ < View >
213+ < TouchableOpacity
214+ style = { [ styles . replyBtn ] }
215+ onPress = { ( ) => this . reply ( ) }
216+ >
217+ < Icon
218+ name = 'ios-undo'
219+ size = { 30 }
220+ color = '#ccc'
221+ />
222+ </ TouchableOpacity >
223+ </ View >
224+ </ View > :
225+ < View style = { [ styles . commentBox , { flexDirection :'row' , alignItems :'center' , justifyContent :"center" } ] } >
226+ < TouchableOpacity onPress = { ( ) => this . goLogin ( ) } >
227+ < Text style = { { fontSize :20 , color :'#ccc' , flex : 1 , textAlign :'center' } } > 登录后评论</ Text >
167228 </ TouchableOpacity >
168229 </ View >
169- </ View >
230+ }
231+
170232 </ View >
171233 )
172234 }
@@ -197,6 +259,30 @@ class Comment extends Component {
197259 content = { rowData . content }
198260 style = { htmlStyles }
199261 />
262+ < View style = { styles . undo } >
263+ < TouchableOpacity
264+ onPress = { ( ) => this . _upreply ( rowData ) }
265+ >
266+ < View >
267+ < Icon
268+ name = 'md-thumbs-up'
269+ size = { 20 }
270+ color = '#ccc'
271+ />
272+ </ View >
273+ </ TouchableOpacity >
274+ < TouchableOpacity
275+ onPress = { ( ) => this . _onAuthorTextPress ( rowData . author . loginname ) }
276+ >
277+ < View >
278+ < Icon
279+ name = 'ios-undo'
280+ size = { 20 }
281+ color = '#ccc'
282+ />
283+ </ View >
284+ </ TouchableOpacity >
285+ </ View >
200286 </ View >
201287 </ View >
202288 )
@@ -227,6 +313,10 @@ const styles = StyleSheet.create({
227313 paddingTop : 5 ,
228314 marginLeft :5
229315 } ,
316+ undo : {
317+ flexDirection : 'row' ,
318+ justifyContent : 'space-between'
319+ } ,
230320 commentHeader : {
231321 height : headerHeight ,
232322 paddingTop :20 ,
@@ -440,15 +530,3 @@ export function mapStateToProps(state){
440530 Detail : state . Detail
441531 }
442532}
443- // const mapActionCreators = (dispatch) => ({
444- // comment : bindActionCreators(CommentActions , dispatch),
445- // detail : bindActionCreators(DetailActions , dispatch),
446- // })
447- //
448- // const mapStateToProps = (state)=>
449- // ({
450- // Comment : state.Comment,
451- // Detail : state.Detail
452- // })
453- //
454- // export default connect (mapStateToProps , mapActionCreators)(Comment)
0 commit comments