fathom/assets/js/script.js

57 lines
1.3 KiB
JavaScript
Raw Normal View History

'use strict';
const m = require('mithril');
2016-11-22 21:33:50 +00:00
import Login from './components/login.js';
import Pageviews from './components/pageviews.js';
import RealtimeVisits from './components/realtime.js';
import VisitsGraph from './components/visits-graph.js';
2016-11-23 15:29:07 +00:00
import LogoutButton from './components/logoutButton.js';
2016-11-22 21:33:50 +00:00
const App = {
controller(args) {
this.state = {
2016-11-23 15:33:52 +00:00
authenticated: document.cookie.indexOf('auth') > -1
};
2016-11-22 21:33:50 +00:00
this.setState = function(nextState) {
m.startComputation();
for(var k in nextState) {
this.state[k] = nextState[k];
}
m.endComputation();
2016-11-22 21:33:50 +00:00
}
},
view(c) {
if( ! c.state.authenticated ) {
2016-11-23 15:33:52 +00:00
return m('div.container', [
m.component(Login, {
2016-11-23 15:29:07 +00:00
onAuth: () => {
c.setState({ authenticated: true })
}
2016-11-23 15:33:52 +00:00
})
]);
}
return [
m('div.container', [
2016-11-23 15:29:07 +00:00
m('div.header.cf', [
m('h1.pull-left', 'Ana'),
m('div.pull-right', [
m.component(LogoutButton, {
cb: () => {
c.setState({ authenticated: false })
}
})
]),
]),
m.component(RealtimeVisits),
m.component(VisitsGraph),
m.component(Pageviews),
])
]
2016-11-22 21:33:50 +00:00
}
}
m.mount(document.getElementById('root'), App)