@@ -82,12 +82,13 @@ class App extends Component {
8282 if ( newDataActionType . includes ( searchField . toLowerCase ( ) ) ) {
8383 this . setState ( state => ( {
8484 data : [ ...state . data , newData ] ,
85- filteredData : [ ...state . data , newData ] ,
8685 isPlayingIndex : state . data . length ,
86+ filteredData : [ ...state . filteredData , newData ] ,
8787 } ) ) ;
8888 } else {
8989 this . setState ( state => ( {
9090 data : [ ...state . data , newData ] ,
91+ isPlayingIndex : state . data . length ,
9192 } ) ) ;
9293 }
9394 } ) ;
@@ -107,12 +108,13 @@ class App extends Component {
107108
108109 // functionality to change 'play' button to 'stop'
109110 setIsPlaying ( ) {
110- if ( this . state . isPlayingIndex >= this . state . data . length ) {
111- this . setState ( prevState => ( { ... prevState , isPlayingIndex : 0 } ) ) ;
111+ if ( this . state . isPlayingIndex >= this . state . data . length - 1 ) {
112+ return ;
112113 }
113114
114115 let { isPlaying } = this . state ;
115- this . setState ( prevState => ( { ...prevState , isPlaying : ! prevState . isPlaying } ) ) ;
116+ isPlaying = ! isPlaying ;
117+ this . setState ( { isPlaying } ) ;
116118
117119 if ( isPlaying ) {
118120 this . actionInPlay ( ) ;
@@ -142,23 +144,14 @@ class App extends Component {
142144 }
143145
144146 actionInPlay ( ) {
145- let { isPlayingIndex } = this . state ;
146- const { isPlaying, data } = this . state ;
147-
148- if ( isPlayingIndex >= data . length - 1 ) isPlayingIndex = 0 ;
149-
150- this . setState ( prevState => ( { ...prevState , isPlayingIndex : isPlayingIndex + 1 } ) ) ;
151- const { id, action, state } = data [ isPlayingIndex + 1 ] ;
152- this . toTheFuture ( ) ;
147+ const { data, isPlayingIndex } = this . state ;
153148
154149 setTimeout ( ( ) => {
155- this . setState ( ( prev , props ) => {
156- return { ...prev , id, action, state } ;
157- } ) ;
158- if ( isPlaying && isPlayingIndex + 1 < data . length - 1 ) {
150+ this . toTheFuture ( ) ;
151+ if ( this . state . isPlaying && isPlayingIndex + 1 < data . length - 1 ) {
159152 this . actionInPlay ( ) ;
160153 } else {
161- this . setState ( prevState => ( { ... prevState , isPlaying : false } ) ) ;
154+ this . setState ( { isPlaying : false } ) ;
162155 }
163156 } , 1000 ) ;
164157 }
@@ -226,7 +219,7 @@ class App extends Component {
226219 direction : 'forward' ,
227220 } ) ;
228221
229- if ( this . state . isPlayingIndex >= this . state . data . length - 1 ) this . setState ( prev => ( { ... prev , isPlayingIndex : 0 } ) ) ;
222+ // if (isPlayingIndex >= this.state.data.length - 1) isPlayingIndex = 0 ;
230223
231224 const { id, action, state } = data [ isPlayingIndex + 1 ] ;
232225 this . setState ( prev => ( {
@@ -289,6 +282,7 @@ class App extends Component {
289282 setIsRecording,
290283 isRecording,
291284 filteredData,
285+ searchField,
292286 } = this . state ;
293287
294288 return (
@@ -304,6 +298,7 @@ class App extends Component {
304298 activeEventId = { id }
305299 searchChange = { this . searchChange }
306300 filteredData = { filteredData }
301+ searchField = { searchField }
307302 />
308303 ) }
309304 right = {
@@ -331,5 +326,4 @@ class App extends Component {
331326 ) ;
332327 }
333328}
334-
335- export default App ;
329+ export default App ;
0 commit comments