Skip to content

Commit 66820b1

Browse files
committed
fixed time travel forward when already at tail of linked list.
1 parent 4f15e5a commit 66820b1

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/app/components/App.jsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ class App extends Component {
217217

218218
// function to travel to the FUTURE
219219
toTheFuture() {
220+
const { data, isPlayingIndex } = this.state;
221+
if (isPlayingIndex === data.length - 1) return;
222+
220223
if (!this.portToExtension) return console.error('No connection on stored port.');
221224
this.portToExtension.postMessage({
222225
type: 'TIMETRAVEL',
@@ -225,7 +228,6 @@ class App extends Component {
225228

226229
// if (isPlayingIndex >= this.state.data.length - 1) isPlayingIndex = 0;
227230

228-
const { data, isPlayingIndex } = this.state;
229231
const { id, action, state } = data[isPlayingIndex + 1];
230232
this.setState(prev => ({
231233
...prev,
@@ -240,26 +242,23 @@ class App extends Component {
240242

241243
// function to travel to the PAST
242244
toThePast() {
245+
const { data, isPlayingIndex } = this.state;
246+
if (isPlayingIndex === 0) return;
247+
243248
if (!this.portToExtension) return console.error('No connection on stored port.');
244249
this.portToExtension.postMessage({
245250
type: 'TIMETRAVEL',
246251
direction: 'backwards',
247252
});
248253

249-
const { data, isPlayingIndex } = this.state;
250-
251-
if (isPlayingIndex === 0) {
252-
console.log('is playingIdx in toThePast is 0');
253-
} else {
254-
const { id, action, state } = data[isPlayingIndex - 1];
255-
this.setState(prev => ({
256-
...prev,
257-
id,
258-
action,
259-
state,
260-
isPlayingIndex: isPlayingIndex - 1,
261-
}));
262-
}
254+
const { id, action, state } = data[isPlayingIndex - 1];
255+
this.setState(prev => ({
256+
...prev,
257+
id,
258+
action,
259+
state,
260+
isPlayingIndex: isPlayingIndex - 1,
261+
}));
263262
}
264263

265264
resetApp() {

0 commit comments

Comments
 (0)