Skip to content

Commit

Permalink
Add GitHub Component Kit
Browse files Browse the repository at this point in the history
closes #90
  • Loading branch information
samad-yar-khan committed Mar 26, 2022
1 parent 2a31cab commit 0930180
Show file tree
Hide file tree
Showing 33 changed files with 1,252 additions and 222 deletions.
5 changes: 4 additions & 1 deletion app/components/github/contributorslist.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Image from 'next/image';

const ContributorsList = ({ contributors }) => {
const ContributorsList = (props) => {

let contributors = props.data.contributors.Contributors;

return (
<div className="container">
{Array.isArray(contributors) &&
Expand Down
46 changes: 0 additions & 46 deletions app/components/github/githubissue.js

This file was deleted.

59 changes: 44 additions & 15 deletions app/components/github/githubissueslist.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,54 @@
import { useEffect, useState } from 'react';
import { Col, NavLink, Row } from 'react-bootstrap';
import LikeIcon from '../../public/svg/like';
import CommentIcon from '../../public/svg/comment';
import IssueIcon from '../../public/svg/issue';
import styles from '../../styles/GithubIssuesList.module.css';
import GithubIssue from './githubissue';

const GithubIssuesList = ({ issues, noOfIssues = 6 }) => {
const [data, setData] = useState([]);

useEffect(() => {
if (Array.isArray(issues)) {
setData(issues.splice(0, noOfIssues));
} else {
setData(issues);
}
}, [issues]);
const GithubIssue = ({ issue }) => {
return (
<Col className={`${styles.column} py-2 px-3 m-2 rounded`}>
<Row className={`${styles.item_container}`}>
<NavLink href={issue.html_url}>{issue.title}</NavLink>
</Row>
<Row className="d-flex align-items-center">
<Col xs="auto" className={`${styles.numbers}`}>
<span className="me-2">
<IssueIcon />
</span>
{issue.state}
</Col>
<Col xs="auto" className={`${styles.numbers}`}>#{issue.number}</Col>
<Col xs="auto" className={`me-3 ${styles.numbers}`}>
<span className="me-2">
<LikeIcon />
</span>
{issue.reactions['+1']}
</Col>
<Col xs="auto" className={`me-2 ${styles.numbers}`}>
<span className="me-2">
<CommentIcon />
</span>
{issue.comments}
</Col>
</Row>
</Col>
);
};

const GithubIssuesList = (props) => {
const data =
props.data.issues.Issues.length > 10
? props.data.issues.Issues.slice(0, 10)
: props.data.issues.Issues;
return (
<div
className={`${styles.container} d-flex flex-wrap justify-content-center`}
>
{Array.isArray(data) ? data.map((issue) => (
<GithubIssue key={issue.id} issue={issue} />
)): <p className='text-danger'>{issues}, ERROR :( </p>}
{Array.isArray(data) ? (
data.map((issue) => <GithubIssue key={issue.id} issue={issue} />)
) : (
<p className="text-danger"> ERROR </p>
)}
</div>
);
};
Expand Down
62 changes: 62 additions & 0 deletions app/components/github/githubpullreqeusts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Col, NavLink, Row } from "react-bootstrap";
import styles from "../../styles/GithubPullRequest.module.css";
import Image from "next/image";
import PullsIcon from '../../public/svg/pull';

const GithubPullReqeust = ({ pull }) => {
return (
<Col className={`${styles.column} py-2 px-3 m-2 rounded`}>
<Row className="d-flex align-items-center">
<Col xs="auto" className={`${styles.numbers}`}>
<a href={pull.user.html_url}>
<Image
className="rounded-circle"
src={pull.user.avatar_url}
width={40}
height={40}
/>
</a>
</Col>
<Col xs="auto" className={`${styles.username}`}>
<a href={pull.user.html_url}>
<span>{pull.user.login}</span>
</a>
</Col>
</Row>
<Row className={`${styles.item_container}`}>
<NavLink href={pull.html_url}>{pull.title}</NavLink>
</Row>
<Row className="d-flex align-items-center">
<Col xs="auto" className={`${styles.numbers}`}>
<span className="me-2">
<PullsIcon />
</span>
{pull.state}
</Col>
<Col xs="auto" className={`${styles.numbers}`}>
#{pull.number}
</Col>
</Row>
</Col>
);
};
const GithubPullRequestsList = (props) => {
const data =
props.data.pulls.pulls.length > 6
? props.data.pulls.pulls.slice(0, 6)
: props.data.pulls.pulls;

return (
<div
className={`${styles.container} d-flex flex-wrap justify-content-center`}
>
{Array.isArray(data) ? (
data.map((pull) => <GithubPullReqeust key={pull.id} pull={pull} />)
) : (
<p className="text-danger"> ERROR </p>
)}
</div>
);
};

export default GithubPullRequestsList;
61 changes: 61 additions & 0 deletions app/components/github/githubrepo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Col, NavLink, Row , Badge } from 'react-bootstrap';
import IssueIcon from '../../public/svg/issue';
import StarIcon from '../../public/svg/star';
import ForkIcon from '../../public/svg/forks';
import styles from '../../styles/GithubRepo.module.css';

const GithubRepo = ({data}) => {
return (

<div
className={`${styles.container} d-flex flex-wrap justify-content-center`}
>
<Col className={`${styles.column} py-2 px-3 m-2 rounded`}>
<Row className={`${styles.item_container}`}>
<NavLink href={data.html_url}>{data.full_name}</NavLink>
</Row>
<Row className="d-flex align-items-center">
<Col xs="auto" className={`${styles.numbers}`}>
<span className="me-2">
<IssueIcon />
</span>
{data.open_issues_count}
</Col>
<Col xs="auto" className={`me-1 ${styles.numbers}`}>
<span className="me-2">
<StarIcon />
</span>
{data.stargazers_count}
</Col>
<Col xs="auto" className={`me-2 ${styles.numbers}`}>
<span className="me-2">
<ForkIcon />
</span>
{data.forks_count}
</Col>
</Row>
{
(Array.isArray(data.topics) && (data.topics.length > 0 )) &&
(
<Row className={`${styles.md_container} p-1 d-flex align-items-center justify-content-start`}>
{data.topics.map((topic) => {
return (<Col xs="auto" className={`m-0 px-1`}>
<Badge pill bg="light" text="dark">
{topic}
</Badge>
</Col>)
})}
</Row>
)
}
<Row className={`${styles.md_container} p-1`}>
<span>
{data.description}
</span>
</Row>
</Col>
</div>
);
};

export default GithubRepo;
20 changes: 17 additions & 3 deletions app/components/github/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
export { default as ContributorsList } from './contributorslist'
export { default as GithubIssue } from './githubissue'
export { default as GithubIssuesList } from './githubissueslist'
import GithubIssuesList from "./githubissueslist";
import ContributorsList from "./contributorslist";
import GithubPullRequestsList from "./githubpullreqeusts";
import GithubRepo from "./githubrepo";

const Github = (props) => {
if(props.type === 'issues'){
return (<GithubIssuesList data={props.githubData}/>);
}else if(props.type === 'pulls'){
return(<GithubPullRequestsList data={props.githubData}/>)
}else if(props.type === 'contributors'){
return (<ContributorsList data={props.githubData}/>);
}
return (<GithubRepo data={props.githubData.repositoryData}/>);
};

export default Github;
12 changes: 0 additions & 12 deletions app/components/mdpreview.js

This file was deleted.

52 changes: 23 additions & 29 deletions app/lib/github.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
import { fetchAPI } from './api';
import { fetchAPI } from "./api";

export const getIssues = async (owner, repo) => {
let issues = [
{
id: 1,
title:
'An error occurred, you can still visit our issues clicking this link',
html_url: `https://github.com/${owner}/${repo}/issues`,
reactions: { '+1': 0 },
comments: 0,
body: '',
state: 'open',
number: 1,
},
];
const res = await fetchAPI('/ghissues');
console.log(res);
if (Array.isArray(res) && Array.isArray(res[0].Issues)) {
issues = res[0].Issues;
export const githubKitData = async (owner, name, needed) => {
try {
const res = await fetchAPI("/github-repositories");
let neededRepository = new Object();
res.forEach((repo) => {
if (repo.owner === owner && repo.name === name) {
neededRepository["id"] = repo.id;
neededRepository["name"] = repo.name;
neededRepository["owner"] = repo.owner;
neededRepository["repositoryData"] = repo.repositoryData;
if(Array.isArray(needed)){
needed.forEach((neededData) => {
neededRepository[neededData] = repo[neededData];
});
}else if(typeof myVariable !== 'undefined'){
neededRepository[needed] = repo[needed];
}
}
});
return neededRepository;
} catch (error) {
console.log(error);
}
return issues;
};

export const getContributors = async () => {
let contributors = [];
const res = await fetchAPI('/ghcontributors');
if (Array.isArray(res) && Array.isArray(res[0].Contributors)) {
contributors = res[0].Contributors;
}
return contributors;
};
Loading

0 comments on commit 0930180

Please sign in to comment.