2016-11-21 12:24:50 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-01-06 14:58:50 +00:00
|
|
|
import { h, render, Component } from 'preact'
|
|
|
|
import Login from './pages/login.js'
|
|
|
|
import Dashboard from './pages/dashboard.js'
|
2018-05-03 08:54:22 +00:00
|
|
|
import { bind } from 'decko';
|
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
|
|
|
}
|
|
|
|
|
2018-05-03 08:54:22 +00:00
|
|
|
@bind
|
|
|
|
toggleAuth() {
|
|
|
|
this.setState({
|
|
|
|
authenticated: !this.state.authenticated
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-11-23 18:40:35 +00:00
|
|
|
render() {
|
|
|
|
// logged-in
|
|
|
|
if( this.state.authenticated ) {
|
2018-05-03 08:54:22 +00:00
|
|
|
return <Dashboard onLogout={this.toggleAuth} />
|
2016-11-23 14:51:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-23 18:40:35 +00:00
|
|
|
// logged-out
|
2018-05-03 08:54:22 +00:00
|
|
|
return <Login onLogin={this.toggleAuth} />
|
2016-11-22 21:33:50 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-21 15:01:14 +00:00
|
|
|
|
2016-11-23 18:40:35 +00:00
|
|
|
render(<App />, document.getElementById('root'));
|