Skip to content

Commit 0736a0c

Browse files
committed
Merge branch 'dev' into rydang/snapshotrefactor
2 parents 63f9d89 + 57ed117 commit 0736a0c

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

extension/app/containers/ActionContainer.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ class ActionContainer extends Component {
2626
);
2727
});
2828
}
29-
return <div className="action-container">{actionsArr}</div>;
29+
return (
30+
<div>
31+
<button onClick = {this.props.emptySnapshot}>emptySnapshot</button>
32+
<div className="action-container">{actionsArr}</div>
33+
</div>
34+
);
35+
3036
}
3137
}
3238

extension/app/containers/MainContainer.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ class MainContainer extends Component {
1515

1616
this.handleChangeSnapshot = this.handleChangeSnapshot.bind(this);
1717
this.handleSendSnapshot = this.handleSendSnapshot.bind(this);
18+
this.emptySnapshot = this.emptySnapshot.bind(this)
1819
}
1920

21+
22+
2023
componentDidMount() {
2124
// open connection with background script
2225
const port = chrome.runtime.connect();
@@ -38,6 +41,14 @@ class MainContainer extends Component {
3841
// assign port to state so it could be used by other components
3942
this.setState({ port });
4043
}
44+
45+
emptySnapshot(){
46+
const { port } = this.state;
47+
48+
this.setState({ snapshots: [] })
49+
50+
port.postMessage({action: 'emptySnap', payload: [] });
51+
}
4152

4253
// change the snapshot index
4354
// --> 1. affects the action that is highlighted
@@ -65,6 +76,7 @@ class MainContainer extends Component {
6576
snapshotIndex={snapshotIndex}
6677
handleChangeSnapshot={this.handleChangeSnapshot}
6778
handleSendSnapshot={this.handleSendSnapshot}
79+
emptySnapshot = {this.emptySnapshot}
6880
/>
6981
<StateContainer snapshot={snapshots[snapshotIndex]} />
7082
</div>

extension/background.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ console.log('background.js file is running');
33
let bg;
44

55
// need a function to clear snapshotArr when either tab is closed or page is refreshed
6-
const snapshotArr = [];
6+
let snapshotArr = [];
77

88
// establishing connection with devtools
99
chrome.runtime.onConnect.addListener((port) => {
@@ -19,11 +19,15 @@ chrome.runtime.onConnect.addListener((port) => {
1919
// receive snapshot from devtools and send it to contentScript
2020
port.onMessage.addListener((msg) => {
2121
console.log('background -> contentScript', msg);
22-
// find active tab
23-
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
24-
// send message to tab
25-
chrome.tabs.sendMessage(tabs[0].id, msg);
26-
});
22+
if(msg.action==='emptySnap') {
23+
snapshotArr = [];
24+
} else {
25+
// find active tab
26+
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
27+
// send message to tab
28+
chrome.tabs.sendMessage(tabs[0].id, msg);
29+
});
30+
}
2731
});
2832
});
2933

extension/contentScript.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ window.addEventListener('message', (msg) => {
55
const { action, payload } = msg.data;
66

77
if (action === 'recordSnap') chrome.runtime.sendMessage(payload);
8-
// console.log(msg);
98
});
109

1110
// listening for messages from background.js

0 commit comments

Comments
 (0)