@@ -24,7 +24,6 @@ const findName = (index, obj) => {
24
24
objChildArray . push ( findName ( index , objChild ) ) ;
25
25
}
26
26
}
27
- console . log ( objChildArray ) ;
28
27
// eslint-disable-next-line no-restricted-syntax
29
28
for ( const objChildName of objChildArray ) {
30
29
if ( objChildName ) {
@@ -40,36 +39,37 @@ export const mainSlice = createSlice({
40
39
41
40
emptySnapshots : ( state ) => {
42
41
const { tabs, currentTab, port } = state ;
43
- console . log ( "this is state 2" , current ( state ) ) ;
44
42
45
- port . postMessage ( { action : 'emptySnap' , tabId : currentTab } ) ;
43
+ port . postMessage ( { action : 'emptySnap' , tabId : currentTab } ) ; //communicate with background.js (service worker)
46
44
45
+ // properties associated with timetravel + seek bar
47
46
tabs [ currentTab ] . sliderIndex = 0 ;
48
47
tabs [ currentTab ] . viewIndex = 0 ;
49
48
tabs [ currentTab ] . playing = false ;
50
49
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
52
51
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
56
55
56
+ // resets currLocation to page last state recorded
57
57
tabs [ currentTab ] . currLocation = tabs [ currentTab ] . hierarchy ;
58
- console . log ( 'tabsHieracyh' , tabs [ currentTab ] . hierarchy ) ;
59
58
tabs [ currentTab ] . index = 1 ;
60
59
tabs [ currentTab ] . currParent = 0 ;
61
60
tabs [ currentTab ] . currBranch = 1 ;
62
61
tabs [ currentTab ] . seriesSavedStatus = false ;
63
62
} ,
64
63
65
64
addNewSnapshots : ( state , action ) => {
66
- const { tabs } = state ;
65
+ const { tabs, currentTab } = state ;
67
66
68
67
const { payload } = action ;
69
68
Object . keys ( tabs ) . forEach ( tab => {
70
69
if ( ! payload [ tab ] )
71
70
delete tabs [ tab ] ;
72
71
else {
72
+ // maintain isExpanded prop from old stateSnapshot to preserve componentMap expansion
73
73
const persistIsExpanded = ( newNode , oldNode ) => {
74
74
newNode . isExpanded = oldNode ? oldNode . isExpanded : true ;
75
75
if ( newNode . children ) {
@@ -91,6 +91,10 @@ export const mainSlice = createSlice({
91
91
} ;
92
92
}
93
93
} ) ;
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 ;
94
98
} ,
95
99
96
100
initialConnect : ( state , action ) => {
@@ -117,9 +121,7 @@ export const mainSlice = createSlice({
117
121
} ,
118
122
119
123
setPort : ( state , action ) => {
120
- console . log ( 'port start: ' , current ( state ) )
121
124
state . port = action . payload ;
122
- console . log ( 'port end: ' , current ( state ) )
123
125
} ,
124
126
125
127
setTab : ( state , action ) => {
@@ -174,43 +176,18 @@ export const mainSlice = createSlice({
174
176
175
177
changeView : ( state , action ) => {
176
178
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 ] )
181
179
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
184
181
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
-
200
182
} ,
201
183
202
184
changeSlider : ( state , action ) => {
203
185
const { port, currentTab, tabs } = state ;
204
186
const { hierarchy, snapshots } = tabs [ currentTab ] || { } ;
205
187
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
210
189
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
214
191
215
192
port . postMessage ( {
216
193
action : 'jumpToSnap' ,
@@ -234,8 +211,6 @@ export const mainSlice = createSlice({
234
211
clearInterval ( intervalId ) ;
235
212
tabs [ currentTab ] . playing = false ;
236
213
tabs [ currentTab ] . intervalId = null ;
237
- console . log ( 'pause: state end' , current ( state ) ) ;
238
-
239
214
} ,
240
215
241
216
launchContentScript : ( state , action ) => {
@@ -408,7 +383,7 @@ export const mainSlice = createSlice({
408
383
409
384
tutorialSaveSeriesToggle : ( state , action ) => {
410
385
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.
412
387
} ,
413
388
414
389
onHover : ( state , action ) => {
@@ -437,7 +412,6 @@ export const mainSlice = createSlice({
437
412
const { newSeries, newSeriesName } = action . payload ;
438
413
if ( ! tabs [ currentTab ] . seriesSavedStatus ) {
439
414
tabs [ currentTab ] = { ...tabs [ currentTab ] , seriesSavedStatus : 'inputBoxOpen' } ;
440
- //testing return to fix save functionality
441
415
return ;
442
416
}
443
417
// Runs if series name input box is active.
@@ -449,7 +423,6 @@ export const mainSlice = createSlice({
449
423
seriesArray . push ( newSeries ) ;
450
424
localStorage . setItem ( 'project' , JSON . stringify ( seriesArray ) ) ;
451
425
tabs [ currentTab ] = { ...tabs [ currentTab ] , seriesSavedStatus : 'saved' } ;
452
- //testing return to fix save functionality instead of break
453
426
return ;
454
427
}
455
428
} ,
0 commit comments