analytics/assets/js/dashboard/stats/current-visitors.js
Uku Taht 32937c53d1
Upgrade tailwind to 1.2.0 (#42)
* Upgrade config file

* Upgrade grey colour

* Update styles for dashboard

* Update styles for new site flow

* Update styles for user settings

* Update site setting styles

* Update other pages

* Adjust spacing

* Update last grey rules

* Purge css
2020-03-06 11:11:38 +02:00

42 lines
1.1 KiB
JavaScript

import React from 'react';
const THIRTY_SECONDS = 30000
export default class CurrentVisitors extends React.Component {
constructor(props) {
super(props)
this.state = {currentVisitors: null}
}
componentDidMount() {
this.updateCount().then(() => {
this.intervalId = setInterval(this.updateCount.bind(this), THIRTY_SECONDS)
})
}
componentWillUnMount() {
clearInverval(this.intervalId)
}
updateCount() {
return fetch(`/api/stats/${encodeURIComponent(this.props.site.domain)}/current-visitors`)
.then(res => res.json())
.then((res) => this.setState({currentVisitors: res}))
}
render() {
if (this.state.currentVisitors !== null) {
return (
<div className="text-sm font-bold text-gray-600 mt-1">
<svg className="w-2 mr-2 fill-current text-green-500 inline" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<circle cx="8" cy="8" r="8"/>
</svg>
{this.state.currentVisitors} current visitors
</div>
)
} else {
return null
}
}
}