@@ -24,7 +24,6 @@ const findName = (index, obj) => {
2424 objChildArray . push ( findName ( index , objChild ) ) ;
2525 }
2626 }
27- console . log ( objChildArray ) ;
2827 // eslint-disable-next-line no-restricted-syntax
2928 for ( const objChildName of objChildArray ) {
3029 if ( objChildName ) {
@@ -40,36 +39,37 @@ export const mainSlice = createSlice({
4039
4140 emptySnapshots : ( state ) => {
4241 const { tabs, currentTab, port } = state ;
43- console . log ( "this is state 2" , current ( state ) ) ;
4442
45- port . postMessage ( { action : 'emptySnap' , tabId : currentTab } ) ;
43+ port . postMessage ( { action : 'emptySnap' , tabId : currentTab } ) ; //communicate with background.js (service worker)
4644
45+ // properties associated with timetravel + seek bar
4746 tabs [ currentTab ] . sliderIndex = 0 ;
4847 tabs [ currentTab ] . viewIndex = 0 ;
4948 tabs [ currentTab ] . playing = false ;
5049
51- const lastSnapshot = tabs [ currentTab ] . snapshots [ tabs [ currentTab ] . snapshots . length - 1 ] ;
50+ const lastSnapshot = tabs [ currentTab ] . snapshots [ tabs [ currentTab ] . snapshots . length - 1 ] ; // the most recent snapshot
5251
53- tabs [ currentTab ] . hierarchy . stateSnapshot = { ...lastSnapshot } ;
54- tabs [ currentTab ] . hierarchy . children = [ ] ;
55- tabs [ currentTab ] . snapshots = [ lastSnapshot ] ;
52+ tabs [ currentTab ] . hierarchy . stateSnapshot = { ...lastSnapshot } ; // resets hierarchy to page last state recorded
53+ tabs [ currentTab ] . hierarchy . children = [ ] ; // resets hierarchy
54+ tabs [ currentTab ] . snapshots = [ lastSnapshot ] ; // resets snapshots to page last state recorded
5655
56+ // resets currLocation to page last state recorded
5757 tabs [ currentTab ] . currLocation = tabs [ currentTab ] . hierarchy ;
58- console . log ( 'tabsHieracyh' , tabs [ currentTab ] . hierarchy ) ;
5958 tabs [ currentTab ] . index = 1 ;
6059 tabs [ currentTab ] . currParent = 0 ;
6160 tabs [ currentTab ] . currBranch = 1 ;
6261 tabs [ currentTab ] . seriesSavedStatus = false ;
6362 } ,
6463
6564 addNewSnapshots : ( state , action ) => {
66- const { tabs } = state ;
65+ const { tabs, currentTab } = state ;
6766
6867 const { payload } = action ;
6968 Object . keys ( tabs ) . forEach ( tab => {
7069 if ( ! payload [ tab ] )
7170 delete tabs [ tab ] ;
7271 else {
72+ // maintain isExpanded prop from old stateSnapshot to preserve componentMap expansion
7373 const persistIsExpanded = ( newNode , oldNode ) => {
7474 newNode . isExpanded = oldNode ? oldNode . isExpanded : true ;
7575 if ( newNode . children ) {
@@ -91,6 +91,10 @@ export const mainSlice = createSlice({
9191 } ;
9292 }
9393 } ) ;
94+
95+ // only set first tab if current tab is non existent
96+ const firstTab = parseInt ( Object . keys ( payload ) [ 0 ] , 10 ) ;
97+ if ( currentTab === undefined || currentTab === null ) state . currentTab = firstTab ;
9498 } ,
9599
96100 initialConnect : ( state , action ) => {
@@ -117,9 +121,7 @@ export const mainSlice = createSlice({
117121 } ,
118122
119123 setPort : ( state , action ) => {
120- console . log ( 'port start: ' , current ( state ) )
121124 state . port = action . payload ;
122- console . log ( 'port end: ' , current ( state ) )
123125 } ,
124126
125127 setTab : ( state , action ) => {
@@ -174,43 +176,18 @@ export const mainSlice = createSlice({
174176
175177 changeView : ( state , action ) => {
176178 const { tabs, currentTab} = state ;
177- console . log ( 'this is state:' , current ( state ) )
178- console . log ( 'this is tabs:' , tabs )
179- console . log ( 'this is currentabs:' , currentTab )
180- console . log ( 'this is tabs[currentab]' , tabs [ currentTab ] )
181179 const { viewIndex} = tabs [ currentTab ] || { } ;
182- console . log ( 'hi this is viewIndex:' , viewIndex ) ;
183- console . log ( 'this is action payload' , action . payload )
180+ // unselect view if same index was selected
184181 tabs [ currentTab ] . viewIndex = viewIndex === action . payload ? - 1 : action . payload ;
185- // if (viewIndex === action.payload) tabs[currentTab].viewIndex = -1;
186- // else tabs[currentTab].viewIndex = action.payload;
187- // tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
188-
189- // case types.CHANGE_VIEW: {
190- // // unselect view if same index was selected
191- // // console.log('action:', action)
192- // // console.log('state: ', state)
193- // if (viewIndex === action.payload) tabs[currentTab].viewIndex = -1;
194- // else tabs[currentTab].viewIndex = action.payload;
195- // // update currLocation
196- // // tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
197- // break;
198- // }
199-
200182 } ,
201183
202184 changeSlider : ( state , action ) => {
203185 const { port, currentTab, tabs } = state ;
204186 const { hierarchy, snapshots } = tabs [ currentTab ] || { } ;
205187
206- console . log ( 'this is PORT' , port ) ;
207- console . log ( 'this is hierarchy' , hierarchy ) ;
208- console . log ( 'this is SNapshots' , snapshots ) ;
209-
188+ // finds the name by the action.payload parsing through the hierarchy to send to background.js the current name in the jump action
210189 const nameFromIndex = findName ( action . payload , hierarchy ) ;
211-
212- // console.log('this is action payload', action.payload);
213- // console.log('this is nameFromIndex', nameFromIndex);
190+ // nameFromIndex is a number based on which jump button is pushed
214191
215192 port . postMessage ( {
216193 action : 'jumpToSnap' ,
@@ -234,8 +211,6 @@ export const mainSlice = createSlice({
234211 clearInterval ( intervalId ) ;
235212 tabs [ currentTab ] . playing = false ;
236213 tabs [ currentTab ] . intervalId = null ;
237- console . log ( 'pause: state end' , current ( state ) ) ;
238-
239214 } ,
240215
241216 launchContentScript : ( state , action ) => {
@@ -408,7 +383,7 @@ export const mainSlice = createSlice({
408383
409384 tutorialSaveSeriesToggle : ( state , action ) => {
410385 const { tabs, currentTab } = state ;
411- tabs [ currentTab ] = { ...tabs [ currentTab ] , seriesSavedStatus : action . payload }
386+ tabs [ currentTab ] = { ...tabs [ currentTab ] , seriesSavedStatus : action . payload } // sets the tab[currentTab]'s 'seriesSavedStatus' property to the payload.
412387 } ,
413388
414389 onHover : ( state , action ) => {
@@ -437,7 +412,6 @@ export const mainSlice = createSlice({
437412 const { newSeries, newSeriesName } = action . payload ;
438413 if ( ! tabs [ currentTab ] . seriesSavedStatus ) {
439414 tabs [ currentTab ] = { ...tabs [ currentTab ] , seriesSavedStatus : 'inputBoxOpen' } ;
440- //testing return to fix save functionality
441415 return ;
442416 }
443417 // Runs if series name input box is active.
@@ -449,7 +423,6 @@ export const mainSlice = createSlice({
449423 seriesArray . push ( newSeries ) ;
450424 localStorage . setItem ( 'project' , JSON . stringify ( seriesArray ) ) ;
451425 tabs [ currentTab ] = { ...tabs [ currentTab ] , seriesSavedStatus : 'saved' } ;
452- //testing return to fix save functionality instead of break
453426 return ;
454427 }
455428 } ,
0 commit comments