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' import LazyLoader from '../../lazy-loader' export default class OperatingSystems extends React.Component { constructor(props) { super(props) this.state = {loading: true} this.onVisible = this.onVisible.bind(this) } onVisible() { this.fetchOperatingSystems() if (this.props.timer) this.props.timer.onTick(this.fetchOperatingSystems.bind(this)) } componentDidUpdate(prevProps) { if (this.props.query !== prevProps.query) { this.setState({loading: true, operatingSystems: null}) this.fetchOperatingSystems() } } fetchOperatingSystems() { if (this.props.query.filters.os) { api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/operating-system-versions`, this.props.query) .then((res) => this.setState({loading: false, operatingSystems: res})) } else { api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/operating-systems`, this.props.query) .then((res) => this.setState({loading: false, operatingSystems: res})) } } renderOperatingSystem(os) { const query = new URLSearchParams(window.location.search) if (this.props.query.filters.os) { query.set('os_version', os.name) } else { query.set('os', os.name) } return (