@@ -48,6 +48,7 @@ class App extends Component {
4848 } ;
4949
5050 this . portToExtension = null ;
51+ this . justStartedRecording = false ;
5152
5253 this . addActionToView = this . addActionToView . bind ( this ) ;
5354 this . toTheFuture = this . toTheFuture . bind ( this ) ;
@@ -64,21 +65,31 @@ class App extends Component {
6465 // adds listener to the effects that are gonna be sent from
6566 // our edited useReducer from the 'react' library.
6667 chrome . runtime . onConnect . addListener ( ( port ) => {
67- if ( port . name === 'injected-app' ) {
68- this . portToExtension = port ;
69-
70- port . onMessage . addListener ( ( msg ) => {
71- const newData = {
72- action : msg . action ,
73- state : msg . state ,
74- id : this . state . data . length ,
75- } ;
76- this . setState ( ( state ) => ( {
68+ if ( port . name !== 'injected-app' ) return ;
69+
70+ this . portToExtension = port ;
71+
72+ port . onMessage . addListener ( ( msg ) => {
73+ const newData = {
74+ action : msg . action ,
75+ state : msg . state ,
76+ id : this . state . data . length ,
77+ } ;
78+
79+ const { searchField } = this . state ;
80+ const newDataActionType = newData . action . type . toLowerCase ( ) ;
81+
82+ if ( newDataActionType . includes ( searchField . toLowerCase ( ) ) ) {
83+ this . setState ( state => ( {
7784 data : [ ...state . data , newData ] ,
7885 filteredData : [ ...state . data , newData ] ,
7986 } ) ) ;
80- } ) ;
81- }
87+ } else {
88+ this . setState ( state => ( {
89+ data : [ ...state . data , newData ] ,
90+ } ) ) ;
91+ }
92+ } ) ;
8293 } ) ;
8394
8495 // We listen to the message from devtools.js (sent originally from
@@ -93,8 +104,6 @@ class App extends Component {
93104 } ) ;
94105 }
95106
96-
97-
98107 // functionality to change 'play' button to 'stop'
99108 setIsPlaying ( ) {
100109 if ( this . state . isPlayingIndex > this . state . data . length - 1 ) {
@@ -110,9 +119,11 @@ class App extends Component {
110119 }
111120 }
112121
113- // functionality to change 'record' button to 'pause'
114122 setIsRecording ( ) {
115- console . log ( 'setIsRecording:' , this . state . isRecording )
123+ // This variable will prevent the app from refreshing when we refresh
124+ // the userpage.
125+ this . justStartedRecording = true ;
126+
116127 this . setState ( state => ( {
117128 isRecording : ! state . isRecording ,
118129 } ) ) ;
@@ -206,6 +217,9 @@ class App extends Component {
206217
207218 // function to travel to the FUTURE
208219 toTheFuture ( ) {
220+ const { data, isPlayingIndex } = this . state ;
221+ if ( isPlayingIndex === data . length - 1 ) return ;
222+
209223 if ( ! this . portToExtension ) return console . error ( 'No connection on stored port.' ) ;
210224 this . portToExtension . postMessage ( {
211225 type : 'TIMETRAVEL' ,
@@ -214,7 +228,6 @@ class App extends Component {
214228
215229 // if (isPlayingIndex >= this.state.data.length - 1) isPlayingIndex = 0;
216230
217- const { data, isPlayingIndex } = this . state ;
218231 const { id, action, state } = data [ isPlayingIndex + 1 ] ;
219232 this . setState ( prev => ( {
220233 ...prev ,
@@ -229,29 +242,32 @@ class App extends Component {
229242
230243 // function to travel to the PAST
231244 toThePast ( ) {
245+ const { data, isPlayingIndex } = this . state ;
246+ if ( isPlayingIndex === 0 ) return ;
247+
232248 if ( ! this . portToExtension ) return console . error ( 'No connection on stored port.' ) ;
233249 this . portToExtension . postMessage ( {
234250 type : 'TIMETRAVEL' ,
235251 direction : 'backwards' ,
236252 } ) ;
237253
238- const { data, isPlayingIndex } = this . state ;
239-
240- if ( isPlayingIndex === 0 ) {
241- console . log ( 'is playingIdx in toThePast is 0' ) ;
242- } else {
243- const { id, action, state } = data [ isPlayingIndex - 1 ] ;
244- this . setState ( prev => ( {
245- ...prev ,
246- id,
247- action,
248- state,
249- isPlayingIndex : isPlayingIndex - 1 ,
250- } ) ) ;
251- }
254+ const { id, action, state } = data [ isPlayingIndex - 1 ] ;
255+ this . setState ( prev => ( {
256+ ...prev ,
257+ id,
258+ action,
259+ state,
260+ isPlayingIndex : isPlayingIndex - 1 ,
261+ } ) ) ;
252262 }
253263
254264 resetApp ( ) {
265+ if ( this . justStartedRecording ) {
266+ console . log ( 'not reseting...' ) ;
267+ this . justStartedRecording = false ;
268+ return ;
269+ }
270+ console . log ( 'reseting...' ) ;
255271 this . setState ( {
256272 data : [ ] ,
257273 searchField : '' ,
0 commit comments