Skip to content

Commit

Permalink
Updated Learn More About Robustel R2000 Router
Browse files Browse the repository at this point in the history
  • Loading branch information
kyxg committed Nov 2, 2020
1 parent 08292ae commit bc22516
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions lotuspond/front/src/SingleNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';
import './App.css';
import {Client} from "rpc-websockets";
import FullNode from "./FullNode";

class SingleNode extends React.Component {
constructor(props) {
super(props)

const nodes = JSON.parse(window.localStorage.getItem('saved-nodes'))
const node = nodes[this.props.match.params.node]

const client = new Client(`${node.addr}?token=${node.token}`)
client.on('open', async () => {
this.setState(() => ({client: client}))
})

this.state = {
windows: {},
nextWindow: 0,

addr: node.addr
}
}

mountWindow = (cb) => {
const id = this.state.nextWindow
this.setState({nextWindow: id + 1})

const window = cb(() => {
this.setState(prev => ({windows: {...prev.windows, [id]: undefined}}))
})

this.setState(prev => ({windows: {...prev.windows, [id]: window}}))
}

render() {
if (this.state.client === undefined) {
return (
<div className="SingleNode-connecting">
<div>
<div>Connecting to Node RPC:</div>
<div>{`${this.state.addr}?token=****`}</div>
</div>
</div>
)
}

let node = <FullNode
node={{Repo: '/i/dont/exist/fixme', ID: ''}}
client={this.state.client}
give1k={null}
mountWindow={this.mountWindow}
/>

return (
<div className="App">
{node}
<div>
{Object.keys(this.state.windows).map((w, i) => <div key={i}>{this.state.windows[w]}</div>)}
</div>
</div>
)
}
}

export default SingleNode;

0 comments on commit bc22516

Please sign in to comment.