Skip to content

Commit b90eb96

Browse files
committed
Connected frontend changes with chrome extension. Play button now changes the app while playing
1 parent 9ec7b2d commit b90eb96

File tree

6 files changed

+42
-28
lines changed

6 files changed

+42
-28
lines changed

src/app/components/App.jsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext, Component } from 'react';
1+
import React, { Component } from 'react';
22
import { createGlobalStyle } from 'styled-components';
33

44
// containers
@@ -48,7 +48,7 @@ class App extends Component {
4848
};
4949

5050
this.portToExtension = null;
51-
51+
5252
this.addActionToView = this.addActionToView.bind(this);
5353
this.toTheFuture = this.toTheFuture.bind(this);
5454
this.toThePast = this.toThePast.bind(this);
@@ -82,6 +82,7 @@ class App extends Component {
8282
}));
8383
});
8484
});
85+
}
8586

8687
// functionality to change 'play' button to 'stop'
8788
setIsPlaying() {
@@ -120,17 +121,19 @@ class App extends Component {
120121

121122
actionInPlay() {
122123
let { isPlayingIndex } = this.state;
123-
if (isPlayingIndex >= this.state.data.length - 1) isPlayingIndex = 0;
124+
const { isPlaying, data } = this.state;
125+
126+
if (isPlayingIndex >= data.length - 1) isPlayingIndex = 0;
124127

125128
this.setState({ isPlayingIndex: isPlayingIndex + 1 });
126-
const { id, action, state } = this.state.data[isPlayingIndex + 1];
127-
this.toThePast();
129+
const { id, action, state } = data[isPlayingIndex + 1];
130+
this.toTheFuture();
128131

129132
setTimeout(() => {
130133
this.setState((prev, props) => {
131134
return { ...prev, id, action, state };
132135
});
133-
if (this.state.isPlaying && isPlayingIndex + 1 < this.state.data.length - 1) {
136+
if (isPlaying && isPlayingIndex + 1 < data.length - 1) {
134137
this.actionInPlay();
135138
} else {
136139
this.setState({ isPlaying: false });
@@ -201,7 +204,6 @@ class App extends Component {
201204
}
202205

203206
render() {
204-
console.log(this.state.isPlayingIndex);
205207
const {
206208
action,
207209
id,

src/app/components/DetailCards/DetailsNav.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import React, { useState } from 'react';
2-
3-
let NavLink = require('react-router-dom').NavLink;
4-
1+
import React from 'react';
52
// styled component imports
63
import { Buttons, Button, DetailsNavWrapper } from '../../styles/Nav.jsx';
74

5+
const { NavLink } = require('react-router-dom');
86

97
export default function RightNav(props) {
108
return (

src/app/container/Details.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import StateDisplay from '../components/DetailCards/State/StateDisplay.jsx'
1515

1616

1717
export default function Details(props) {
18-
1918
// destructuring required info that's being passed down from App.jsx
2019
// passing these props onto children
2120
const {

src/browser/chrome/background.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
const parseAndGenerate = require('./scripts/parser');
22

3+
let portToDevtools;
4+
const msgsToPanel = [];
5+
36
chrome.tabs.onUpdated.addListener((id, info, tab) => {
47
if (tab.status !== 'complete' || tab.url.startsWith('chrome')) return;
58

9+
// active page action button and inject extension.js
610
chrome.pageAction.show(tab.id);
711
chrome.tabs.executeScript(null, {
812
file: 'extension.js',
913
runAt: 'document_end',
1014
});
15+
16+
// refresh devtool panel everytime we refresh webpage
17+
// console.log('port: ', portToDevtools);
18+
// if (portToDevtools) portToDevtools.postMessage({ action: 'refresh_devtool' });
19+
// else msgsToPanel.push({ action: 'refresh_devtool' });
1120
});
1221

1322

@@ -29,7 +38,6 @@ function handleRequest(request) {
2938
const syncRequest = new XMLHttpRequest();
3039
syncRequest.open('GET', request.url, false);
3140
syncRequest.send(null);
32-
console.log(`Status: ${syncRequest.status} - Size of response: ${syncRequest.responseText.length}`);
3341

3442
sendMessageToContent(parseAndGenerate(syncRequest.responseText));
3543

@@ -40,6 +48,18 @@ function handleRequest(request) {
4048
// The App on the devtools panel start a connection so that it can
4149
// tell us when to start intercepting the script requests.
4250
chrome.runtime.onConnect.addListener((port) => {
51+
portToDevtools = port;
52+
53+
// if (msgsToPanel.length > 0) {
54+
// for (let msg of msgsToPanel) port.postMessage(msg);
55+
// }
56+
// we change the port to null when we disconnect, so that when we refresh
57+
// the page by start recording, we can check if (!port) and not refresh
58+
// the devtools page.
59+
port.onDisconnect.addListener(() => {
60+
portToDevtools = null;
61+
});
62+
4363
port.onMessage.addListener((msg) => {
4464
if (!msg.turnOnDevtool) return;
4565
interceptedUrl = msg.url;
@@ -64,7 +84,6 @@ function addScriptInterception() {
6484
let reqIndex = 0;
6585
function sendMessageToContent(codeString) {
6686
const index = reqIndex++;
67-
console.log(`Sending request ${index}.`);
6887
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
6988
chrome.tabs.sendMessage(tabs[0].id, { codeString, index });
7089
});

src/browser/chrome/devtools.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ chrome.devtools.panels.create('React Rewind',
33
'devtools.html',
44
(extensionPanel) => {
55
const port = chrome.runtime.connect({ name: 'devtools' });
6-
port.onMessage.addListener(() => {});
6+
port.onMessage.addListener((msg) => {
7+
// console.log('got msg: ', msg);
8+
if (msg.action === 'refresh_devtool') extensionPanel.setPage('devtools.html');
9+
});
10+
711
extensionPanel.onShown.addListener((panelWindow) => {
812
panelWindow.backgroundPort = port;
913
});

src/browser/chrome/scripts/time_travel.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ let root = null;
3636
const timeTravelLList = new DoublyLinkedList();
3737

3838
function timeTravel(direction) {
39-
console.log('calling time travel...');
40-
// if (timeTravelTrackerIndex === null) {
41-
// // First time we call this function. We need to remove the PLACEMENT entry
42-
// // from position [0]. This is originated from the initial mount of the App.
43-
// timeTravelTracker = timeTravelTracker.slice(1);
44-
// timeTravelTrackerIndex = timeTravelTracker.length - 1;
45-
// root = getRootContainerInstance(timeTravelTracker[0].effect);
46-
// }
4739
if (!root) {
4840
root = getRootContainerInstance(timeTravelLList.current.value.effect);
4941
timeTravelLList.current = timeTravelLList.tail;
@@ -78,7 +70,7 @@ function timeTravel(direction) {
7870
// if we are moving forwards, we need to commitWork() the same
7971
// way the function was originally called.
8072
if (diff === 1) {
81-
commitWork(current, effect);
73+
commitWork(_.cloneDeep(current), _.cloneDeep(effect));
8274
break;
8375
}
8476

@@ -100,16 +92,16 @@ function timeTravel(direction) {
10092

10193
const currentCopy = _.cloneDeep(current);
10294
currentCopy.updateQueue = payload;
103-
commitWork(effect, currentCopy);
95+
commitWork(_.cloneDeep(effect), currentCopy);
10496
break;
10597
}
10698

107-
commitWork(effect, current);
99+
commitWork(_.cloneDeep(effect), _.cloneDeep(current));
108100
break;
109101
}
110102
case 'PLACEMENT': {
111103
if (diff === 1) {
112-
commitPlacement(effect);
104+
commitPlacement(_.cloneDeep(effect));
113105
} else {
114106
// commitDeletion() will call unmountHostComponents(), which recursively
115107
// deletes all host nodes from the parent. This means that
@@ -127,7 +119,7 @@ function timeTravel(direction) {
127119
const effectCopy = _.cloneDeep(effect);
128120
commitDeletion(effectCopy);
129121
} else {
130-
commitPlacement(effect);
122+
commitPlacement(_.cloneDeep(effect));
131123
}
132124
break;
133125
}

0 commit comments

Comments
 (0)