2016-11-23 18:40:35 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import { h, render, Component } from 'preact';
|
2016-12-08 11:27:19 +00:00
|
|
|
import Client from '../lib/client.js';
|
2018-05-01 14:06:17 +00:00
|
|
|
import { bind } from 'decko';
|
2016-11-23 18:40:35 +00:00
|
|
|
|
|
|
|
class Realtime extends Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
count: 0
|
|
|
|
}
|
2018-05-01 17:45:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.fetchData();
|
|
|
|
window.setInterval(this.fetchData, 15000);
|
2016-11-23 18:40:35 +00:00
|
|
|
}
|
|
|
|
|
2018-05-01 14:06:17 +00:00
|
|
|
@bind
|
2016-11-23 18:40:35 +00:00
|
|
|
fetchData() {
|
2016-12-10 13:16:05 +00:00
|
|
|
Client.request(`visitors/count/realtime`)
|
2016-12-08 11:27:19 +00:00
|
|
|
.then((d) => { this.setState({ count: d })})
|
2016-11-23 18:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let visitors = this.state.count == 1 ? 'visitor' : 'visitors';
|
|
|
|
return (
|
2018-05-01 14:06:17 +00:00
|
|
|
<span><span class="count">{this.state.count}</span> <span>current {visitors}</span></span>
|
2016-11-23 18:40:35 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Realtime
|