import React from 'react'; import { Link } from 'react-router-dom' import FadeIn from '../../fade-in' import numberFormatter from '../../number-formatter' import Bar from '../bar' import * as api from '../../api' export default class Browsers extends React.Component { constructor(props) { super(props) this.state = {loading: true} } componentDidMount() { this.fetchBrowsers() if (this.props.timer) this.props.timer.onTick(this.fetchBrowsers.bind(this)) } componentDidUpdate(prevProps) { if (this.props.query !== prevProps.query) { this.setState({loading: true, browsers: null}) this.fetchBrowsers() } } fetchBrowsers() { if (this.props.query.filters.browser) { api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/browser-versions`, this.props.query) .then((res) => this.setState({loading: false, browsers: res})) } else { api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/browsers`, this.props.query) .then((res) => this.setState({loading: false, browsers: res})) } } renderBrowser(browser) { const query = new URLSearchParams(window.location.search) if (this.props.query.filters.browser) { query.set('browser_version', browser.name) } else { query.set('browser', browser.name) } return (