@@ -93,6 +93,8 @@ class App extends Component {
9393 } ) ;
9494 }
9595
96+
97+
9698 // functionality to change 'play' button to 'stop'
9799 setIsPlaying ( ) {
98100 if ( this . state . isPlayingIndex > this . state . data . length - 1 ) {
@@ -183,15 +185,23 @@ class App extends Component {
183185
184186 // time travel bar change
185187 handleBarChange ( e ) {
186- const { data } = this . state ;
188+ const { data, isPlayingIndex } = this . state ;
187189 const { id, action, state } = data [ e . target . value ] ;
188-
190+ // forward or past
191+ const currentIsPlayingIndex = e . target . value ;
192+ const forward = currentIsPlayingIndex > isPlayingIndex ;
189193 this . setState ( {
190194 id,
191195 action,
192196 state,
193- isPlayingIndex : parseInt ( e . target . value ) ,
197+ isPlayingIndex : parseInt ( currentIsPlayingIndex ) ,
194198 } ) ;
199+ // Displays to screen
200+ if ( forward ) {
201+ this . toTheFuture ( ) ;
202+ } else {
203+ this . toThePast ( ) ;
204+ }
195205 }
196206
197207 // function to travel to the FUTURE
@@ -201,6 +211,20 @@ class App extends Component {
201211 type : 'TIMETRAVEL' ,
202212 direction : 'forward' ,
203213 } ) ;
214+
215+ // if (isPlayingIndex >= this.state.data.length - 1) isPlayingIndex = 0;
216+
217+ const { data, isPlayingIndex } = this . state ;
218+ const { id, action, state } = data [ isPlayingIndex + 1 ] ;
219+ this . setState ( prev => ( {
220+ ...prev ,
221+ id,
222+ action,
223+ state,
224+ isPlayingIndex : isPlayingIndex + 1 ,
225+ } ) ) ;
226+
227+ console . log ( 'isPlayingIndex' , this . state . isPlayingIndex ) ;
204228 }
205229
206230 // function to travel to the PAST
@@ -210,6 +234,21 @@ class App extends Component {
210234 type : 'TIMETRAVEL' ,
211235 direction : 'backwards' ,
212236 } ) ;
237+
238+ const { data, isPlayingIndex } = this . state ;
239+
240+ if ( isPlayingIndex === 0 ) {
241+ console . log ( 'is playingIdx in toThePast is 0' ) ;
242+ } else {
243+ const { id, action, state } = data [ isPlayingIndex - 1 ] ;
244+ this . setState ( prev => ( {
245+ ...prev ,
246+ id,
247+ action,
248+ state,
249+ isPlayingIndex : isPlayingIndex - 1 ,
250+ } ) ) ;
251+ }
213252 }
214253
215254 resetApp ( ) {
@@ -277,4 +316,4 @@ class App extends Component {
277316 }
278317}
279318
280- export default App ;
319+ export default App ;
0 commit comments