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'
|
2018-05-03 10:54:22 +02:00
|
|
|
import { bind } from 'decko';
|
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
|
|
|
}
|
|
|
|
|
2018-05-03 10:54:22 +02:00
|
|
|
@bind
|
|
|
|
toggleAuth() {
|
|
|
|
this.setState({
|
|
|
|
authenticated: !this.state.authenticated
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-11-23 19:40:35 +01:00
|
|
|
render() {
|
|
|
|
// logged-in
|
|
|
|
if( this.state.authenticated ) {
|
2018-05-03 10:54:22 +02:00
|
|
|
return <Dashboard onLogout={this.toggleAuth} />
|
2016-11-23 15:51:19 +01:00
|
|
|
}
|
|
|
|
|
2016-11-23 19:40:35 +01:00
|
|
|
// logged-out
|
2018-05-03 10:54:22 +02:00
|
|
|
return <Login onLogin={this.toggleAuth} />
|
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'));
|