1
1
import { produce } from 'immer' ;
2
2
import _ , { values } from 'lodash' ;
3
3
import * as types from '../constants/actionTypes.ts' ;
4
+ // import { current } from 'immer';
4
5
5
6
export default ( state , action ) =>
6
7
produce ( state , ( draft ) => {
7
8
const { port, currentTab, tabs } = draft ;
8
9
const { hierarchy, snapshots, mode, intervalId, viewIndex, sliderIndex } =
9
10
tabs [ currentTab ] || { } ;
10
11
12
+ // console.log('----consoles before reducer funcs!-----')
13
+ // console.log('state:', state)
14
+ //console.log(tabs[currentTab]);
15
+ //console.log('properties of tabs[currentTab]:', hierarchy, snapshots, mode, intervalId, viewIndex, sliderIndex)
16
+
17
+ //console.log('reducer file!', 'hierarchy:', hierarchy, 'tabs:', tabs)
18
+
11
19
// eslint-disable-next-line max-len
12
20
// function that finds the index in the hierarchy and extracts the name of the equivalent index to add to the post message
13
21
// eslint-disable-next-line consistent-return
@@ -36,6 +44,7 @@ export default (state, action) =>
36
44
switch ( action . type ) {
37
45
// This saves the series user wants to save to chrome local storage
38
46
case types . SAVE : {
47
+ console . log ( 'save action reducer!' , 'payload:' , action . payload ) ;
39
48
const { newSeries, newSeriesName } = action . payload ;
40
49
if ( ! tabs [ currentTab ] . seriesSavedStatus ) {
41
50
tabs [ currentTab ] = { ...tabs [ currentTab ] , seriesSavedStatus : 'inputBoxOpen' } ;
@@ -176,18 +185,28 @@ export default (state, action) =>
176
185
break ;
177
186
}
178
187
case types . EMPTY : {
188
+ console . log ( '-----clear snapshots reducer----' ) ;
189
+ console . log ( 'state before:' , state . tabs [ currentTab ] ) ;
190
+
179
191
// send msg to background script
180
- port . postMessage ( { action : 'emptySnap' , tabId : currentTab } ) ;
192
+ port . postMessage ( { action : 'emptySnap' , tabId : currentTab } ) ; //communicate with background.js
193
+
194
+ // properties associated with timetravel + seek bar
181
195
tabs [ currentTab ] . sliderIndex = 0 ;
182
196
tabs [ currentTab ] . viewIndex = 0 ;
183
197
tabs [ currentTab ] . playing = false ;
184
- const lastSnapshot = tabs [ currentTab ] . snapshots [ tabs [ currentTab ] . snapshots . length - 1 ] ;
198
+
199
+ const lastSnapshot = tabs [ currentTab ] . snapshots [ tabs [ currentTab ] . snapshots . length - 1 ] ; // first snapshot?
200
+
185
201
// resets hierarchy to page last state recorded
186
202
tabs [ currentTab ] . hierarchy . stateSnapshot = { ...lastSnapshot } ;
203
+
187
204
// resets hierarchy
188
205
tabs [ currentTab ] . hierarchy . children = [ ] ;
206
+
189
207
// resets snapshots to page last state recorded
190
208
tabs [ currentTab ] . snapshots = [ lastSnapshot ] ;
209
+
191
210
// resets currLocation to page last state recorded
192
211
tabs [ currentTab ] . currLocation = tabs [ currentTab ] . hierarchy ;
193
212
tabs [ currentTab ] . index = 1 ;
@@ -201,12 +220,47 @@ export default (state, action) =>
201
220
break ;
202
221
}
203
222
case types . IMPORT : {
223
+ // Log the value of tabs[currentTab].snapshots before the update
224
+ console . log ( '-----import snapshots reducer----' ) ;
225
+ console . log ( 'state before:' , state . tabs [ currentTab ] ) ;
226
+ console . log ( 'action payload:' , action . payload ) ;
227
+
204
228
port . postMessage ( {
205
229
action : 'import' ,
206
- payload : action . payload ,
230
+ payload : action . payload , //.snapshots,
207
231
tabId : currentTab ,
208
232
} ) ;
209
- tabs [ currentTab ] . snapshots = action . payload ;
233
+
234
+ //============
235
+ const savedSnapshot = action . payload ;
236
+
237
+ tabs [ currentTab ] . sliderIndex = savedSnapshot . sliderIndex ;
238
+ tabs [ currentTab ] . viewIndex = savedSnapshot . viewIndex ;
239
+ tabs [ currentTab ] . playing = false ;
240
+
241
+ // resets hierarchy to page last state recorded
242
+ tabs [ currentTab ] . hierarchy . stateSnapshot = savedSnapshot . hierarchy . stateSnapshot ;
243
+
244
+ // resets hierarchy
245
+ tabs [ currentTab ] . hierarchy . children = savedSnapshot . hierarchy . children ;
246
+
247
+ // resets snapshots to page last state recorded
248
+ tabs [ currentTab ] . snapshots = savedSnapshot . snapshots ;
249
+
250
+ // resets currLocation to page last state recorded
251
+ tabs [ currentTab ] . currLocation = tabs [ currentTab ] . hierarchy ;
252
+ tabs [ currentTab ] . index = savedSnapshot . index ;
253
+ tabs [ currentTab ] . currParent = savedSnapshot . currParent ;
254
+ tabs [ currentTab ] . currBranch = savedSnapshot . Branch ;
255
+ tabs [ currentTab ] . seriesSavedStatus = false ;
256
+
257
+ //============
258
+ //tabs[currentTab].snapshots = action.payload.snapshots;
259
+
260
+ // console.log('New snapshots:', action.payload);
261
+ // console.log('updated tabs[CurrentTab].snapshots:', tabs[currentTab].snapshots)
262
+ //console.log('state after:', state)
263
+
210
264
break ;
211
265
}
212
266
case types . TOGGLE_MODE : {
0 commit comments