fathom/assets/js/pages/dashboard.js

69 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-11-24 15:29:11 +00:00
'use strict'
2018-05-03 08:54:22 +00:00
import { h, Component } from 'preact';
2018-05-01 14:06:17 +00:00
import LogoutButton from '../components/LogoutButton.js';
2016-11-24 15:29:11 +00:00
import Realtime from '../components/Realtime.js';
import DatePicker from '../components/DatePicker.js';
import CountWidget from '../components/CountWidget.js';
2018-05-01 14:06:17 +00:00
import Table from '../components/Table.js';
2016-11-24 15:29:11 +00:00
2018-05-01 14:06:17 +00:00
import { bind } from 'decko';
2016-11-26 15:17:52 +00:00
2016-11-24 15:29:11 +00:00
class Dashboard extends Component {
constructor(props) {
super(props)
this.state = {
2018-05-01 14:06:17 +00:00
period: (window.location.hash.substring(2) || 'week'),
before: 0,
after: 0,
2016-11-24 15:29:11 +00:00
}
}
2018-05-01 14:06:17 +00:00
@bind
changePeriod(s) {
this.setState({ period: s.period, before: s.before, after: s.after })
window.history.replaceState(this.state, null, `#!${s.period}`)
2016-11-24 15:29:11 +00:00
}
2018-05-01 14:06:17 +00:00
render(props, state) {
2016-11-25 12:16:42 +00:00
return (
2018-05-11 12:15:58 +00:00
<div class="app-page wrapper">
2018-05-01 14:06:17 +00:00
<header class="section">
<nav class="main-nav animated fadeInDown">
<ul>
<li class="logo"><a href="/">Fathom</a></li>
2018-05-15 12:31:51 +00:00
<li class="visitors"><Realtime onError={props.onLogout} /></li>
2018-05-01 14:06:17 +00:00
<li class="spacer">&middot;</li>
2018-05-15 12:31:51 +00:00
<li class="signout"><LogoutButton onSuccess={props.onLogout} /></li>
2018-05-01 14:06:17 +00:00
</ul>
</nav>
</header>
<section class="section animated fadeInUp delayed_02s">
<nav class="date-nav">
<DatePicker onChange={this.changePeriod} value={state.period} />
</nav>
<div class="boxes">
<div class="box box-totals animated fadeInUp delayed_03s">
<CountWidget title="Unique visitors" endpoint="stats/site/visitors" before={state.before} after={state.after} />
<CountWidget title="Page views" endpoint="stats/site/pageviews" before={state.before} after={state.after} />
<CountWidget title="Avg time on site" endpoint="stats/site/duration" format="duration" before={state.before} after={state.after} />
<CountWidget title="Bounce rate" endpoint="stats/site/bounces" format="percentage" before={state.before} after={state.after} />
2016-11-24 15:47:33 +00:00
</div>
2018-05-01 14:06:17 +00:00
2018-05-07 17:20:58 +00:00
<Table endpoint="stats/pages" headers={["Top pages", "Views", "Uniques"]} before={state.before} after={state.after} />
<Table endpoint="stats/referrers" headers={["Top referrers", "Views", "Uniques"]} before={state.before} after={state.after} showHostname="true" />
2018-05-01 14:06:17 +00:00
2016-11-24 15:29:11 +00:00
</div>
2018-05-01 14:06:17 +00:00
</section>
<footer class="section"></footer>
</div>
2016-11-25 12:16:42 +00:00
)}
2016-11-24 15:29:11 +00:00
}
export default Dashboard