fathom/assets/js/script.js

36 lines
696 B
JavaScript
Raw Normal View History

'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
})
}
render(props, state) {
2016-11-23 18:40:35 +00:00
// logged-in
if( state.authenticated ) {
2018-05-03 08:54:22 +00:00
return <Dashboard onLogout={this.toggleAuth} />
}
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-23 18:40:35 +00:00
render(<App />, document.getElementById('root'));