diff --git a/src/app/components/App.jsx b/src/app/components/App.jsx
index db64dfe..980d239 100644
--- a/src/app/components/App.jsx
+++ b/src/app/components/App.jsx
@@ -41,6 +41,7 @@ class App extends Component {
isRecording: true,
};
+ this.port = null;
this.addActionToView = this.addActionToView.bind(this);
this.toTheFuture = this.toTheFuture.bind(this);
this.toThePast = this.toThePast.bind(this);
@@ -52,11 +53,13 @@ class App extends Component {
// adds listener to the effects that are gonna be sent from
// our edited useReducer from the 'react' library.
chrome.runtime.onConnect.addListener((portFromExtension) => {
+ this.port = portFromExtension;
+
portFromExtension.onMessage.addListener((msg) => {
const newData = {
action: msg.action,
state: msg.state,
- id: this.state.length,
+ id: this.state.data.length,
};
this.setState((state) => ({
data: [...state.data, newData]
@@ -67,7 +70,6 @@ class App extends Component {
// functionality to change 'play' button to 'stop'
setIsPlaying() {
- console.log('setIsPlaying:', this.state.isPlaying)
let { isPlaying } = this.state;
isPlaying = !isPlaying;
this.setState({ isPlaying });
@@ -75,7 +77,6 @@ class App extends Component {
// functionality to change 'record' button to 'pause'
setIsRecording() {
- console.log('setIsRecording:', this.state.isRecording)
this.setState(state => ({
isRecording: !state.isRecording,
}));
@@ -96,41 +97,21 @@ class App extends Component {
// function to travel to the FUTURE
- toTheFuture(e) {
- if (this.state.action) {
- for (let i = 0; i < data.length - 1; i += 1) {
- // clicking next returns next piece of data
- if (data[i].id === this.state.id) {
- const { action, id, payload, state } = data[i + 1];
- this.setState({action, id, payload, state});
- }
- // if we're at the last action stop there
- // don't let user go any further
- if (data[i].id === undefined) {
- const { action, id, payload, state } = data[data.length -1 ];
- this.setState({action, id, payload, state});
- }
- }
- }
+ toTheFuture() {
+ if (!this.port) return console.error('No connection on stored port.');
+ this.port.postMessage({
+ type: 'TIMETRAVEL',
+ direction: 'forward',
+ });
}
// function to travel to the PAST
- toThePast(e) {
- if (this.state.action) {
- for (let i = data.length - 1; i >= 0; i -= 1) {
- // clicking next returns next piece of data
- if (data[i].id === this.state.id) {
- const { action, id, payload, state } = data[i - 1];
- this.setState({action, id, payload, state});
- }
- // if we're at the last action stop there
- // don't let user go any further
- if (this.state.action === undefined) {
- const { action, id, payload, state } = data[0];
- this.setState({action, id, payload, state});
- }
- }
- }
+ toThePast() {
+ if (!this.port) return console.error('No connection on stored port.');
+ this.port.postMessage({
+ type: 'TIMETRAVEL',
+ direction: 'backwards',
+ });
}
render() {
@@ -153,7 +134,7 @@ class App extends Component {
left={
(
);
}
- }
+}
export default App;
diff --git a/src/app/styles/Events.jsx b/src/app/styles/Events.jsx
index fc36d00..9ed2e31 100644
--- a/src/app/styles/Events.jsx
+++ b/src/app/styles/Events.jsx
@@ -39,10 +39,3 @@ export const TimeTravelContainer = styled.div`
display: flex;
justify-content: space-evenly;
`;
-
-export const TimeTravelContainer = styled.div`
- border-top: 1px solid white;
- padding-top: 5%;
- display: flex;
- justify-content: space-evenly;
-`;
diff --git a/src/browser/chrome/extension.js b/src/browser/chrome/extension.js
index a0ae655..e93fd6c 100644
--- a/src/browser/chrome/extension.js
+++ b/src/browser/chrome/extension.js
@@ -2,9 +2,14 @@ const port = chrome.runtime.connect({
name: 'Injected-Background Connection',
});
+port.onMessage.addListener((msg) => {
+ window.postMessage(msg);
+});
+
port.onDisconnect.addListener(() => console.log('Disconecting...'));
window.addEventListener('message', (msg) => {
+ // TODO: fix comments. Are we gonna receive msgs from reactDOM here??
// When our injected scripts post messages (both from the 'react'
// and 'react-dom'), we receive it here and send it to our app loaded
// on the DevTool. If storage.isAppTurnedOff is false, it means that
@@ -12,17 +17,7 @@ window.addEventListener('message', (msg) => {
// though our injected scripts keep posting messages, we don't want to
// send them over to the App anymore.
chrome.storage.sync.get(['isAppTurnedOn'], (status) => {
- if (!status.isAppTurnedOn) return;
-
- switch (msg.data.type) {
- case 'DISPATCH':
- port.postMessage(msg.data.data);
- break;
- case 'EFFECT':
- console.log('Received effect: ', msg.data);
- break;
- default:
- console.log('default');
- }
+ // if (!status.isAppTurnedOn) return;
+ if (msg.data.type === 'DISPATCH') port.postMessage(msg.data.data);
});
});
diff --git a/src/browser/chrome/manifest.json b/src/browser/chrome/manifest.json
index 24c0314..c0c0385 100644
--- a/src/browser/chrome/manifest.json
+++ b/src/browser/chrome/manifest.json
@@ -9,6 +9,13 @@
"background": {
"scripts": ["background.js"]
},
+ "content_scripts": [
+ {
+ "matches": ["", "http://*/*", "https://*/*"],
+ "js": ["scripts/inject_script_tags.js"],
+ "run_at":"document_start"
+ }
+ ],
"permissions": [
"",
"tabs",
@@ -17,7 +24,8 @@
"webRequestBlocking"
],
"web_accessible_resources": [
-
+ "scripts/linked_list.js",
+ "scripts/time_travel.js"
],
"devtools_page": "devtools.html"
}
\ No newline at end of file
diff --git a/src/browser/chrome/scripts/inject_script_tags.js b/src/browser/chrome/scripts/inject_script_tags.js
new file mode 100644
index 0000000..924f2a8
--- /dev/null
+++ b/src/browser/chrome/scripts/inject_script_tags.js
@@ -0,0 +1,15 @@
+// We add a