Skip to content

Commit 3096091

Browse files
committed
merged with dev
2 parents 82480a0 + 95d8d76 commit 3096091

File tree

15 files changed

+2657
-2142
lines changed

15 files changed

+2657
-2142
lines changed

package-lock.json

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

package/tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Tree {
1919
}
2020

2121
// deep copies only the state of each component and creates a new tree
22-
getCopy(copy = new Tree('root', true, 'root')) {
22+
getCopy(copy = new Tree('root', true)) {
2323
// copy state of children
2424
copy.children = this.children.map(child => new Tree(child.component.state, true, child.component.constructor.name));
2525

src/app/components/Slider.jsx renamed to src/app/components/MainSlider.jsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import React, { Component } from 'react';
22
import Slider from 'rc-slider';
33
import Tooltip from 'rc-tooltip';
44

5-
import 'rc-slider/assets/index.css';
6-
import 'rc-tooltip/assets/bootstrap.css';
75

86
const { Handle } = Slider;
97

@@ -32,7 +30,6 @@ class mainSlider extends Component {
3230

3331
render() {
3432
return (
35-
<div>
3633
<Slider
3734
min={0}
3835
max={this.props.snapshotLength - 1}
@@ -44,7 +41,6 @@ class mainSlider extends Component {
4441
}}
4542
handle={handle}
4643
/>
47-
</div>
4844
);
4945
}
5046
}

src/app/containers/MainContainer.jsx

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class MainContainer extends Component {
1717
this.handleSendSnapshot = this.handleSendSnapshot.bind(this);
1818
this.handleJumpSnapshot = this.handleJumpSnapshot.bind(this);
1919
this.emptySnapshot = this.emptySnapshot.bind(this);
20+
this.moveBackward = this.moveBackward.bind(this);
21+
this.moveForward = this.moveForward.bind(this);
22+
this.playForward = this.playForward.bind(this);
2023
}
2124

2225
componentDidMount() {
@@ -41,14 +44,43 @@ class MainContainer extends Component {
4144
this.setState({ port });
4245
}
4346

47+
moveBackward() {
48+
const { snapshots, snapshotIndex } = this.state;
49+
if (snapshots.length > 0 && snapshotIndex > 0) {
50+
const newIndex = snapshotIndex - 1;
51+
this.handleJumpSnapshot(newIndex);
52+
this.setState({ snapshotIndex: newIndex });
53+
}
54+
}
55+
56+
moveForward() {
57+
const { snapshots, snapshotIndex } = this.state;
58+
if (snapshotIndex < snapshots.length - 1) {
59+
const newIndex = snapshotIndex + 1;
60+
this.handleJumpSnapshot(newIndex);
61+
this.setState({ snapshotIndex: newIndex });
62+
}
63+
}
64+
65+
playForward() {
66+
var play = setInterval(() => {
67+
const { snapshots, snapshotIndex } = this.state;
68+
if (snapshotIndex < snapshots.length - 1) {
69+
const newIndex = snapshotIndex + 1;
70+
this.handleJumpSnapshot(newIndex);
71+
this.setState({ snapshotIndex: newIndex });
72+
} else clearInterval(play);
73+
}, 1000)
74+
play();
75+
}
76+
4477
emptySnapshot() {
4578
const { port } = this.state;
4679
this.setState({ snapshots: [], snapshotIndex: 0 });
4780
port.postMessage({ action: 'emptySnap' });
4881
}
4982

50-
// change the snapshot index
51-
// this will change the state shown in the state container but won't change the DOM
83+
// change the snapshot index, this will change the state shown in the state container but won't change the DOM
5284
handleChangeSnapshot(snapshotIndex) {
5385
// snapshotIndex
5486
// --> 1. affects the action that is highlighted
@@ -105,13 +137,16 @@ class MainContainer extends Component {
105137
emptySnapshot={this.emptySnapshot}
106138
/>
107139
<StateContainer snapshot={snapshots[snapshotIndex]} />
140+
<TravelContainer
141+
snapshotsLength={snapshots.length}
142+
handleChangeSnapshot={this.handleChangeSnapshot}
143+
handleJumpSnapshot={this.handleJumpSnapshot}
144+
snapshotIndex={snapshotIndex}
145+
moveBackward={this.moveBackward}
146+
moveForward={this.moveForward}
147+
playForward={this.playForward}
148+
/>
108149
</div>
109-
<TravelContainer
110-
snapshotsLength={snapshots.length}
111-
handleChangeSnapshot={this.handleChangeSnapshot}
112-
handleJumpSnapshot={this.handleJumpSnapshot}
113-
snapshotIndex={snapshotIndex}
114-
/>
115150
</div>
116151
);
117152
}
Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
1+
<<<<<<< HEAD
12
import React, { Component } from 'react';
23

34
import Slider from '../components/Slider';
5+
=======
6+
import React from 'react';
7+
import MainSlider from '../components/MainSlider'
8+
>>>>>>> dev
49

5-
class TravelContainer extends Component {
6-
constructor(props) {
7-
super(props);
8-
}
9-
10-
render() {
11-
return (
12-
<div>
13-
<div className="travel-container">TravelContainer</div>
14-
<Slider
15-
className="travel-slider"
16-
snapshotLength={this.props.snapshotsLength}
17-
handleChangeSnapshot={this.props.handleChangeSnapshot}
18-
handleJumpSnapshot={this.props.handleJumpSnapshot}
19-
snapshotIndex={this.props.snapshotIndex}
20-
/>
21-
{`travelContainer snapshotIndex ${this.props.snapshotIndex}`}
22-
</div>
23-
);
24-
}
25-
}
10+
const TravelContainer = ({
11+
playForward,
12+
moveBackward,
13+
moveForward,
14+
snapshotsLength,
15+
handleChangeSnapshot,
16+
handleJumpSnapshot,
17+
snapshotIndex,
18+
}) => (
19+
<div className="travel-container">
20+
<div className="play-button" onClick={playForward}>
21+
play
22+
</div>
23+
<MainSlider
24+
snapshotLength={snapshotsLength}
25+
handleChangeSnapshot={handleChangeSnapshot}
26+
snapshotIndex={snapshotIndex}
27+
handleJumpSnapshot={handleJumpSnapshot}
28+
/>
29+
<div className="backward-button" onClick={moveBackward}>
30+
{'<'}
31+
</div>
32+
<div className="forward-button" onClick={moveForward}>
33+
{'>'}
34+
</div>
35+
</div>
36+
);
2637
export default TravelContainer;

src/app/styles/components/_actionComponent.scss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.action-component {
22
padding: 5px 10px;
3-
display: flex;
4-
justify-content: space-around;
3+
display: grid;
4+
grid-template-columns: 5fr 1fr;
55
align-items: center;
66
height: 20px;
77
background-color: $brand-color;
@@ -18,5 +18,8 @@
1818

1919
.action-component button {
2020
position: relative;
21-
right: 0px;
21+
}
22+
23+
.action-component:hover .jump-button {
24+
visibility: visible;
2225
}

src/app/styles/components/_buttons.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
.jump-button {
77
@extend %button-shared;
88
width: 50px;
9+
visibility: hidden;
910
}
1011

1112
.jump-button:hover {
@@ -16,6 +17,24 @@
1617
background-color: $highlight-color;
1718
}
1819

20+
.play-button {
21+
@extend %button-shared;
22+
width: 60px;
23+
margin: 10px;
24+
}
25+
26+
.backward-button {
27+
@extend %button-shared;
28+
width: 30px;
29+
margin: 7px;
30+
}
31+
32+
.forward-button {
33+
@extend %button-shared;
34+
width: 30px;
35+
margin: 7px;
36+
}
37+
1938
%button-shared {
2039
display: flex;
2140
justify-content: center;

0 commit comments

Comments
 (0)