1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-26 15:04:19 +01:00
ipfs-boards/components/Status.js

45 lines
1.1 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.ipfsLoading) statusText = 'Starting IPFS'
if (info.ipfsReady) {
Icon = ConnectedIcon
statusText = `${info.ipfsPeers.length} Peers`
}
if (info.orbitDbLoading) statusText = 'Starting DB'
}
return <Button color="inherit">
{statusText} <Icon />
</Button>
}
}
export default Status