Skip to content

Commit bce154c

Browse files
davidchai717nusanam
andcommitted
Multi tree branch support implemented
Co-authored-by: Ruth Anam <[email protected]> Co-authored-by: David Chai <[email protected]>
1 parent feff6b9 commit bce154c

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

src/app/reducers/mainReducer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default (state, action) => produce(state, draft => {
1616
port.postMessage({
1717
action: 'jumpToSnap',
1818
payload: snapshots[newIndex],
19+
index: newIndex,
1920
tabId: currentTab,
2021
});
2122
clearInterval(intervalId);
@@ -31,6 +32,7 @@ export default (state, action) => produce(state, draft => {
3132

3233
port.postMessage({
3334
action: 'jumpToSnap',
35+
index: newIndex,
3436
payload: snapshots[newIndex],
3537
tabId: currentTab,
3638
});
@@ -55,6 +57,7 @@ export default (state, action) => produce(state, draft => {
5557
port.postMessage({
5658
action: 'jumpToSnap',
5759
payload: snapshots[action.payload],
60+
index: action.payload,
5861
tabId: currentTab,
5962
});
6063
tabs[currentTab].sliderIndex = action.payload;

src/extension/background.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,13 @@ function createTabObj(title) {
2424
};
2525
}
2626

27-
28-
// function resetIndex(num) {
29-
// return num = 0;
30-
// }
31-
32-
// let num = 0;
33-
34-
class Node {
35-
constructor(obj, tabObj) {
36-
this.index = tabObj.index += 1;
37-
this.stateSnapshot = obj;
38-
this.children = [];
39-
}
40-
};
27+
class Node {
28+
constructor(obj, tabObj) {
29+
this.index = tabObj.index += 1;
30+
this.stateSnapshot = obj;
31+
this.children = [];
32+
}
33+
};
4134

4235
function sendToHierarchy (tabObj, newNode) {
4336
if (!tabObj.currLocation) {
@@ -48,6 +41,7 @@ function sendToHierarchy (tabObj, newNode) {
4841
tabObj.currLocation = newNode;
4942
}
5043
}
44+
5145
function changeCurrLocation (tabObj, rootNode, index) {
5246
// check if current node has the index wanted
5347
if (rootNode.index === index) {
@@ -130,15 +124,16 @@ chrome.runtime.onConnect.addListener(port => {
130124

131125
// background.js recieves message from contentScript.js
132126
chrome.runtime.onMessage.addListener((request, sender) => {
127+
console.log('received request', request);
133128
// IGNORE THE AUTOMATIC MESSAGE SENT BY CHROME WHEN CONTENT SCRIPT IS FIRST LOADED
134129
if (request.type === 'SIGN_CONNECT') return;
135130
const tabTitle = sender.tab.title;
136131
const tabId = sender.tab.id;
137-
const { action } = request;
132+
const { action, index } = request;
138133
let isReactTimeTravel = false;
139134

140135
// Filter out tabs that don't have reactime
141-
if (action === 'tabReload' || action === 'recordSnap') {
136+
if (action === 'tabReload' || action === 'recordSnap' || action === 'jumpToSnap') {
142137
isReactTimeTravel = true;
143138
} else return;
144139

@@ -150,13 +145,19 @@ chrome.runtime.onMessage.addListener((request, sender) => {
150145
const { persist } = tabsObj[tabId].mode;
151146

152147
switch (action) {
148+
case 'jumpToSnap': {
149+
console.log("im triggered")
150+
changeCurrLocation(tabsObj[tabId], tabsObj[tabId].hierarchy, index);
151+
break;
152+
}
153153
case 'tabReload': {
154+
console.log("tabreload triggered")
154155
tabsObj[tabId].mode.locked = false;
155156
tabsObj[tabId].mode.paused = false;
156157
// dont remove snapshots if persisting
157158
if (!persist) {
158159
tabsObj[tabId].snapshots.splice(1);
159-
// reset children in root node to reset graph
160+
// reset children in root node to reset graph
160161
tabsObj[tabId].hierarchy.children = [];
161162
// reassigning pointer to the appropriate node to branch off of
162163
tabsObj[tabId].currLocation = tabsObj[tabId].hierarchy;

src/extension/contentScript.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ window.addEventListener('message', msg => {
1616
if (action === 'recordSnap') chrome.runtime.sendMessage(msg.data);
1717
});
1818

19-
// listening for messages from background.js
19+
// listening for messages from the UI
2020
chrome.runtime.onMessage.addListener(request => {
2121
// send the message to npm package
2222
const { action } = request;
2323
switch (action) {
2424
case 'jumpToSnap':
25+
console.log('jumpped to snap', request);
26+
chrome.runtime.sendMessage(request);
27+
window.postMessage(request);
28+
break;
2529
case 'setLock':
2630
case 'setPause':
2731
window.postMessage(request);

0 commit comments

Comments
 (0)