Skip to content

Commit

Permalink
dashboard.jsx: Use withAuth wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
li-boxuan committed Aug 7, 2018
1 parent d4705c5 commit d1a9bf2
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions src/components/dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Client from '../github-client';
import CurrentUserStore from '../user-store';
import AsyncButton from './async-button';
import Time from './time';
import withAuth from './login-auth';

const SAMPLE_REPOS = [
{repoOwner: 'huboard', repoName: 'huboard'},
Expand Down Expand Up @@ -335,28 +336,14 @@ class ExamplesPanel extends Component {
class DashboardShell extends Component {
state = {repos: null};

componentDidMount() {
Client.on('changeToken', this.onChangeToken);
this.onChangeToken();
}

componentWillUnmount() {
Client.off('changeToken', this.onChangeToken);
componentDidUpdate(prevProps) {
if (this.props.loginInfo && this.props.loginInfo !== prevProps.loginInfo) {
Client.dbPromise().then(() => Client.getOcto().user.repos.fetchAll())
.then((allRepos) => this.setState({repos: allRepos}))
.catch(() => this.setState({repos: []}));
}
}

onChangeToken = () => {
CurrentUserStore.fetchUser()
.then((currentUser) => {
if (currentUser) {
return Client.dbPromise().then(() => Client.getOcto().user.repos.fetchAll());
} else {
return []; // Anonymous has no repos
}
})
.then((allRepos) => this.setState({repos: allRepos}))
.catch(() => this.setState({repos: []}));
};

render() {
let {repos} = this.state;

Expand Down Expand Up @@ -390,4 +377,4 @@ class DashboardShell extends Component {
}
}

export default DashboardShell;
export default withAuth(DashboardShell);

0 comments on commit d1a9bf2

Please sign in to comment.