import React from 'react'; import { Link } from 'react-router-dom' import * as api from '../api' import * as url from '../util/url' import { appliedFilters } from '../query'; import { Tooltip } from '../util/tooltip'; import { SecondsSinceLastLoad } from '../util/seconds-since-last-load'; export default class CurrentVisitors extends React.Component { constructor(props) { super(props) this.state = {currentVisitors: null} this.updateCount = this.updateCount.bind(this) } componentDidMount() { this.updateCount() document.addEventListener('tick', this.updateCount) } componentWillUnmount() { document.removeEventListener('tick', this.updateCount) } updateCount() { return api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/current-visitors`) .then((res) => this.setState({currentVisitors: res})) } tooltipInfo() { return (

Last updated s ago

Click to view realtime dashboard

) } render() { if (appliedFilters(this.props.query).length >= 1) { return null } const { currentVisitors } = this.state; if (currentVisitors !== null) { return ( {currentVisitors} current visitor{currentVisitors === 1 ? '' : 's'} ) } return null } }