Show a not-logged-in view when you're not logged in.

This commit is contained in:
joshaber 2016-05-27 16:50:08 -04:00
parent 356474a869
commit cf9d3143f1
2 changed files with 22 additions and 20 deletions

View file

@ -2,11 +2,12 @@ import * as React from 'react'
import ThingList from './thing-list'
import Info from './info'
import UsersStore from './users-store'
const Octokat = require('octokat')
import User from './user'
import NotLoggedIn from './not-logged-in'
type AppState = {
selectedRow: number
selectedRow: number,
user: User
}
type AppProps = {
@ -21,27 +22,14 @@ const AppStyle = {
}
export default class App extends React.Component<AppProps, AppState> {
private octo: any
public constructor(props: AppProps) {
super(props)
this.octo = new Octokat({
token: process.env.GITHUB_ACCESS_TOKEN
})
props.usersStore.onUsersChanged(users => {
console.log('users', users)
this.setState({selectedRow: this.state.selectedRow, user: users[0]})
})
console.log('users', props.usersStore.getUsers())
this.state = {selectedRow: -1}
}
public async componentDidMount() {
const zen = await this.octo.zen.read()
console.log('zen', zen)
this.state = {selectedRow: -1, user: props.usersStore.getUsers()[0]}
}
public render() {
@ -49,12 +37,12 @@ export default class App extends React.Component<AppProps, AppState> {
return (
<div style={completeStyle}>
<ThingList selectedRow={this.state.selectedRow} onSelectionChanged={row => this.handleSelectionChanged(row)}/>
<Info selectedRow={this.state.selectedRow}/>
{this.state.user ? <Info selectedRow={this.state.selectedRow} user={this.state.user}/> : <NotLoggedIn/>}
</div>
)
}
private handleSelectionChanged(row: number) {
this.setState({selectedRow: row})
this.setState({selectedRow: row, user: this.state.user})
}
}

14
src/not-logged-in.tsx Normal file
View file

@ -0,0 +1,14 @@
import * as React from 'react'
import {askUserToAuth} from './auth'
export default class NotLoggedIn extends React.Component<void, void> {
public render() {
return (
<div>
<div>You don't seem to be logged in.</div>
<button onClick={() => askUserToAuth()}>Log In For Great Glory</button>
</div>
)
}
}