@@ -2,6 +2,7 @@ import React from 'react';
22
33import getTemplate from 'common/templates' ;
44import { protocolAndHost } from 'common/utils/url-generator' ;
5+ import { ARROW_LEFT , ARROW_RIGHT } from 'common/utils/keycodes' ;
56
67import TitleAndMetaTags from '../components/TitleAndMetaTags' ;
78import PageContainer from '../components/PageContainer' ;
@@ -44,6 +45,21 @@ export default class Explore extends React.PureComponent {
4445 // render and server render are not the same. So we force a rerender.
4546 // eslint-disable-next-line
4647 this . setState ( { renderModal : true } ) ;
48+
49+ document . addEventListener ( 'keyup' , ( { keyCode } ) => {
50+ const { featuredSandboxIndex } = this . state ;
51+ switch ( keyCode ) {
52+ case ARROW_LEFT :
53+ if ( featuredSandboxIndex === 0 ) return ;
54+ this . navigateToPreviousSandbox ( ) ;
55+ break ;
56+ case ARROW_RIGHT :
57+ if ( featuredSandboxIndex === featuredSandboxes . length - 1 ) return ;
58+ this . navigateToNextSandbox ( ) ;
59+ break ;
60+ default :
61+ }
62+ } ) ;
4763 }
4864
4965 loadSandboxes = ( ) => {
@@ -99,6 +115,18 @@ export default class Explore extends React.PureComponent {
99115 this . openSandbox ( currentIndex + 1 ) ;
100116 } ;
101117
118+ navigateToNextSandbox = ( ) => {
119+ this . setState ( state => ( {
120+ featuredSandboxIndex : state . featuredSandboxIndex + 1 ,
121+ } ) ) ;
122+ } ;
123+
124+ navigateToPreviousSandbox = ( ) => {
125+ this . setState ( state => ( {
126+ featuredSandboxIndex : state . featuredSandboxIndex - 1 ,
127+ } ) ) ;
128+ } ;
129+
102130 getCurrentIndex = ( ) =>
103131 this . state . selectedSandbox
104132 ? this . state . sandboxes . findIndex (
@@ -156,11 +184,7 @@ export default class Explore extends React.PureComponent {
156184 < Dots >
157185 < StyledLeftArrow
158186 disable = { featuredSandboxIndex === 0 }
159- onClick = { ( ) =>
160- this . setState ( state => ( {
161- featuredSandboxIndex : state . featuredSandboxIndex - 1 ,
162- } ) )
163- }
187+ onClick = { this . navigateToPreviousSandbox }
164188 />
165189
166190 { featuredSandboxes . map ( ( sandbox , i ) => {
@@ -186,11 +210,7 @@ export default class Explore extends React.PureComponent {
186210 disable = {
187211 featuredSandboxIndex === featuredSandboxes . length - 1
188212 }
189- onClick = { ( ) =>
190- this . setState ( state => ( {
191- featuredSandboxIndex : state . featuredSandboxIndex + 1 ,
192- } ) )
193- }
213+ onClick = { this . navigateToNextSandbox }
194214 />
195215 </ Dots >
196216 </ Navigation >
0 commit comments