diff --git a/client/src/component/Contributors.jsx b/client/src/component/Contributors.jsx index 84ffb66..6f5a62b 100644 --- a/client/src/component/Contributors.jsx +++ b/client/src/component/Contributors.jsx @@ -223,20 +223,21 @@ StatCard.propTypes = { onClick: PropTypes.func, }; + export default function Contributor(props) { const [contributors, setContributors] = useState([]); const [openIssues, setOpenIssues] = useState([]); const [showIssue, setShowIssue] = useState(true); // Determine which section to show const [loading, setLoading] = useState(true); const [currentPage, setCurrentPage] = useState(1); - const itemsPerPage = 9; // Set the number of items per page (for both contributors and issues) - const [repoStats, setRepoStats] = useState({ stars: 0, forks: 0, openIssues: 0, }); + const [searchTerm, setSearchTerm] = useState(''); // State for search term + const itemsPerPage = 9; // Set the number of items per page (for both contributors and issues) useEffect(() => { const fetchData = async () => { @@ -250,10 +251,8 @@ export default function Contributor(props) { const contributorsData = await contributorsResponse.json(); setContributors(contributorsData); - // 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, @@ -279,15 +278,27 @@ export default function Contributor(props) { 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); + // Filter contributors or issues based on search term + const filteredContributors = contributors.filter(contributor => + contributor.login.toLowerCase().includes(searchTerm.toLowerCase()) + ); + + const filteredIssues = openIssues.filter(issue => + issue.title.toLowerCase().includes(searchTerm.toLowerCase()) + ); + + // Get current items based on selected section and search + const currentItems = showIssue + ? filteredIssues.slice(indexOfFirstItem, indexOfLastItem) + : filteredContributors.slice(indexOfFirstItem, indexOfLastItem); // Determine total pages - const totalPages = showIssue ? Math.ceil(openIssues.length / itemsPerPage) : Math.ceil(contributors.length / itemsPerPage); + const totalPages = showIssue + ? Math.ceil(filteredIssues.length / itemsPerPage) + : Math.ceil(filteredContributors.length / itemsPerPage); const paginate = (pageNumber) => setCurrentPage(pageNumber); - return (
- {/* Repository Stars */} + {/* Repository Stats */}