-
Notifications
You must be signed in to change notification settings - Fork 38
/
LeftPane.js
98 lines (83 loc) 路 2.39 KB
/
LeftPane.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import React, { Component } from 'react';
import styled from 'styled-components';
import { connect } from 'react-redux';
import { resetNodeSettings, getLocalNodeSetupProgress } from '/redux/localNode/actions';
import { LoadingBar, LocalNodeLog, LocalNodeStatus } from '/components/localNode';
import { SmButton } from '/basicComponents';
import { localNodeModes } from '/vars';
import type { Action } from '/types';
const completeValue = 80; // TODO: change to actual complete value
const Wrapper = styled.div`
height: 100%;
display: flex;
flex: 1;
flex-direction: column;
`;
const Header = styled.div`
display: flex;
flex-direction: row;
margin-bottom: 30px;
`;
type Props = {
isInProgress: boolean,
switchMode: (mode: number) => void,
capacity: any,
progress: number,
resetNodeSettings: Action,
getLocalNodeSetupProgress: Action
};
class LeftPane extends Component<Props> {
timer: any;
render() {
const { capacity, isInProgress } = this.props;
const status = isInProgress ? 'Connecting' : 'Active and Connected';
return (
<Wrapper>
<Header>
<LoadingBar isLoading={isInProgress} capacity={(capacity && capacity.label) || ''} status={status} />
<SmButton theme="green" text="Stop" onPress={this.handleStopSetup} style={{ marginLeft: 20 }} />
</Header>
<LocalNodeStatus />
<LocalNodeLog />
</Wrapper>
);
}
componentDidMount() {
const { getLocalNodeSetupProgress } = this.props;
this.checkInitStatus();
getLocalNodeSetupProgress();
this.timer = setInterval(() => {
getLocalNodeSetupProgress();
}, 30000);
}
componentDidUpdate() {
this.checkInitStatus();
}
componentWillUnmount() {
this.timer && clearInterval(this.timer);
}
handleStopSetup = () => {
const { resetNodeSettings, switchMode, isInProgress } = this.props;
isInProgress && resetNodeSettings();
switchMode(localNodeModes.SETUP);
};
checkInitStatus = () => {
const { switchMode, progress } = this.props;
if (progress === completeValue) {
switchMode(localNodeModes.OVERVIEW);
}
};
}
const mapStateToProps = (state) => ({
capacity: state.localNode.capacity,
progress: state.localNode.progress
});
const mapDispatchToProps = {
resetNodeSettings,
getLocalNodeSetupProgress
};
LeftPane = connect(
mapStateToProps,
mapDispatchToProps
)(LeftPane);
export default LeftPane;