@@ -71,7 +71,11 @@ class App extends Component {
7171 // adds listener to the effects that are gonna be sent from
7272 // our edited useReducer from the 'react' library.
7373 chrome . runtime . onConnect . addListener ( ( port ) => {
74- if ( port . name !== 'injected-app' ) return ;
74+ // if our port is already open with the extension script,
75+ // we don't want to change this.portToExtension no more. We want
76+ // to keep every instance of the App associated with the specific
77+ // extension script that can communicated with the injected timeTravel.
78+ if ( port . name !== 'injected-app' || this . portToExtension ) return ;
7579
7680 this . portToExtension = port ;
7781
@@ -90,11 +94,10 @@ class App extends Component {
9094 // search field
9195 const { searchField } = this . state ;
9296 const newDataActionType = newData . action . type . toLowerCase ( ) ;
93-
94- // get the date everytime an action fires and add it to state
9597
9698 const eventTime = Date . now ( ) ;
97-
99+
100+ // get the date everytime an action fires and add it to state
98101 if ( newDataActionType . includes ( searchField . toLowerCase ( ) ) ) {
99102 this . setState ( state => ( {
100103 data : [ ...state . data , newData ] ,
@@ -140,18 +143,18 @@ class App extends Component {
140143 }
141144
142145 setIsRecording ( ) {
143- // This variable will prevent the app from refreshing when we refresh
144- // the userpage.
145- this . justStartedRecording = true ;
146- const { isRecording, hasInjectedScript } = this . state ;
146+ const { isRecording } = this . state ;
147147 this . setState ( state => ( {
148148 isRecording : ! state . isRecording ,
149149 } ) ) ;
150150
151151 // if we are hitting the pause or re-starting the record session
152- if ( isRecording || hasInjectedScript ) return ;
152+ if ( isRecording || this . hasInjectedScript ) return ;
153153
154- this . setState ( { hasInjectedScript : true } ) ;
154+ // This variable will prevent the app from refreshing when we refresh
155+ // the userpage.
156+ this . justStartedRecording = true ;
157+ this . hasInjectedScript = true ;
155158
156159 // we query the active window so we can send it to the background script
157160 // so it knows on which URL to run our devtool.
@@ -167,11 +170,13 @@ class App extends Component {
167170 }
168171
169172 actionInPlay ( ) {
170- const { data, isPlayingIndex, isPlaying } = this . state ;
173+ const { data, isPlayingIndex } = this . state ;
171174
172175 setTimeout ( ( ) => {
173176 this . toTheFuture ( ) ;
174- if ( isPlaying && isPlayingIndex + 1 < data . length - 1 ) {
177+ // We CANT deconstruct isPlaying because we want it to be the value
178+ // when this function gets executed - 1000s later.
179+ if ( this . state . isPlaying && isPlayingIndex + 1 < data . length - 1 ) {
175180 this . actionInPlay ( ) ;
176181 } else {
177182 this . setState ( { isPlaying : false } ) ;
@@ -260,6 +265,7 @@ class App extends Component {
260265 if ( isPlayingIndex === 0 ) return ;
261266
262267 if ( ! this . portToExtension ) return console . error ( 'No connection on stored port.' ) ;
268+
263269 this . portToExtension . postMessage ( {
264270 type : 'TIMETRAVEL' ,
265271 direction : 'backwards' ,
@@ -278,11 +284,13 @@ class App extends Component {
278284
279285 resetApp ( ) {
280286 if ( this . justStartedRecording ) {
281- console . log ( 'not reseting...' ) ;
282- this . justStartedRecording = false ;
287+ // hacky: some pages will fire update twice on the background script
288+ setTimeout ( ( ) => this . justStartedRecording = false , 50 ) ;
283289 return ;
284290 }
285- console . log ( 'reseting...' ) ;
291+
292+ this . justStartedRecording = false ;
293+ this . hasInjectedScript = false ;
286294 this . setState ( {
287295 data : [ ] ,
288296 searchField : '' ,
@@ -294,6 +302,7 @@ class App extends Component {
294302 action : { } ,
295303 state : { } ,
296304 prevState : { } ,
305+ eventTimes : [ ] ,
297306 } ) ;
298307 }
299308
0 commit comments