Skip to content

Commit 5793383

Browse files
authored
Merge pull request #13 from oslabs-beta/oliver/ax-time-travel
Refactored Clear Button (bug fix)
2 parents f90ad7f + a02dee0 commit 5793383

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

src/app/slices/mainSlice.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,31 @@ export const mainSlice = createSlice({
4646
tabs[currentTab].viewIndex = 0;
4747
tabs[currentTab].playing = false;
4848

49-
const lastSnapshot = tabs[currentTab].snapshots[tabs[currentTab].snapshots.length - 1]; // the most recent snapshot
50-
51-
tabs[currentTab].hierarchy.stateSnapshot = { ...lastSnapshot }; // resets hierarchy to page last state recorded
49+
// REFACTORED TO HAVE CLEAR BUTTON KEEP CURRENT STATE OF DEMO APP RATHER THAN JUST THE LAST STATE RECORDED
50+
// PRIOR IMPLEMENTATION WAS FAILING TO RESET STATE OF DEMO APP UPON CLEAR
51+
// IF CHANGING, CHANGE BACKGROUND.JS TOO
52+
53+
// const lastSnapshot = tabs[currentTab].snapshots[tabs[currentTab].snapshots.length - 1]; // the most recent snapshot
54+
// const lastAxSnapshot = tabs[currentTab].axSnapshots[tabs[currentTab].axSnapshots.length - 1]; // the most recent snapshot
55+
const currSnapshot = tabs[currentTab].snapshots[tabs[currentTab].currLocation.index]; // the most recent snapshot
56+
const currAxSnapshot = tabs[currentTab].axSnapshots[tabs[currentTab].currLocation.index]; // the most recent snapshot
57+
58+
// tabs[currentTab].hierarchy.stateSnapshot = { ...lastSnapshot }; // resets hierarchy to page last state recorded
59+
// // not sure why shallow deep copy
60+
// tabs[currentTab].hierarchy.axSnapshot = lastAxSnapshot; // resets hierarchy to page last state recorded
61+
// tabs[currentTab].hierarchy.children = []; // resets hierarchy
62+
// tabs[currentTab].snapshots = [lastSnapshot]; // resets snapshots to page last state recorded
63+
// tabs[currentTab].axSnapshots = [lastAxSnapshot]; // resets snapshots to page last state recorded
64+
65+
tabs[currentTab].hierarchy.stateSnapshot = { ...currSnapshot }; // resets hierarchy to page last state recorded
66+
// not sure why shallow deep copy
67+
tabs[currentTab].hierarchy.axSnapshot = currAxSnapshot; // resets hierarchy to page last state recorded
5268
tabs[currentTab].hierarchy.children = []; // resets hierarchy
53-
tabs[currentTab].snapshots = [lastSnapshot]; // resets snapshots to page last state recorded
69+
tabs[currentTab].snapshots = [currSnapshot]; // resets snapshots to page last state recorded
70+
tabs[currentTab].axSnapshots = [currAxSnapshot]; // resets snapshots to page last state recorded
5471

5572
// resets currLocation to page last state recorded
56-
tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
73+
// tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
5774
tabs[currentTab].index = 1;
5875
tabs[currentTab].currParent = 0;
5976
tabs[currentTab].currBranch = 1;

src/extension/background.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,21 @@ chrome.runtime.onConnect.addListener((port) => {
264264

265265
// emptySnap actions comes through when the user uses the 'clear' button on the front end to clear the snapshot history and move slider back to 0 position
266266
case 'emptySnap':
267-
tabsObj[tabId].snapshots = [tabsObj[tabId].snapshots[tabsObj[tabId].snapshots.length - 1]]; // reset snapshots to page last state recorded
267+
// REFACTORED TO HAVE CLEAR BUTTON KEEP CURRENT STATE OF DEMO APP RATHER THAN JUST THE LAST STATE RECORDED
268+
// PRIOR IMPLEMENTATION WAS FAILING TO RESET STATE OF DEMO APP UPON CLEAR
269+
// IF CHANGING, CHANGE MAINSLICE.JS TOO
270+
tabsObj[tabId].snapshots = [tabsObj[tabId].snapshots[tabsObj[tabId].currLocation.index]]; // reset snapshots to current page state
268271
tabsObj[tabId].hierarchy.children = []; // resets hierarchy
269272
tabsObj[tabId].hierarchy.stateSnapshot = {
270-
// resets hierarchy to page last state recorded
273+
// resets hierarchy to current page state
274+
// not sure why they are doing a "shallow" deep copy
271275
...tabsObj[tabId].snapshots[0],
272276
};
273-
tabsObj[tabId].axSnapshots =
274-
tabsObj[tabId].axSnapshots[tabsObj[tabId].axSnapshots.length - 1];
275-
tabsObj[tabId].hierarchy.axSnapshot = tabsObj[tabId].axSnapshots[0]; //what about other hierarchy properties? Shouldn't those be reset as well?
276-
tabsObj[tabId].currLocation = tabsObj[tabId].hierarchy; // resets currLocation to page last state recorded
277+
tabsObj[tabId].axSnapshots = [
278+
tabsObj[tabId].axSnapshots[tabsObj[tabId].currLocation.index],
279+
]; // resets axSnapshots to current page state
280+
tabsObj[tabId].hierarchy.axSnapshot = tabsObj[tabId].axSnapshots[0]; // resets hierarchy to ax tree of current page state
281+
// tabsObj[tabId].currLocation = tabsObj[tabId].hierarchy; // resets currLocation to page last state recorded
277282
tabsObj[tabId].index = 1; //reset index
278283
tabsObj[tabId].currParent = 0; // reset currParent
279284
tabsObj[tabId].currBranch = 1; // reset currBranch
@@ -500,10 +505,14 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
500505
const previousSnap =
501506
tabsObj[tabId]?.currLocation?.stateSnapshot?.children[0]?.componentData?.actualDuration;
502507
const incomingSnap = request.payload.children[0].componentData.actualDuration;
503-
if (previousSnap === incomingSnap) break;
508+
if (previousSnap === incomingSnap) {
509+
console.log('background.js: previousSnap===incomingSnap');
510+
break;
511+
}
504512

505513
// Or if it is a snapShot after a jump, we don't record it.
506514
if (reloaded[tabId]) {
515+
console.log('background.js: reloaded[tabId]');
507516
// don't add anything to snapshot storage if tab is reloaded for the initial snapshot
508517
reloaded[tabId] = false;
509518
} else {
@@ -519,6 +528,8 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
519528
'background.js: bottom of recordSnap: tabsObj[tabId]:',
520529
JSON.parse(JSON.stringify(tabsObj[tabId])),
521530
);
531+
} else {
532+
console.log('background.js: tabsObj[tabId][index]');
522533
}
523534
}
524535

@@ -531,6 +542,8 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
531542
sourceTab,
532543
}),
533544
);
545+
} else {
546+
console.log('background.js: portsArr.length < 0');
534547
}
535548
break;
536549
}

0 commit comments

Comments
 (0)