@@ -82,11 +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 ] ,
85+ isPlayingIndex : state . data . length ,
86+ filteredData : [ ...state . filteredData , newData ] ,
8687 } ) ) ;
8788 } else {
8889 this . setState ( state => ( {
8990 data : [ ...state . data , newData ] ,
91+ isPlayingIndex : state . data . length ,
9092 } ) ) ;
9193 }
9294 } ) ;
@@ -106,8 +108,8 @@ class App extends Component {
106108
107109 // functionality to change 'play' button to 'stop'
108110 setIsPlaying ( ) {
109- if ( this . state . isPlayingIndex > this . state . data . length - 1 ) {
110- this . setState ( { isPlayingIndex : 0 } ) ;
111+ if ( this . state . isPlayingIndex >= this . state . data . length - 1 ) {
112+ return ;
111113 }
112114
113115 let { isPlaying } = this . state ;
@@ -142,20 +144,11 @@ 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 ( { 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 {
161154 this . setState ( { isPlaying : false } ) ;
@@ -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 = {
0 commit comments