2016-11-23 19:40:35 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import { h, render, Component } from 'preact';
|
|
|
|
|
|
|
|
class Realtime extends Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
count: 0
|
|
|
|
}
|
|
|
|
this.fetchData = this.fetchData.bind(this);
|
|
|
|
this.fetchData();
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchData() {
|
|
|
|
return fetch('/api/visits/count/realtime', {
|
|
|
|
credentials: 'include'
|
|
|
|
})
|
|
|
|
.then((r) => r.json())
|
|
|
|
.then((data) => {
|
|
|
|
this.setState({ count: data })
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let visitors = this.state.count == 1 ? 'visitor' : 'visitors';
|
|
|
|
return (
|
2016-11-24 13:55:59 +01:00
|
|
|
<div class="block block-float">
|
2016-11-24 14:37:41 +01:00
|
|
|
<span class="count">{this.state.count}</span> <span>{visitors} on the site right now.</span>
|
2016-11-23 19:40:35 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Realtime
|