lotus/testbed/front/src/NodeList.js

60 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-07-24 17:10:44 +00:00
import React from 'react';
import FullNode from "./FullNode";
2019-07-24 18:42:02 +00:00
import ConnMgr from "./ConnMgr";
2019-07-24 17:10:44 +00:00
class NodeList extends React.Component {
constructor(props) {
2019-07-24 18:42:02 +00:00
super(props)
2019-07-24 17:10:44 +00:00
this.state = {
existingLoaded: false,
2019-07-24 18:42:02 +00:00
nodes: [],
showConnMgr: false,
}
2019-07-24 17:10:44 +00:00
// This binding is necessary to make `this` work in the callback
2019-07-24 18:42:02 +00:00
this.spawnNode = this.spawnNode.bind(this)
this.connMgr = this.connMgr.bind(this)
2019-07-24 17:10:44 +00:00
this.props.client.call('Pond.Nodes').then(nodes => this.setState({existingLoaded: true, nodes: nodes}))
}
async spawnNode() {
const node = await this.props.client.call('Pond.Spawn')
console.log(node)
this.setState(state => ({nodes: state.nodes.concat(node)}))
}
2019-07-24 18:42:02 +00:00
connMgr() {
this.setState({showConnMgr: true})
}
2019-07-24 17:10:44 +00:00
render() {
2019-07-24 18:42:02 +00:00
let connMgr
if (this.state.showConnMgr) {
connMgr = (<ConnMgr nodes={this.state.nodes}/>)
}
2019-07-24 17:10:44 +00:00
return (
<div>
<div>
<button onClick={this.spawnNode} disabled={!this.state.existingLoaded}>Spawn Node</button>
2019-07-24 18:42:02 +00:00
<button onClick={this.connMgr} disabled={!this.state.existingLoaded && !this.state.showConnMgr}>Connections</button>
2019-07-24 17:10:44 +00:00
</div>
<div>
{
2019-07-24 18:42:02 +00:00
this.state.nodes.map((node, i) => {
return (<FullNode key={node.ID}
node={node}
pondClient={this.props.client}/>)
})
2019-07-24 17:10:44 +00:00
}
2019-07-24 18:42:02 +00:00
{connMgr}
2019-07-24 17:10:44 +00:00
</div>
</div>
);
}
}
export default NodeList