import React from 'react'; import Bar from './bar' import MoreLink from './more-link' import * as api from '../api' export default class OperatingSystems extends React.Component { constructor(props) { super(props) this.state = {loading: true} } componentDidMount() { this.fetchOperatingSystems() } componentDidUpdate(prevProps) { if (this.props.query !== prevProps.query) { this.setState({loading: true, systems: null}) this.fetchOperatingSystems() } } fetchOperatingSystems() { api.get(`/api/stats/${this.props.site.domain}/operating-systems`, this.props.query) .then((res) => this.setState({loading: false, systems: res})) } renderSystem(system) { return (
{system.name} {system.percentage}%
) } render() { if (this.state.loading) { return (
) } else if (this.state.systems) { return (

Operating Systems

by visitors
{ this.state.systems.map(this.renderSystem.bind(this)) }
) } } }