summaryrefslogtreecommitdiff
path: root/src/components/timeline/TimelineComponent.js
blob: b400a37830ab9067a306e6b2237cd18d8b2c0c11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React from "react";
import TimelineControlsContainer from "../../containers/timeline/TimelineControlsContainer";
import TimelineLabelsContainer from "../../containers/timeline/TimelineLabelsContainer";
import "./Timeline.css";

class TimelineComponent extends React.Component {
    componentDidMount() {
        this.interval = setInterval(() => {
            if (!this.props.isPlaying) {
                return;
            }

            if (this.props.currentTick < this.props.lastSimulatedTick) {
                for (let i in this.props.sections.reverse()) {
                    if (this.props.currentTick + 1 >= this.props.sections[i].startTick) {
                        if (this.props.currentDatacenterId !== this.props.sections[i].datacenterId) {
                            this.props.setCurrentDatacenter(this.props.sections[i].datacenterId);
                        }
                        break;
                    }
                }
                this.props.incrementTick();
            }
        }, 1000);
    }

    componentWillUnmount() {
        clearInterval(this.interval);
    }

    render() {
        return (
            <div className="timeline-bar">
                <div className="timeline-container">
                    <TimelineLabelsContainer/>
                    <TimelineControlsContainer/>
                </div>
            </div>
        );
    }
}

export default TimelineComponent;