Browse Source

feature(network): setup right side

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
e8ab27fb56
  1. 22
      app/components/Network/PeersList.js
  2. 18
      app/components/Network/PeersList.scss
  3. 30
      app/reducers/network.js
  4. 52
      app/routes/network/components/Network.js
  5. 53
      app/routes/network/components/Network.scss
  6. 11
      app/routes/network/containers/NetworkContainer.js

22
app/components/Network/PeersList.js

@ -0,0 +1,22 @@
import React from 'react'
import PropTypes from 'prop-types'
import styles from './PeersList.scss'
const PeersList = ({ peers }) => (
<ul>
{
peers.map(peer =>
<li className={styles.peer} key={peer.peer_id}>
<h1>{peer.address}</h1>
<h4>{peer.pub_key}</h4>
</li>
)
}
</ul>
)
PeersList.propTypes = {
peers: PropTypes.array.isRequired
}
export default PeersList

18
app/components/Network/PeersList.scss

@ -0,0 +1,18 @@
@import '../../variables.scss';
.peer {
margin: 20px 0;
cursor: pointer;
&:hover {
opacity: 0.5;
}
h1 {
margin-bottom: 5px;
}
h4 {
font-size: 10px;
}
}

30
app/reducers/network.js

@ -14,6 +14,10 @@ export const SET_CURRENT_ROUTE = 'SET_CURRENT_ROUTE'
export const SET_CURRENT_CHANNEL = 'SET_CURRENT_CHANNEL' export const SET_CURRENT_CHANNEL = 'SET_CURRENT_CHANNEL'
export const SET_CURRENT_TAB = 'SET_CURRENT_TAB'
export const SET_CURRENT_PEER = 'SET_CURRENT_PEER'
// ------------------------------------ // ------------------------------------
// Actions // Actions
// ------------------------------------ // ------------------------------------
@ -44,6 +48,20 @@ export function setCurrentChannel(selectedChannel) {
} }
} }
export function setCurrentTab(currentTab) {
return {
type: SET_CURRENT_TAB,
currentTab
}
}
export function setCurrentPeer(currentPeer) {
return {
type: SET_CURRENT_PEER,
currentPeer
}
}
// Send IPC event for describeNetwork // Send IPC event for describeNetwork
export const fetchDescribeNetwork = () => (dispatch) => { export const fetchDescribeNetwork = () => (dispatch) => {
dispatch(getDescribeNetwork()) dispatch(getDescribeNetwork())
@ -83,7 +101,11 @@ const ACTION_HANDLERS = {
} }
), ),
[SET_CURRENT_CHANNEL]: (state, { selectedChannel }) => ({ ...state, selectedChannel }) [SET_CURRENT_CHANNEL]: (state, { selectedChannel }) => ({ ...state, selectedChannel }),
[SET_CURRENT_TAB]: (state, { currentTab }) => ({ ...state, currentTab }),
[SET_CURRENT_PEER]: (state, { currentPeer }) => ({ ...state, currentPeer })
} }
// ------------------------------------ // ------------------------------------
@ -115,7 +137,11 @@ const initialState = {
routes: [], routes: [],
currentRoute: {} currentRoute: {}
}, },
selectedChannel: {} selectedChannel: {},
currentTab: 1,
currentPeer: {}
} }

52
app/routes/network/components/Network.js

@ -2,20 +2,27 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { InteractiveForceGraph, ForceGraphNode, ForceGraphLink } from 'react-vis-force' import { InteractiveForceGraph, ForceGraphNode, ForceGraphLink } from 'react-vis-force'
import LoadingBolt from '../../../components/LoadingBolt' import LoadingBolt from 'components/LoadingBolt'
import PeersList from 'components/Network/PeersList'
import styles from './Network.scss' import styles from './Network.scss'
class Network extends Component { class Network extends Component {
componentWillMount() { componentWillMount() {
const { fetchDescribeNetwork } = this.props const { fetchDescribeNetwork, fetchPeers, fetchChannels } = this.props
fetchDescribeNetwork() fetchDescribeNetwork()
fetchPeers()
fetchChannels()
} }
render() { render() {
const { const {
network: { nodes, edges, selectedNode, networkLoading }, setCurrentTab,
network: { nodes, edges, selectedNode, networkLoading, currentTab },
peers: { peers },
channels,
identity_pubkey identity_pubkey
} = this.props } = this.props
@ -23,6 +30,20 @@ class Network extends Component {
if (networkLoading) return <LoadingBolt /> if (networkLoading) return <LoadingBolt />
const renderTab = () => {
switch(currentTab) {
case 1:
return <PeersList peers={peers} />
break
case 2:
return <h1>channels</h1>
break
case 3:
return <h1>transaction</h1>
break
}
}
return ( return (
<div className={styles.container}> <div className={styles.container}>
<section className={styles.network}> <section className={styles.network}>
@ -30,7 +51,7 @@ class Network extends Component {
simulationOptions={ simulationOptions={
{ {
height: 1000, height: 1000,
width: 1000, width: 800,
strength: { strength: {
charge: -750 charge: -750
}, },
@ -76,6 +97,29 @@ class Network extends Component {
} }
</InteractiveForceGraph> </InteractiveForceGraph>
</section> </section>
<section className={styles.data}>
<header>
<h1>Toolbox</h1>
</header>
<ul className={styles.tabs}>
<li className={`${styles.tab} ${currentTab === 1 && styles.active}`} onClick={() => setCurrentTab(1)}>
<h2>Peers</h2>
</li>
<li className={`${styles.tab} ${currentTab === 2 && styles.active}`} onClick={() => setCurrentTab(2)}>
<h2>Channels</h2>
</li>
<li className={`${styles.tab} ${currentTab === 3 && styles.active}`} onClick={() => setCurrentTab(3)}>
<h2>Transaction</h2>
</li>
</ul>
<div className={styles.currentTab}>
{
renderTab()
}
</div>
</section>
</div> </div>
) )
} }

53
app/routes/network/components/Network.scss

@ -44,42 +44,51 @@
} }
.data { .data {
width: 30%; width: calc(30% - 1px);
background: $black;
color: #00FF00; color: #00FF00;
word-wrap: break-word; word-wrap: break-word;
overflow-y: scroll; overflow-y: scroll;
border-left: 1px solid $darkgrey;
header, .routes { font-family: 'Courier New';
padding: 10px;
}
header { header {
margin-top: 50px; margin: 20px 0;
padding: 20px;
border-bottom: 1px solid $darkgrey;
h1 span { h1 {
display: block; font-weight: bold;
margin: 5px 0; font-size: 30px;
&:nth-child(2) {
font-size: 12px;
}
} }
} }
.routes {
.route { .tabs {
padding: 0 20px;
display: flex;
flex-direction: row;
.tab {
padding: 10px;
cursor: pointer; cursor: pointer;
margin: 20px 0; transition: all 0.25s;
&.active { &:hover {
background: #00FF00; background: #00FF00;
color: black; color: $black;
opacity: 0.5;
} }
&:hover { &.active {
opacity: 0.5; background: #00FF00;
color: $black;
} }
} }
}
.currentTab {
margin-top: 20px;
padding: 20px;
} }
} }

11
app/routes/network/containers/NetworkContainer.js

@ -1,16 +1,23 @@
import { withRouter } from 'react-router' import { withRouter } from 'react-router'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { fetchDescribeNetwork } from 'reducers/network' import { fetchDescribeNetwork, setCurrentTab } from 'reducers/network'
import { fetchPeers } from 'reducers/peers'
import { fetchChannels } from 'reducers/channels'
import Network from '../components/Network' import Network from '../components/Network'
const mapDispatchToProps = { const mapDispatchToProps = {
fetchDescribeNetwork setCurrentTab,
fetchDescribeNetwork,
fetchPeers,
fetchChannels
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
network: state.network, network: state.network,
peers: state.peers,
channels: state.channels,
identity_pubkey: state.info.data.identity_pubkey identity_pubkey: state.info.data.identity_pubkey
}) })

Loading…
Cancel
Save