@@ -71,6 +71,10 @@ 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 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.
7478 if ( port . name !== 'injected-app' || this . portToExtension ) return ;
7579
7680 this . portToExtension = port ;
@@ -91,10 +95,9 @@ class App extends Component {
9195 const { searchField } = this . state ;
9296 const newDataActionType = newData . action . type . toLowerCase ( ) ;
9397
94- // get the date everytime an action fires and add it to state
95-
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 ] ,
@@ -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,7 +265,7 @@ class App extends Component {
260265 if ( isPlayingIndex === 0 ) return ;
261266
262267 if ( ! this . portToExtension ) return console . error ( 'No connection on stored port.' ) ;
263- console . log ( 'Sending timetravel PAST to extension' ) ;
268+
264269 this . portToExtension . postMessage ( {
265270 type : 'TIMETRAVEL' ,
266271 direction : 'backwards' ,
@@ -279,7 +284,8 @@ class App extends Component {
279284
280285 resetApp ( ) {
281286 if ( this . justStartedRecording ) {
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 }
285291
0 commit comments