Skip to content

Commit 19c31fc

Browse files
authored
Merge pull request #73 from victorvrv/victor-dev
Removed old way of injecting timeTravel and DLL from inject_script_tags file.
2 parents a2fc0ef + ba07383 commit 19c31fc

File tree

12 files changed

+1093
-225
lines changed

12 files changed

+1093
-225
lines changed

package-lock.json

Lines changed: 35 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"eslint-plugin-jsx-a11y": "^6.2.1",
2828
"esprima": "^4.0.1",
2929
"estraverse": "^4.2.0",
30-
"lodash": "^4.17.11"
30+
"lodash": "^4.17.11",
31+
"lodash.clonedeep": "^4.5.0"
3132
}
3233
}

src/app/components/App.jsx

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,16 @@ class App extends Component {
4545
isPlaying: false,
4646
isRecording: false,
4747
isPlayingIndex: 0,
48+
id: 0,
49+
action: {},
50+
state: {},
51+
prevState: {},
4852
eventTimes: [],
4953
};
5054

5155
this.portToExtension = null;
5256
this.justStartedRecording = false;
57+
this.hasInjectedScript = false;
5358

5459
this.addActionToView = this.addActionToView.bind(this);
5560
this.toTheFuture = this.toTheFuture.bind(this);
@@ -71,9 +76,14 @@ class App extends Component {
7176
this.portToExtension = port;
7277

7378
port.onMessage.addListener((msg) => {
79+
// If the user paused the recording session, we return
80+
const { isRecording } = this.state;
81+
if (!isRecording) return;
82+
7483
const newData = {
7584
action: msg.action,
7685
state: msg.state,
86+
prevState: msg.prevState,
7787
id: this.state.data.length,
7888
};
7989

@@ -115,7 +125,8 @@ class App extends Component {
115125

116126
// functionality to change 'play' button to 'stop'
117127
setIsPlaying() {
118-
if (this.state.isPlayingIndex >= this.state.data.length - 1) {
128+
const { isPlayingIndex, data } = this.state;
129+
if (isPlayingIndex >= data.length - 1) {
119130
return;
120131
}
121132

@@ -130,19 +141,24 @@ class App extends Component {
130141

131142
setIsRecording() {
132143
// This variable will prevent the app from refreshing when we refresh
133-
// the userpage.
144+
// the userpage.
134145
this.justStartedRecording = true;
135-
146+
const { isRecording, hasInjectedScript } = this.state;
136147
this.setState(state => ({
137148
isRecording: !state.isRecording,
138149
}));
139150

151+
// if we are hitting the pause or re-starting the record session
152+
if (isRecording || hasInjectedScript) return;
153+
154+
this.setState({ hasInjectedScript: true });
155+
140156
// we query the active window so we can send it to the background script
141157
// so it knows on which URL to run our devtool.
142158
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
143159
const { url } = tabs[0];
144160

145-
// backgroundPort is a variable made avaiable by the devtools.js
161+
// backgroundPort is a variable made avaiable by the devtools.js
146162
backgroundPort.postMessage({
147163
turnOnDevtool: true,
148164
url,
@@ -151,11 +167,11 @@ class App extends Component {
151167
}
152168

153169
actionInPlay() {
154-
const { data, isPlayingIndex } = this.state;
170+
const { data, isPlayingIndex, isPlaying } = this.state;
155171

156172
setTimeout(() => {
157173
this.toTheFuture();
158-
if (this.state.isPlaying && isPlayingIndex + 1 < data.length - 1) {
174+
if (isPlaying && isPlayingIndex + 1 < data.length - 1) {
159175
this.actionInPlay();
160176
} else {
161177
this.setState({ isPlaying: false });
@@ -169,10 +185,10 @@ class App extends Component {
169185
const { data } = this.state;
170186
const actionToView = data.filter(action => e.target.id === String(action.id));
171187
const {
172-
action, id, state,
188+
action, id, state, prevState,
173189
} = actionToView[0];
174190
this.setState({
175-
action, id, state,
191+
action, id, state, prevState,
176192
});
177193
}
178194

@@ -197,14 +213,15 @@ class App extends Component {
197213
// time travel bar change
198214
handleBarChange(e) {
199215
const { data, isPlayingIndex } = this.state;
200-
const { id, action, state } = data[e.target.value];
216+
const { id, action, state, prevState } = data[e.target.value];
201217
// forward or past
202218
const currentIsPlayingIndex = e.target.value;
203219
const forward = currentIsPlayingIndex > isPlayingIndex;
204220
this.setState({
205221
id,
206222
action,
207223
state,
224+
prevState,
208225
isPlayingIndex: parseInt(currentIsPlayingIndex),
209226
});
210227
// Displays to screen
@@ -226,18 +243,15 @@ class App extends Component {
226243
direction: 'forward',
227244
});
228245

229-
// if (isPlayingIndex >= this.state.data.length - 1) isPlayingIndex = 0;
230-
231-
const { id, action, state } = data[isPlayingIndex + 1];
246+
const { id, action, state, prevState } = data[isPlayingIndex + 1];
232247
this.setState(prev => ({
233248
...prev,
234249
id,
235250
action,
236251
state,
252+
prevState,
237253
isPlayingIndex: isPlayingIndex + 1,
238254
}));
239-
240-
console.log('isPlayingIndex', this.state.isPlayingIndex);
241255
}
242256

243257
// function to travel to the PAST
@@ -251,12 +265,13 @@ class App extends Component {
251265
direction: 'backwards',
252266
});
253267

254-
const { id, action, state } = data[isPlayingIndex - 1];
268+
const { id, action, state, prevState } = data[isPlayingIndex - 1];
255269
this.setState(prev => ({
256270
...prev,
257271
id,
258272
action,
259273
state,
274+
prevState,
260275
isPlayingIndex: isPlayingIndex - 1,
261276
}));
262277
}
@@ -275,6 +290,10 @@ class App extends Component {
275290
isPlaying: false,
276291
isRecording: false,
277292
isPlayingIndex: 0,
293+
id: 0,
294+
action: {},
295+
state: {},
296+
prevState: {},
278297
});
279298
}
280299

@@ -284,12 +303,12 @@ class App extends Component {
284303
id,
285304
state,
286305
data,
287-
setIsPlaying,
288306
isPlaying,
289-
setIsRecording,
290307
isRecording,
291308
filteredData,
292309
searchField,
310+
isPlayingIndex,
311+
prevState,
293312
eventTimes,
294313
} = this.state;
295314

@@ -316,6 +335,7 @@ class App extends Component {
316335
action={action}
317336
id={id}
318337
actionState={state}
338+
prevState={prevState}
319339
/>
320340
)}
321341
/>
@@ -324,7 +344,7 @@ class App extends Component {
324344
toTheFuture={this.toTheFuture}
325345
toThePast={this.toThePast}
326346
isPlaying={isPlaying}
327-
isPlayingIndex={this.state.isPlayingIndex}
347+
isPlayingIndex={isPlayingIndex}
328348
isRecording={isRecording}
329349
setIsPlaying={this.setIsPlaying}
330350
setIsRecording={this.setIsRecording}
@@ -335,4 +355,5 @@ class App extends Component {
335355
);
336356
}
337357
}
358+
338359
export default App;

0 commit comments

Comments
 (0)