Skip to content

Commit 71180fa

Browse files
authored
Merge pull request #34 from oslabs-beta/bryan/slider-scss
Bryan/slider scss
2 parents 73bd0f3 + 1917a88 commit 71180fa

File tree

10 files changed

+2611
-2098
lines changed

10 files changed

+2611
-2098
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.

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: 37 additions & 2 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
@@ -111,6 +143,9 @@ class MainContainer extends Component {
111143
handleChangeSnapshot={this.handleChangeSnapshot}
112144
handleJumpSnapshot={this.handleJumpSnapshot}
113145
snapshotIndex={snapshotIndex}
146+
moveBackward = {this.moveBackward}
147+
moveForward = {this.moveForward}
148+
playForward = {this.playForward}
114149
/>
115150
</div>
116151
);

src/app/containers/TravelContainer.jsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
import React, { Component } from 'react';
2-
import Slider from '../components/Slider';
2+
import MainSlider from '../components/MainSlider'
3+
4+
5+
36

47
class TravelContainer extends Component {
58
constructor(props) {
69
super(props);
710
}
811

12+
13+
914
render() {
1015
return (
11-
<div>
12-
<div className="travel-container">TravelContainer</div>
13-
<Slider
14-
className="travel-slider"
15-
snapshotLength={this.props.snapshotsLength}
16-
handleChangeSnapshot={this.props.handleChangeSnapshot}
16+
<div className="travel-container">
17+
<div className="play-button" onClick={this.props.playForward}>
18+
play
19+
</div>
20+
<MainSlider
21+
snapshotLength = {this.props.snapshotsLength}
22+
handleChangeSnapshot = {this.props.handleChangeSnapshot}
23+
snapshotIndex = {this.props.snapshotIndex}
1724
handleJumpSnapshot={this.props.handleJumpSnapshot}
18-
snapshotIndex={this.props.snapshotIndex}
1925
/>
20-
{`travelContainer snapshotIndex ${this.props.snapshotIndex}`}
26+
<div className="backward-button" onClick={this.props.moveBackward}>
27+
{'<'}
28+
</div>
29+
<div className="forward-button" onClick={this.props.moveForward}>
30+
{'>'}
31+
</div>
2132
</div>
2233
);
2334
}

src/app/styles/components/_buttons.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@
1616
background-color: $highlight-color;
1717
}
1818

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

0 commit comments

Comments
 (0)