mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-28 15:24:19 +01:00
44 lines
1.0 KiB
JavaScript
44 lines
1.0 KiB
JavaScript
|
import React from 'react'
|
||
|
import { Button } from '@material-ui/core'
|
||
|
import { refreshInfo, getInfo } from './system'
|
||
|
import SSRIcon from '@material-ui/icons/SignalCellularNull'
|
||
|
import ConnectedIcon from '@material-ui/icons/SignalCellular1Bar'
|
||
|
|
||
|
class Status extends React.PureComponent {
|
||
|
state = { info: getInfo() || {} }
|
||
|
|
||
|
componentDidMount() {
|
||
|
this.refresh()
|
||
|
}
|
||
|
|
||
|
componentWillUnmount() {
|
||
|
clearTimeout(this.state.timeout)
|
||
|
}
|
||
|
|
||
|
async refresh() {
|
||
|
const info = await refreshInfo()
|
||
|
this.setState({
|
||
|
info, timeout: setTimeout(this.refresh.bind(this), 3000)
|
||
|
})
|
||
|
}
|
||
|
|
||
|
render() {
|
||
|
const { info } = this.state
|
||
|
let Icon = SSRIcon
|
||
|
let statusText = 'Pre-Rendered'
|
||
|
if (!info.isServer) {
|
||
|
statusText = 'Offline'
|
||
|
if (info.ipfsReady) {
|
||
|
statusText = 'Starting DB'
|
||
|
Icon = ConnectedIcon
|
||
|
}
|
||
|
if (info.orbitDbReady) statusText = `${info.ipfsPeers.length} Peers`
|
||
|
}
|
||
|
|
||
|
return <Button color="inherit">
|
||
|
{statusText} <Icon />
|
||
|
</Button>
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default Status
|