@@ -70,7 +70,7 @@ module.exports = React.createClass({
7070 this . unsubscribe ( )
7171 } ,
7272 componentDidUpdate : function ( ) {
73- if ( this . state . currentPlanet . name !== this . props . params . planetName || this . state . currentPlanet . userName !== this . props . params . userName ) {
73+ if ( this . state . currentPlanet == null || this . state . currentPlanet . name !== this . props . params . planetName || this . state . currentPlanet . userName !== this . props . params . userName ) {
7474 PlanetActions . fetchPlanet ( this . props . params . userName , this . props . params . planetName )
7575 this . focus ( )
7676 }
@@ -162,6 +162,10 @@ module.exports = React.createClass({
162162 }
163163 } ,
164164 onFetched : function ( res ) {
165+ if ( res == null ) {
166+ return
167+ }
168+
165169 var articles = this . state . currentPlanet == null ? null : this . state . currentPlanet . Articles
166170
167171 if ( res . status === 'planetFetched' ) {
@@ -195,8 +199,16 @@ module.exports = React.createClass({
195199 }
196200 this . state . currentPlanet . Users . push ( user )
197201 this . setState ( { currentPlanet : this . state . currentPlanet } , function ( ) {
198- this . closeAddUserModal ( )
202+ if ( this . state . isAddUserModalOpen ) { this . closeAddUserModal ( ) }
199203 } )
204+ return
205+ }
206+
207+ if ( res . status === 'nameChanged' ) {
208+ var params = Object . assign ( { } , this . props . params )
209+ params . planetName = res . data . name
210+ this . transitionTo ( 'planet' , params )
211+ return
200212 }
201213
202214 var article = res . data
@@ -209,14 +221,17 @@ module.exports = React.createClass({
209221 articles . unshift ( article )
210222
211223 this . setState ( { planet : this . state . currentPlanet , search : '' } , function ( ) {
224+ this . closeLaunchModal ( )
212225 this . selectArticleByIndex ( 0 )
213226 } )
214227 break
215228 case 'articleUpdated' :
216229 articles . splice ( index , 1 )
217230 articles . unshift ( article )
218231
219- this . setState ( { planet : this . state . currentPlanet } )
232+ this . setState ( { planet : this . state . currentPlanet } , function ( ) {
233+ this . closeEditModal ( )
234+ } )
220235 break
221236 case 'articleDeleted' :
222237 articles . splice ( index , 1 )
@@ -241,20 +256,26 @@ module.exports = React.createClass({
241256 this . setState ( { isLaunchModalOpen : true } )
242257 } ,
243258 closeLaunchModal : function ( ) {
244- this . setState ( { isLaunchModalOpen : false } )
259+ this . setState ( { isLaunchModalOpen : false } , function ( ) {
260+ this . focus ( )
261+ } )
245262 } ,
246263 openAddUserModal : function ( ) {
247264 this . setState ( { isAddUserModalOpen : true } )
248265 } ,
249266 closeAddUserModal : function ( ) {
250- this . setState ( { isAddUserModalOpen : false } )
267+ this . setState ( { isAddUserModalOpen : false } , function ( ) {
268+ this . focus ( )
269+ } )
251270 } ,
252271 openEditModal : function ( ) {
253272 if ( this . refs . detail . props . article == null ) { return }
254273 this . setState ( { isEditModalOpen : true } )
255274 } ,
256275 closeEditModal : function ( ) {
257- this . setState ( { isEditModalOpen : false } )
276+ this . setState ( { isEditModalOpen : false } , function ( ) {
277+ this . focus ( )
278+ } )
258279 } ,
259280 submitEditModal : function ( ) {
260281 this . setState ( { isEditModalOpen : false } )
@@ -264,7 +285,9 @@ module.exports = React.createClass({
264285 this . setState ( { isDeleteModalOpen : true } )
265286 } ,
266287 closeDeleteModal : function ( ) {
267- this . setState ( { isDeleteModalOpen : false } )
288+ this . setState ( { isDeleteModalOpen : false } , function ( ) {
289+ this . focus ( )
290+ } )
268291 } ,
269292 submitDeleteModal : function ( ) {
270293 this . setState ( { isDeleteModalOpen : false } )
@@ -273,7 +296,9 @@ module.exports = React.createClass({
273296 this . setState ( { isSettingModalOpen : true } )
274297 } ,
275298 closeSettingModal : function ( ) {
276- this . setState ( { isSettingModalOpen : false } )
299+ this . setState ( { isSettingModalOpen : false } , function ( ) {
300+ this . focus ( )
301+ } )
277302 } ,
278303 focus : function ( ) {
279304 React . findDOMNode ( this ) . focus ( )
@@ -283,28 +308,30 @@ module.exports = React.createClass({
283308 if ( this . state . isLaunchModalOpen ) {
284309 if ( e . keyCode === 27 ) {
285310 this . closeLaunchModal ( )
286- this . focus ( )
287311 }
288312 return
289313 }
290314 if ( this . state . isEditModalOpen ) {
291315 if ( e . keyCode === 27 ) {
292316 this . closeEditModal ( )
293- this . focus ( )
294317 }
295318 return
296319 }
297320 if ( this . state . isDeleteModalOpen ) {
298321 if ( e . keyCode === 27 ) {
299322 this . closeDeleteModal ( )
300- this . focus ( )
301323 }
302324 return
303325 }
304326 if ( this . state . isAddUserModalOpen ) {
305327 if ( e . keyCode === 27 ) {
306328 this . closeAddUserModal ( )
307- this . focus ( )
329+ }
330+ return
331+ }
332+ if ( this . state . isSettingModalOpen ) {
333+ if ( e . keyCode === 27 ) {
334+ this . closeSettingModal ( )
308335 }
309336 return
310337 }
0 commit comments