import React, { useState } from 'react'; import { makeStyles } from '@material-ui/core/styles'; import { Table, TableBody, TableCell, TableContainer, TableRow, TableHead, Button, Paper, Tooltip, Container, CircularProgress } from '@material-ui/core'; import { Autorenew } from '@material-ui/icons'; import { beeDebugApi } from '../../services/bee'; import type { Peer } from '@ethersphere/bee-js'; const useStyles = makeStyles({ table: { minWidth: 650, }, }); interface Props { peers: Peer[] | null isLoading: boolean error: Error | null } function PeerTable(props: Props) { const classes = useStyles(); const [peerLatency, setPeerLatency] = useState([{ peerId: '', rtt: '', loading: false }]); const PingPeer = async (peerId: string) => { setPeerLatency([...peerLatency, { peerId: peerId, rtt: '', loading: true }]) beeDebugApi.connectivity.ping(peerId) .then(res => { setPeerLatency([...peerLatency, { peerId: peerId, rtt: res.data.rtt, loading: false }]) }) .catch(error => { setPeerLatency([...peerLatency, { peerId: peerId, rtt: 'error', loading: false }]) }) } if (props.isLoading) { return ( ) } if (props.error || props.peers === null) { return (

Failed to load peers

) } return (
Index Peer Id Actions {props.peers.map((peer: any, idx: number) => ( {idx + 1} {peer.address} ))}
) } export default PeerTable