pond: pass nodes to connmgr

This commit is contained in:
Łukasz Magiera 2019-07-24 22:00:11 +02:00
parent e77fff82a9
commit 8638057340
3 changed files with 19 additions and 7 deletions

View File

@ -5,7 +5,7 @@ class ConnMgr extends React.Component {
render() { render() {
return( return(
<Cristal title="Connection Manager"> <Cristal title="Connection Manager">
Cmgr {Object.keys(this.props.nodes)}
</Cristal> </Cristal>
) )
} }

View File

@ -41,6 +41,8 @@ class FullNode extends React.Component {
peers: -1 peers: -1
})) }))
this.props.onConnect(client)
this.loadInfo() this.loadInfo()
setInterval(this.loadInfo, 1000) setInterval(this.loadInfo, 1000)
}) })

View File

@ -7,7 +7,7 @@ class NodeList extends React.Component {
super(props) super(props)
this.state = { this.state = {
existingLoaded: false, existingLoaded: false,
nodes: [], nodes: {},
showConnMgr: false, showConnMgr: false,
} }
@ -16,13 +16,20 @@ class NodeList extends React.Component {
this.spawnNode = this.spawnNode.bind(this) this.spawnNode = this.spawnNode.bind(this)
this.connMgr = this.connMgr.bind(this) this.connMgr = this.connMgr.bind(this)
this.props.client.call('Pond.Nodes').then(nodes => this.setState({existingLoaded: true, nodes: nodes})) this.getNodes()
}
async getNodes() {
const nds = await this.props.client.call('Pond.Nodes')
const nodes = nds.reduce((o, i) => {o[i.ID] = i; return o}, {})
console.log('nds', nodes)
this.setState({existingLoaded: true, nodes: nodes})
} }
async spawnNode() { async spawnNode() {
const node = await this.props.client.call('Pond.Spawn') const node = await this.props.client.call('Pond.Spawn')
console.log(node) console.log(node)
this.setState(state => ({nodes: state.nodes.concat(node)})) this.setState(state => ({nodes: {...state.nodes, [node.ID]: node}}))
} }
connMgr() { connMgr() {
@ -43,10 +50,13 @@ class NodeList extends React.Component {
</div> </div>
<div> <div>
{ {
this.state.nodes.map((node, i) => { Object.keys(this.state.nodes).map(n => {
const node = this.state.nodes[n]
return (<FullNode key={node.ID} return (<FullNode key={node.ID}
node={node} node={{...node}}
pondClient={this.props.client}/>) pondClient={this.props.client}
onConnect={conn => this.setState(prev => ({nodes: {...prev.nodes, [n]: {...node, conn: conn}}}))}/>)
}) })
} }
{connMgr} {connMgr}