Skip to content

Commit a53c7ed

Browse files
committed
import reducer in mainReducer and background js fixed
1 parent 4c459d5 commit a53c7ed

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

src/app/containers/ButtonsContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function ButtonsContainer(): JSX.Element {
8181
{paused ? <FontAwesomeIcon icon={faLock} /> : <FontAwesomeIcon icon={faUnlock} />}
8282
{paused ? 'Locked' : 'Unlocked'}
8383
</button>
84-
<button className='export-button' type='button' onClick={() => exportHandler(snapshots)}>
84+
<button className='export-button' type='button' onClick={() => exportHandler(tabs[currentTab])}>
8585
<FontAwesomeIcon icon={faDownload} />
8686
Download
8787
</button>

src/app/reducers/mainReducer.js

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,28 @@ export default (state, action) =>
185185
break;
186186
}
187187
case types.EMPTY: {
188-
// send msg to background script
189188
console.log('-----clear snapshots reducer----')
190189
console.log('state before:', state.tabs[currentTab])
191190

192-
port.postMessage({ action: 'emptySnap', tabId: currentTab });
191+
// send msg to background script
192+
port.postMessage({ action: 'emptySnap', tabId: currentTab }); //communicate with background.js
193+
194+
// properties associated with timetravel + seek bar
193195
tabs[currentTab].sliderIndex = 0;
194196
tabs[currentTab].viewIndex = 0;
195197
tabs[currentTab].playing = false;
196-
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+
197201
// resets hierarchy to page last state recorded
198202
tabs[currentTab].hierarchy.stateSnapshot = { ...lastSnapshot };
203+
199204
// resets hierarchy
200205
tabs[currentTab].hierarchy.children = [];
206+
201207
// resets snapshots to page last state recorded
202208
tabs[currentTab].snapshots = [lastSnapshot];
209+
203210
// resets currLocation to page last state recorded
204211
tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
205212
tabs[currentTab].index = 1;
@@ -216,16 +223,40 @@ export default (state, action) =>
216223
// Log the value of tabs[currentTab].snapshots before the update
217224
console.log('-----import snapshots reducer----')
218225
console.log('state before:', state.tabs[currentTab])
219-
226+
console.log('action payload:', action.payload)
220227

221228
port.postMessage({
222229
action: 'import',
223-
payload: action.payload,
230+
payload: action.payload, //.snapshots,
224231
tabId: currentTab,
225232
});
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+
226257

227-
228-
tabs[currentTab].snapshots = action.payload;
258+
//============
259+
//tabs[currentTab].snapshots = action.payload.snapshots;
229260

230261

231262

src/extension/background.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,26 @@ chrome.runtime.onConnect.addListener((port) => {
181181

182182
switch (action) {
183183
case 'import': // create a snapshot property on tabId and set equal to tabs object
184+
const savedSnapshot = payload
185+
console.log('background.js savedSnapshot:', savedSnapshot)
184186
// may need do something like filter payload from stateless
185-
tabsObj[tabId].snapshots = payload;
187+
tabsObj[tabId].snapshots = savedSnapshot.snapshots;
188+
189+
// reset snapshots to page last state recorded
190+
tabsObj[tabId].snapshots = savedSnapshot.snapshots
191+
192+
193+
194+
// resets hierarchy
195+
tabsObj[tabId].hierarchy.children = savedSnapshot.hierarchy.children;
196+
// resets hierarchy to page last state recorded
197+
tabsObj[tabId].hierarchy.stateSnapshot = savedSnapshot.hierarchy.stateSnapshot
198+
// resets currLocation to page last state recorded
199+
tabsObj[tabId].currLocation = savedSnapshot.currLocation;
200+
tabsObj[tabId].index = savedSnapshot.index;
201+
tabsObj[tabId].currParent = savedSnapshot.currParent;
202+
tabsObj[tabId].currBranch = savedSnapshot.currBranch;
203+
186204
return true;
187205
case 'emptySnap':
188206
// reset snapshots to page last state recorded

0 commit comments

Comments
 (0)