mirror of
https://github.com/plausible/analytics.git
synced 2024-12-21 08:31:29 +03:00
3999f282a5
* extract blinkingDot function * position pulsating-circle with tailwind instead * remove unused function * extract renderStatName function * display seconds since last realtime update Adds a 'Last updated X seconds ago' label to the Current Visitors tooltip. * small refactor: avoid duplication of this.props and this.state * show the 'last updated ...' tooltip in historical * changelog update * use className utility function
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
import React from 'react';
|
|
import { withRouter } from 'react-router-dom'
|
|
|
|
import Historical from './historical'
|
|
import Realtime from './realtime'
|
|
import {parseQuery} from './query'
|
|
import * as api from './api'
|
|
import { withComparisonProvider } from './comparison-provider-hoc';
|
|
|
|
class Dashboard extends React.Component {
|
|
constructor(props) {
|
|
super(props)
|
|
this.updateLastLoadTimestamp = this.updateLastLoadTimestamp.bind(this)
|
|
this.state = {
|
|
query: parseQuery(props.location.search, this.props.site),
|
|
lastLoadTimestamp: new Date()
|
|
}
|
|
}
|
|
|
|
componentDidMount() {
|
|
document.addEventListener('tick', this.updateLastLoadTimestamp)
|
|
}
|
|
|
|
componentDidUpdate(prevProps) {
|
|
if (prevProps.location.search !== this.props.location.search) {
|
|
api.cancelAll()
|
|
this.setState({query: parseQuery(this.props.location.search, this.props.site)})
|
|
this.updateLastLoadTimestamp()
|
|
}
|
|
}
|
|
|
|
updateLastLoadTimestamp() {
|
|
this.setState({lastLoadTimestamp: new Date()})
|
|
}
|
|
|
|
render() {
|
|
const { site, loggedIn, currentUserRole } = this.props
|
|
const { query, lastLoadTimestamp } = this.state
|
|
|
|
if (this.state.query.period === 'realtime') {
|
|
return <Realtime site={site} loggedIn={loggedIn} currentUserRole={currentUserRole} query={query} lastLoadTimestamp={lastLoadTimestamp}/>
|
|
} else {
|
|
return <Historical site={site} loggedIn={loggedIn} currentUserRole={currentUserRole} query={query} lastLoadTimestamp={lastLoadTimestamp}/>
|
|
}
|
|
}
|
|
}
|
|
|
|
export default withRouter(withComparisonProvider(Dashboard))
|