diff --git a/client/src/component/Contributors.jsx b/client/src/component/Contributors.jsx index f321f90..064fafa 100644 --- a/client/src/component/Contributors.jsx +++ b/client/src/component/Contributors.jsx @@ -94,16 +94,111 @@ ContributorCard.propTypes = { type: PropTypes.string.isRequired, }; -const StatCard = ({ label, value, icon, mode }) => ( + +const IssueCard = ({ + title, + number, + html_url, + user, + state, + mode, +}) => ( + + + + + + {title} + + + Status: {state} + + + + Issue : #{number} + + + + + + + + + + View Issue + + + + + + + +); + +IssueCard.propTypes = { + title: PropTypes.string.isRequired, + number: PropTypes.number.isRequired, + html_url: PropTypes.string.isRequired, // Add validation for html_url + user: PropTypes.shape({ + login: PropTypes.string.isRequired, + avatar_url: PropTypes.string.isRequired, + }).isRequired, + state: PropTypes.string.isRequired, + mode: PropTypes.string.isRequired, +}; + +const StatCard = ({ label, value, icon, mode, onClick }) => ( { const fetchData = async () => { try { - const contributorsResponse = await fetch( - "https://api.github.com/repos/Bitbox-Connect/Bitbox/contributors?page=1&per_page=100" - ); + // Fetch contributors + const contributorsResponse = await fetch("https://api.github.com/repos/Bitbox-Connect/Bitbox/contributors?page=1&per_page=100"); + if (!contributorsResponse.ok) { throw new Error("Failed to fetch contributors data"); } const contributorsData = await contributorsResponse.json(); setContributors(contributorsData); - const repoResponse = await fetch( - "https://api.github.com/repos/Bitbox-Connect/Bitbox" - ); + + // Fetch repo stats + const repoResponse = await fetch('https://api.github.com/repos/Bitbox-Connect/Bitbox'); + const repoData = await repoResponse.json(); setRepoStats({ stars: repoData.stargazers_count, forks: repoData.forks_count, openIssues: repoData.open_issues_count, }); + + // Fetch issues + const issueResponse = await fetch('https://api.github.com/repos/Bitbox-Connect/Bitbox/issues'); + const issueData = await issueResponse.json(); + setOpenIssues(issueData); } catch (error) { console.error("Error fetching data:", error); } finally { @@ -177,6 +285,19 @@ export default function Contributor(props) { fetchData(); }, []); + // Calculate pagination indices + const indexOfLastItem = currentPage * itemsPerPage; + const indexOfFirstItem = indexOfLastItem - itemsPerPage; + + // Get current items based on selected section + const currentItems = showIssue ? openIssues.slice(indexOfFirstItem, indexOfLastItem) : contributors.slice(indexOfFirstItem, indexOfLastItem); + + // Determine total pages + const totalPages = showIssue ? Math.ceil(openIssues.length / itemsPerPage) : Math.ceil(contributors.length / itemsPerPage); + + const paginate = (pageNumber) => setCurrentPage(pageNumber); + + return ( } + onClick={() => { + setShowIssue(false); + setCurrentPage(1); // Reset pagination when switching to contributors + }} /> } + onClick={() => { + setShowIssue(true); + setCurrentPage(1); // Reset pagination when switching to contributors + }} /> - - - Meet Our Contributors - - {loading ? ( - - {props.mode === "dark" ? "Loading..." : "Loading..."} - - ) : ( - - {contributors.map((contributor, index) => ( + + + {showIssue ? 'Your contribution is valuable see all Issues' : 'Contributors'} + + {currentItems.map(item => showIssue ? ( + + ) : ( ))} - )} + + {Array.from({ length: totalPages }, (_, i) => ( + paginate(i + 1)} + className={`px-4 py-2 mx-1 rounded text-black ${i + 1 === currentPage ? 'bg-blue-500 text-white' : 'bg-gray-200 text-gray-900'}`} + > + {i + 1} + + ))} + + - + + + ); }
+ Status: {state} +
- {props.mode === "dark" ? "Loading..." : "Loading..."} -