Skip to content

Commit 32a90c7

Browse files
committed
play pause display
1 parent 6c28995 commit 32a90c7

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/app/containers/MainContainer.jsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class MainContainer extends Component {
1212
snapshotIndex: 0,
1313
currentIndex: null,
1414
port: null,
15+
playing: false,
1516
};
1617
this.handleChangeSnapshot = this.handleChangeSnapshot.bind(this);
1718
this.handleSendSnapshot = this.handleSendSnapshot.bind(this);
@@ -64,13 +65,21 @@ class MainContainer extends Component {
6465

6566
playForward() {
6667
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);
68+
const { snapshots, snapshotIndex, playing } = this.state;
69+
if(!playing){
70+
if (snapshotIndex < snapshots.length - 1) {
71+
const newIndex = snapshotIndex + 1;
72+
this.handleJumpSnapshot(newIndex);
73+
this.setState({ snapshotIndex: newIndex, playing: true });
74+
} else {
75+
this.setState({ playing: false})
76+
clearInterval(play);
77+
}
78+
} else {
79+
clearInterval(play);
80+
}
7381
}, 1000)
82+
7483
play();
7584
}
7685

@@ -124,7 +133,7 @@ class MainContainer extends Component {
124133
}
125134

126135
render() {
127-
const { snapshots, snapshotIndex } = this.state;
136+
const { snapshots, snapshotIndex, playing } = this.state;
128137
return (
129138
<div className="main-container">
130139
<HeadContainer />
@@ -145,6 +154,7 @@ class MainContainer extends Component {
145154
moveBackward={this.moveBackward}
146155
moveForward={this.moveForward}
147156
playForward={this.playForward}
157+
playing={playing}
148158
/>
149159
</div>
150160
</div>

src/app/containers/TravelContainer.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ const TravelContainer = ({
99
handleChangeSnapshot,
1010
handleJumpSnapshot,
1111
snapshotIndex,
12+
playing
1213
}) => (
1314
<div className="travel-container">
1415
<div className="play-button" onClick={playForward}>
15-
play
16+
{ playing ? 'Pause': 'Play' }
1617
</div>
1718
<MainSlider
1819
snapshotLength={snapshotsLength}

0 commit comments

Comments
 (0)