@@ -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 ) {
@@ -200,6 +198,20 @@ class App extends Component {
200198 type : 'TIMETRAVEL' ,
201199 direction : 'forward' ,
202200 } ) ;
201+
202+ // if (isPlayingIndex >= this.state.data.length - 1) isPlayingIndex = 0;
203+
204+ const { data, isPlayingIndex } = this . state ;
205+ const { id, action, state } = data [ isPlayingIndex + 1 ] ;
206+ this . setState ( prev => ( {
207+ ...prev ,
208+ id,
209+ action,
210+ state,
211+ isPlayingIndex : isPlayingIndex + 1 ,
212+ } ) ) ;
213+
214+ console . log ( 'isPlayingIndex' , this . state . isPlayingIndex ) ;
203215 }
204216
205217 // function to travel to the PAST
@@ -209,6 +221,21 @@ class App extends Component {
209221 type : 'TIMETRAVEL' ,
210222 direction : 'backwards' ,
211223 } ) ;
224+
225+ const { data, isPlayingIndex } = this . state ;
226+
227+ if ( isPlayingIndex === 0 ) {
228+ console . log ( 'is playingIdx in toThePast is 0' ) ;
229+ } else {
230+ const { id, action, state } = data [ isPlayingIndex - 1 ] ;
231+ this . setState ( prev => ( {
232+ ...prev ,
233+ id,
234+ action,
235+ state,
236+ isPlayingIndex : isPlayingIndex - 1 ,
237+ } ) ) ;
238+ }
212239 }
213240
214241 render ( ) {
@@ -265,4 +292,4 @@ class App extends Component {
265292 }
266293}
267294
268- export default App ;
295+ export default App ;
0 commit comments