import React from 'react'; import FadeIn from '../fade-in' import Bar from './bar' import MoreLink from './more-link' import numberFormatter from '../number-formatter' import { eventName } from '../query' import * as api from '../api' export default class Pages extends React.Component { constructor(props) { super(props) this.state = { loading: true } } componentDidMount() { this.fetchPages() } componentDidUpdate(prevProps) { if (this.props.query !== prevProps.query) { this.setState({loading: true, pages: null}) this.fetchPages() } } fetchPages() { api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/pages`, this.props.query) .then((res) => this.setState({loading: false, pages: res})) } renderPage(page) { return (
{page.name}
{numberFormatter(page.count)}
) } renderList() { if (this.state.pages.length > 0) { return (
Page url Pageviews
{ this.state.pages.map(this.renderPage.bind(this)) }
) } else { return
No data yet
} } renderContent() { if (this.state.pages) { return (

Top Pages

{ this.renderList() }
) } } render() { return (
{ this.state.loading &&
} { this.renderContent() }
) } }