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