[deploy] Rewrite GithubRepos with async/await for better debugging (#8363)

This commit is contained in:
rhymes 2020-06-09 15:09:08 +02:00 committed by GitHub
parent 9e3b6a090b
commit f49decf306
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,5 @@
import { h, Component } from 'preact';
import { request } from '@utilities/http';
import { SingleRepo } from './singleRepo';
export class GithubRepos extends Component {
@ -11,34 +12,24 @@ export class GithubRepos extends Component {
this.getGithubRepos();
}
getGithubRepos = () => {
fetch(`/github_repos`, {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
credentials: 'same-origin',
})
.then((response) => response.json())
.then((json) => {
this.setState({ repos: json });
})
.catch(() => {
this.setState({ erroredOut: true });
});
};
async getGithubRepos() {
try {
const response = await request('/github_repos');
const repositories = await response.json();
this.setState({ repos: repositories });
} catch (error) {
this.setState({ erroredOut: true });
Honeybadger.notify(error);
// will remove this, need it temporarily to properly debug
console.error(error); // eslint-disable-line no-console
}
}
render() {
const { repos, erroredOut } = this.state;
const allRepos = repos.map((repo) => (
<SingleRepo
githubIdCode={repo.github_id_code}
name={repo.name}
fork={repo.fork}
featured={repo.featured}
/>
));
if (erroredOut) {
return (
<div className="github-repos github-repos-errored">
@ -48,6 +39,16 @@ export class GithubRepos extends Component {
</div>
);
}
const allRepos = repos.map((repo) => (
<SingleRepo
githubIdCode={repo.github_id_code}
name={repo.name}
fork={repo.fork}
featured={repo.featured}
/>
));
if (repos.length > 0) {
return <div className="github-repos">{allRepos}</div>;
}