@@ -45,11 +45,16 @@ class App extends Component {
4545 isPlaying : false ,
4646 isRecording : false ,
4747 isPlayingIndex : 0 ,
48+ id : 0 ,
49+ action : { } ,
50+ state : { } ,
51+ prevState : { } ,
4852 eventTimes : [ ] ,
4953 } ;
5054
5155 this . portToExtension = null ;
5256 this . justStartedRecording = false ;
57+ this . hasInjectedScript = false ;
5358
5459 this . addActionToView = this . addActionToView . bind ( this ) ;
5560 this . toTheFuture = this . toTheFuture . bind ( this ) ;
@@ -71,9 +76,14 @@ class App extends Component {
7176 this . portToExtension = port ;
7277
7378 port . onMessage . addListener ( ( msg ) => {
79+ // If the user paused the recording session, we return
80+ const { isRecording } = this . state ;
81+ if ( ! isRecording ) return ;
82+
7483 const newData = {
7584 action : msg . action ,
7685 state : msg . state ,
86+ prevState : msg . prevState ,
7787 id : this . state . data . length ,
7888 } ;
7989
@@ -115,7 +125,8 @@ class App extends Component {
115125
116126 // functionality to change 'play' button to 'stop'
117127 setIsPlaying ( ) {
118- if ( this . state . isPlayingIndex >= this . state . data . length - 1 ) {
128+ const { isPlayingIndex, data } = this . state ;
129+ if ( isPlayingIndex >= data . length - 1 ) {
119130 return ;
120131 }
121132
@@ -130,19 +141,24 @@ class App extends Component {
130141
131142 setIsRecording ( ) {
132143 // This variable will prevent the app from refreshing when we refresh
133- // the userpage.
144+ // the userpage.
134145 this . justStartedRecording = true ;
135-
146+ const { isRecording , hasInjectedScript } = this . state ;
136147 this . setState ( state => ( {
137148 isRecording : ! state . isRecording ,
138149 } ) ) ;
139150
151+ // if we are hitting the pause or re-starting the record session
152+ if ( isRecording || hasInjectedScript ) return ;
153+
154+ this . setState ( { hasInjectedScript : true } ) ;
155+
140156 // we query the active window so we can send it to the background script
141157 // so it knows on which URL to run our devtool.
142158 chrome . tabs . query ( { active : true , currentWindow : true } , ( tabs ) => {
143159 const { url } = tabs [ 0 ] ;
144160
145- // backgroundPort is a variable made avaiable by the devtools.js
161+ // backgroundPort is a variable made avaiable by the devtools.js
146162 backgroundPort . postMessage ( {
147163 turnOnDevtool : true ,
148164 url,
@@ -151,11 +167,11 @@ class App extends Component {
151167 }
152168
153169 actionInPlay ( ) {
154- const { data, isPlayingIndex } = this . state ;
170+ const { data, isPlayingIndex, isPlaying } = this . state ;
155171
156172 setTimeout ( ( ) => {
157173 this . toTheFuture ( ) ;
158- if ( this . state . isPlaying && isPlayingIndex + 1 < data . length - 1 ) {
174+ if ( isPlaying && isPlayingIndex + 1 < data . length - 1 ) {
159175 this . actionInPlay ( ) ;
160176 } else {
161177 this . setState ( { isPlaying : false } ) ;
@@ -169,10 +185,10 @@ class App extends Component {
169185 const { data } = this . state ;
170186 const actionToView = data . filter ( action => e . target . id === String ( action . id ) ) ;
171187 const {
172- action, id, state,
188+ action, id, state, prevState ,
173189 } = actionToView [ 0 ] ;
174190 this . setState ( {
175- action, id, state,
191+ action, id, state, prevState ,
176192 } ) ;
177193 }
178194
@@ -197,14 +213,15 @@ class App extends Component {
197213 // time travel bar change
198214 handleBarChange ( e ) {
199215 const { data, isPlayingIndex } = this . state ;
200- const { id, action, state } = data [ e . target . value ] ;
216+ const { id, action, state, prevState } = data [ e . target . value ] ;
201217 // forward or past
202218 const currentIsPlayingIndex = e . target . value ;
203219 const forward = currentIsPlayingIndex > isPlayingIndex ;
204220 this . setState ( {
205221 id,
206222 action,
207223 state,
224+ prevState,
208225 isPlayingIndex : parseInt ( currentIsPlayingIndex ) ,
209226 } ) ;
210227 // Displays to screen
@@ -226,18 +243,15 @@ class App extends Component {
226243 direction : 'forward' ,
227244 } ) ;
228245
229- // if (isPlayingIndex >= this.state.data.length - 1) isPlayingIndex = 0;
230-
231- const { id, action, state } = data [ isPlayingIndex + 1 ] ;
246+ const { id, action, state, prevState } = data [ isPlayingIndex + 1 ] ;
232247 this . setState ( prev => ( {
233248 ...prev ,
234249 id,
235250 action,
236251 state,
252+ prevState,
237253 isPlayingIndex : isPlayingIndex + 1 ,
238254 } ) ) ;
239-
240- console . log ( 'isPlayingIndex' , this . state . isPlayingIndex ) ;
241255 }
242256
243257 // function to travel to the PAST
@@ -251,12 +265,13 @@ class App extends Component {
251265 direction : 'backwards' ,
252266 } ) ;
253267
254- const { id, action, state } = data [ isPlayingIndex - 1 ] ;
268+ const { id, action, state, prevState } = data [ isPlayingIndex - 1 ] ;
255269 this . setState ( prev => ( {
256270 ...prev ,
257271 id,
258272 action,
259273 state,
274+ prevState,
260275 isPlayingIndex : isPlayingIndex - 1 ,
261276 } ) ) ;
262277 }
@@ -275,6 +290,10 @@ class App extends Component {
275290 isPlaying : false ,
276291 isRecording : false ,
277292 isPlayingIndex : 0 ,
293+ id : 0 ,
294+ action : { } ,
295+ state : { } ,
296+ prevState : { } ,
278297 } ) ;
279298 }
280299
@@ -284,12 +303,12 @@ class App extends Component {
284303 id,
285304 state,
286305 data,
287- setIsPlaying,
288306 isPlaying,
289- setIsRecording,
290307 isRecording,
291308 filteredData,
292309 searchField,
310+ isPlayingIndex,
311+ prevState,
293312 eventTimes,
294313 } = this . state ;
295314
@@ -316,6 +335,7 @@ class App extends Component {
316335 action = { action }
317336 id = { id }
318337 actionState = { state }
338+ prevState = { prevState }
319339 />
320340 ) }
321341 />
@@ -324,7 +344,7 @@ class App extends Component {
324344 toTheFuture = { this . toTheFuture }
325345 toThePast = { this . toThePast }
326346 isPlaying = { isPlaying }
327- isPlayingIndex = { this . state . isPlayingIndex }
347+ isPlayingIndex = { isPlayingIndex }
328348 isRecording = { isRecording }
329349 setIsPlaying = { this . setIsPlaying }
330350 setIsRecording = { this . setIsRecording }
@@ -335,4 +355,5 @@ class App extends Component {
335355 ) ;
336356 }
337357}
358+
338359export default App ;
0 commit comments