@@ -60,11 +60,6 @@ class App extends Component {
6060 }
6161
6262 componentDidMount ( ) {
63- // *******************************************************
64- // need to impletement setState for filteredData to same value as data
65- // this.setState({ data, filteredData: data });
66- // *******************************************************
67-
6863 // adds listener to the effects that are gonna be sent from
6964 // our edited useReducer from the 'react' library.
7065 chrome . runtime . onConnect . addListener ( ( portFromExtension ) => {
@@ -79,11 +74,14 @@ class App extends Component {
7974 this . setState ( ( state ) => ( {
8075 data : [ ...state . data , newData ] ,
8176 filteredData : [ ...state . data , newData ] ,
77+ isPlayingIndex : state . data . length - 1 ,
8278 } ) ) ;
8379 } ) ;
8480 } ) ;
8581 }
8682
83+
84+
8785 // functionality to change 'play' button to 'stop'
8886 setIsPlaying ( ) {
8987 if ( this . state . isPlayingIndex > this . state . data . length - 1 ) {
@@ -192,6 +190,20 @@ class App extends Component {
192190 type : 'TIMETRAVEL' ,
193191 direction : 'forward' ,
194192 } ) ;
193+
194+ // if (isPlayingIndex >= this.state.data.length - 1) isPlayingIndex = 0;
195+
196+ const { data, isPlayingIndex } = this . state ;
197+ const { id, action, state } = data [ isPlayingIndex + 1 ] ;
198+ this . setState ( prev => ( {
199+ ...prev ,
200+ id,
201+ action,
202+ state,
203+ isPlayingIndex : isPlayingIndex + 1 ,
204+ } ) ) ;
205+
206+ console . log ( 'isPlayingIndex' , this . state . isPlayingIndex ) ;
195207 }
196208
197209 // function to travel to the PAST
@@ -201,6 +213,21 @@ class App extends Component {
201213 type : 'TIMETRAVEL' ,
202214 direction : 'backwards' ,
203215 } ) ;
216+
217+ const { data, isPlayingIndex } = this . state ;
218+
219+ if ( isPlayingIndex === 0 ) {
220+ console . log ( 'is playingIdx in toThePast is 0' ) ;
221+ } else {
222+ const { id, action, state } = data [ isPlayingIndex - 1 ] ;
223+ this . setState ( prev => ( {
224+ ...prev ,
225+ id,
226+ action,
227+ state,
228+ isPlayingIndex : isPlayingIndex - 1 ,
229+ } ) ) ;
230+ }
204231 }
205232
206233 render ( ) {
0 commit comments