fathom/assets/js/script.js

28 lines
615 B
JavaScript
Raw Normal View History

'use strict';
2016-11-23 18:40:35 +00:00
import { h, render, Component } from 'preact';
2016-11-24 15:29:11 +00:00
import Login from './pages/login.js';
import Dashboard from './pages/dashboard.js';
2016-11-22 21:33:50 +00:00
2016-11-23 18:40:35 +00:00
class App extends Component {
constructor(props) {
super(props)
2016-11-22 21:33:50 +00:00
2016-11-24 15:29:11 +00:00
this.state = {
authenticated: document.cookie.indexOf('auth') > -1
2016-11-22 21:33:50 +00:00
}
2016-11-23 18:40:35 +00:00
}
render() {
// logged-in
if( this.state.authenticated ) {
2016-11-24 15:29:11 +00:00
return <Dashboard onLogout={() => this.setState({ authenticated: false })} />
}
2016-11-23 18:40:35 +00:00
// logged-out
2016-11-24 15:29:11 +00:00
return <Login onLogin={() => this.setState({ authenticated: true })} />
2016-11-22 21:33:50 +00:00
}
}
2016-11-23 18:40:35 +00:00
render(<App />, document.getElementById('root'));