* Rename find_or_create to upsert and improve validation and testing * Add User.authenticated_through? * Refactor settings/integrations * Refactor profile github repositories rendering * Refactor repos fetching * Only fetch a single repo and improve error messages * Remove unused code * Cleanups * Fix specs * Remove trailing whitespace * Fix spec * Trigger Travis
58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
import { h, Component } from 'preact';
|
|
import { SingleRepo } from './singleRepo';
|
|
|
|
export class GithubRepos extends Component {
|
|
state = {
|
|
repos: [],
|
|
erroredOut: false,
|
|
};
|
|
|
|
componentDidMount() {
|
|
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 });
|
|
});
|
|
};
|
|
|
|
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">
|
|
An error occurred. Please check your browser console and email
|
|
<a href="mailto:yo@dev.to"> yo@dev.to </a>
|
|
for more help.
|
|
</div>
|
|
);
|
|
}
|
|
if (repos.length > 0) {
|
|
return <div className="github-repos">{allRepos}</div>;
|
|
}
|
|
return <div className="github-repos loading-repos" />;
|
|
}
|
|
}
|
|
|
|
GithubRepos.displayName = 'GitHub Repositories Wrapper';
|