@@ -63,11 +63,14 @@ module.exports = React.createClass({
6363 this . unsubscribe = PlanetStore . listen ( this . onFetched )
6464
6565 PlanetActions . fetchPlanet ( this . props . params . userName + '/' + this . props . params . planetName )
66- document . addEventListener ( 'keydown' , this . handleKeyDown )
6766 } ,
6867 componentWillUnmount : function ( ) {
6968 this . unsubscribe ( )
70- document . removeEventListener ( 'keydown' , this . handleKeyDown )
69+ } ,
70+ componentDidUpdate : function ( ) {
71+ if ( this . state . currentPlanet . planetName !== this . props . params . planetName ) {
72+ PlanetActions . fetchPlanet ( this . props . params . userName + '/' + this . props . params . planetName )
73+ }
7174 } ,
7275 getFilteredIndexOfCurrentArticle : function ( ) {
7376 var params = this . props . params
@@ -164,7 +167,19 @@ module.exports = React.createClass({
164167 if ( this . refs . detail . props . article == null ) {
165168 var params = this . props . params
166169 delete params . localId
167- this . transitionTo ( 'planetHome' , params )
170+
171+ var articles = this . refs . list . props . articles
172+ if ( articles . length > 0 ) {
173+ console . log ( 'need to redirect' , this . refs . list . props . articles )
174+ var article = articles [ 0 ]
175+ params . localId = article . localId
176+
177+ if ( article . type === 'snippet' ) {
178+ this . transitionTo ( 'snippets' , params )
179+ } else {
180+ this . transitionTo ( 'blueprints' , params )
181+ }
182+ }
168183 }
169184 } )
170185 return
@@ -234,18 +249,31 @@ module.exports = React.createClass({
234249 submitDeleteModal : function ( ) {
235250 this . setState ( { isDeleteModalOpen : false } )
236251 } ,
252+ focus : function ( ) {
253+ React . findDOMNode ( this ) . focus ( )
254+ console . log ( 'focus this' )
255+ } ,
237256 handleKeyDown : function ( e ) {
238257 // Bypath for modal open state
239258 if ( this . state . isLaunchModalOpen ) {
240- if ( e . keyCode === 27 ) this . closeLaunchModal ( )
259+ if ( e . keyCode === 27 ) {
260+ this . closeLaunchModal ( )
261+ this . focus ( )
262+ }
241263 return
242264 }
243265 if ( this . state . isEditModalOpen ) {
244- if ( e . keyCode === 27 ) this . closeEditModal ( )
266+ if ( e . keyCode === 27 ) {
267+ this . closeEditModal ( )
268+ this . focus ( )
269+ }
245270 return
246271 }
247272 if ( this . state . isDeleteModalOpen ) {
248- if ( e . keyCode === 27 ) this . closeDeleteModal ( )
273+ if ( e . keyCode === 27 ) {
274+ this . closeDeleteModal ( )
275+ this . focus ( )
276+ }
249277 return
250278 }
251279
@@ -259,17 +287,18 @@ module.exports = React.createClass({
259287 var searchInput = React . findDOMNode ( this ) . querySelector ( '.PlanetHeader .searchInput input' )
260288
261289 if ( document . activeElement === searchInput ) {
290+ console . log ( 'fff' , e . keyCode )
262291 switch ( e . keyCode ) {
263292 case 38 :
264- searchInput . blur ( )
293+ this . focus ( )
265294 break
266295 case 40 :
267296 e . preventDefault ( )
268- searchInput . blur ( )
297+ this . focus ( )
269298 break
270299 case 27 :
271300 e . preventDefault ( )
272- searchInput . blur ( )
301+ this . focus ( )
273302 break
274303 }
275304 return
@@ -349,7 +378,7 @@ module.exports = React.createClass({
349378 ) ) : null
350379
351380 return (
352- < div className = 'PlanetContainer' >
381+ < div tabIndex = '1' onKeyDown = { this . handleKeyDown } className = 'PlanetContainer' >
353382 < ModalBase isOpen = { this . state . isLaunchModalOpen } close = { this . closeLaunchModal } >
354383 < LaunchModal submit = { this . submitLaunchModal } close = { this . closeLaunchModal } />
355384 </ ModalBase >
0 commit comments