@@ -69,7 +69,7 @@ var CommentFooter = React.createClass({
69
69
return (
70
70
< div className = "commentFooter" >
71
71
< span className = "time" > 25分钟前</ span >
72
- < span className = "reply" > 回复 </ span >
72
+ < span className = "reply" > < a href = '#/reply' > 回复 </ a > </ span >
73
73
</ div >
74
74
) ;
75
75
}
@@ -117,24 +117,42 @@ var CommentBox = React.createClass({
117
117
console . error ( this . props . url , status , err . toString ( ) ) ;
118
118
} . bind ( this )
119
119
} ) ;
120
+ window . location . hash = '' ;
120
121
} ,
121
122
handleOpenForm :function ( ) {
122
- $ ( '.commentFormHolder' ) . show ( ) ; //.css('display','block');
123
+ console . log ( 'handleOpenForm' ) ;
124
+ //$('.commentFormHolder').show();//.css('display','block');
125
+ } ,
126
+ handleHashChange :function ( ) { console . log ( window . location . hash . substr ( 1 ) ) ;
127
+ this . setState ( {
128
+ route : window . location . hash . substr ( 1 )
129
+ } )
123
130
} ,
124
131
getInitialState : function ( ) {
125
- return { data : [ ] } ;
132
+ return {
133
+ data : [ ] ,
134
+ route :window . location . hash . substr ( 1 )
135
+ } ;
126
136
} ,
127
137
componentDidMount : function ( ) {
138
+ window . addEventListener ( 'hashchange' , this . handleHashChange ) ;
128
139
this . loadCommentsFromServer ( ) ;
129
140
setInterval ( this . loadCommentsFromServer , this . props . pollInterval ) ;
130
141
} ,
131
142
render : function ( ) {
143
+
144
+ var CommentFormA ; console . log ( 'render' , this . state . route ) ;
145
+ switch ( this . state . route ) {
146
+ case '/post' : CommentFormA = CommentForm ; break ;
147
+ case '/reply' : CommentFormA = CommentForm ; break ;
148
+ default : CommentFormA = CommentFormBlank ;
149
+ }
132
150
return (
133
151
< div className = "commentBox" >
134
152
< h1 > Comments</ h1 >
135
153
< CommentList data = { this . state . data } />
136
154
< CommentBar onOpenForm = { this . handleOpenForm } />
137
- < CommentForm onCommentSubmit = { this . handleCommentSubmit } />
155
+ < CommentFormA onCommentSubmit = { this . handleCommentSubmit } />
138
156
</ div >
139
157
) ;
140
158
}
@@ -164,11 +182,16 @@ var CommentBar = React.createClass({
164
182
render : function ( ) {
165
183
return (
166
184
< div className = "commentBar" >
167
- < button className = "BtnOpenForm" onClick = { this . props . onOpenForm } > 我也来说说</ button >
185
+ < a href = '#/post' className = "BtnOpenForm" onClick = { this . props . onOpenForm } > 我也来说说</ a >
168
186
</ div >
169
187
)
170
188
}
171
189
} ) ;
190
+ var CommentFormBlank = React . createClass ( {
191
+ render : function ( ) {
192
+ return ( < br /> ) ;
193
+ }
194
+ } ) ;
172
195
var CommentForm = React . createClass ( {
173
196
handleSubmit : function ( e ) {
174
197
e . preventDefault ( ) ;
@@ -177,11 +200,13 @@ var CommentForm = React.createClass({
177
200
if ( ! text || ! author ) {
178
201
return ;
179
202
}
180
- this . props . onCommentSubmit ( { author : author , text : text } ) ;
203
+ this . props . onCommentSubmit ( { author : author , text : text , likedCount : 0 } ) ;
181
204
React . findDOMNode ( this . refs . author ) . value = '' ;
182
205
React . findDOMNode ( this . refs . text ) . value = '' ;
183
206
} ,
184
207
render : function ( ) {
208
+ /* var id = this.props.params.id;
209
+ console.log('key=',id);*/
185
210
return (
186
211
< div className = "commentFormHolder" >
187
212
< form className = "commentForm" onSubmit = { this . handleSubmit } >
@@ -198,3 +223,18 @@ React.render(
198
223
< CommentBox url = "comments.json" pollInterval = { 2000 } /> ,
199
224
document . getElementById ( 'content' )
200
225
) ;
226
+
227
+
228
+ /*var Router = ReactRouter.Router;
229
+ var Route = ReactRouter.Route;
230
+ var Link = ReactRouter.Link;
231
+
232
+ React.render((
233
+ <Router>
234
+ <Route path="/" component={CommentBox} >
235
+ <Route path="post" component={CommentForm} />
236
+ <Route path="reply/:id" component={CommentForm} />
237
+ </Route>
238
+ </Router>
239
+ ), document.getElementById('content')
240
+ );*/
0 commit comments