'use strict'; import { h, render, Component } from 'preact'; import * as numbers from '../lib/numbers.js'; import Client from '../lib/client.js'; const dayInSeconds = 60 * 60 * 24; class Pageviews extends Component { constructor(props) { super(props) this.state = { records: [] } this.fetchRecords = this.fetchRecords.bind(this); } componentDidMount() { this.fetchRecords(this.props.period); } componentWillReceiveProps(newProps) { if(this.props.period != newProps.period) { this.fetchRecords(newProps.period) } } fetchRecords(period) { const before = Math.round((+new Date() ) / 1000); const after = before - ( period * dayInSeconds ); Client.request(`/pageviews?before=${before}&after=${after}`) .then((d) => { this.setState({ records: d })}) .catch((e) => { console.log(e) }) } render() { const tableRows = this.state.records.map( (p, i) => ( {i+1} {p.Path.substring(0, 50)}{p.Path.length > 50 ? '..' : ''} {numbers.formatWithComma(p.Count)} {numbers.formatWithComma(p.CountUnique)} )); return (

Pageviews

{tableRows}
# URL Pageviews Unique
) } } export default Pageviews