Skip to content

Commit a02dee0

Browse files
committed
refactored clear button, which was keeping last state recorded without changing target app. Refactored clear button to keep only the current snapshot instead of only the last snapshot recorded
1 parent 6c1c4e1 commit a02dee0

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

src/app/slices/mainSlice.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +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-
const lastAxSnapshot = tabs[currentTab].axSnapshots[tabs[currentTab].axSnapshots.length - 1]; // the most recent snapshot
51-
52-
tabs[currentTab].hierarchy.stateSnapshot = { ...lastSnapshot }; // resets hierarchy to page last state recorded
53-
tabs[currentTab].hierarchy.axSnapshot = lastAxSnapshot; // 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
5468
tabs[currentTab].hierarchy.children = []; // resets hierarchy
55-
tabs[currentTab].snapshots = [lastSnapshot]; // resets snapshots to page last state recorded
56-
tabs[currentTab].axSnapshots = [lastAxSnapshot]; // 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
5771

5872
// resets currLocation to page last state recorded
59-
tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
73+
// tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
6074
tabs[currentTab].index = 1;
6175
tabs[currentTab].currParent = 0;
6276
tabs[currentTab].currBranch = 1;

src/extension/background.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +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
};
273277
tabsObj[tabId].axSnapshots = [
274-
tabsObj[tabId].axSnapshots[tabsObj[tabId].axSnapshots.length - 1],
275-
]; // resets axSnapshots to page last recorded
276-
tabsObj[tabId].hierarchy.axSnapshot = tabsObj[tabId].axSnapshots[0]; // resets hierarchy to page of last ax tree recorded
277-
// SHOULDN'T HIERARCHY.AXSNAPSHOT AND HIERARCHY.SNAPSHOT BE RESET BASED ON CURRLOCATION, NOT LAST SNAP RECORDED BECAUSE WHAT IF JUMPING TO PREVIOUS SNAPSHOT AND THEN CLEAR. WOULDN'T THAT REQUIRE UPDATING THE DEMO APP TO THE LAST STATE RECORDED AS WELL?
278-
tabsObj[tabId].currLocation = tabsObj[tabId].hierarchy; // resets currLocation to page last state recorded
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
279282
tabsObj[tabId].index = 1; //reset index
280283
tabsObj[tabId].currParent = 0; // reset currParent
281284
tabsObj[tabId].currBranch = 1; // reset currBranch

0 commit comments

Comments
 (0)