mirror of
https://github.com/plausible/analytics.git
synced 2024-12-30 13:03:23 +03:00
e8f20e67cc
* Load dashboard with react * Rename stast2 to dashboard * Save timeframe on the frontend * Implement current visitors * Implement comparisons * React to route changes * Add modals * Show number of visitors on hover * Show 'Today' for today * Add 30 days * Show referrer drilldown * Arrow keys to go back and forward * Improve comparisons UI * Fix dropdown when clicking on it * Verify API access in a memoized fashion * Test API access * Test stats through controller * Move map formatting from stats controller to stats * Remove unused code * Remove dead code from query * Remove dead code from stats templates * Add stats view test back in * Render modal inside the modal component * Implement google search terms * Add explanation for screen sizes * Separate dashboard JS from the app js
42 lines
1.0 KiB
JavaScript
42 lines
1.0 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/${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-grey-darker mt-2 mt-0">
|
|
<svg className="w-2 mr-1 fill-current text-green" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
|
<circle cx="8" cy="8" r="8"/>
|
|
</svg>
|
|
<span> {this.state.currentVisitors}</span> current visitors
|
|
</div>
|
|
)
|
|
} else {
|
|
return null
|
|
}
|
|
}
|
|
}
|