diff --git a/src/pages/Contributors/Contributors.tsx b/src/pages/Contributors/Contributors.tsx index d4fee52c..a801e9a1 100644 --- a/src/pages/Contributors/Contributors.tsx +++ b/src/pages/Contributors/Contributors.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { useEffect, useState, useMemo } from "react"; import { Container, Grid, @@ -10,6 +10,11 @@ import { Box, CircularProgress, Alert, + TextField, + MenuItem, + Select, + FormControl, + InputLabel, } from "@mui/material"; import { FaGithub } from "react-icons/fa"; import { Link } from "react-router-dom"; @@ -22,14 +27,18 @@ interface Contributor { avatar_url: string; contributions: number; html_url: string; + type?: string; } const ContributorsPage = () => { const [contributors, setContributors] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); + const [search, setSearch] = useState(""); + const [sortOrder, setSortOrder] = useState("desc"); + const [minPRs, setMinPRs] = useState(""); + const [prType, setPrType] = useState("all"); - // Fetch contributors from GitHub API useEffect(() => { const fetchContributors = async () => { try { @@ -43,10 +52,32 @@ const ContributorsPage = () => { setLoading(false); } }; - fetchContributors(); }, []); + const handleClearFilters = () => { + setSearch(""); + setSortOrder("desc"); + setMinPRs(""); + setPrType("all"); + }; + + const filtered = useMemo(() => { + return contributors + .filter((c) => { + const matchesSearch = c.login.toLowerCase().includes(search.toLowerCase()); + const matchesMinPR = minPRs === "" || c.contributions >= parseInt(minPRs, 10); + const matchesType = prType === "all" || (c.type && c.type.toLowerCase() === prType.toLowerCase()); + return matchesSearch && matchesMinPR && matchesType; + }) + .sort((a, b) => { + if (sortOrder === "desc") { + return b.contributions - a.contributions; + } + return a.contributions - b.contributions; + }); + }, [contributors, search, sortOrder, minPRs, prType]); + if (loading) { return ( @@ -70,69 +101,115 @@ const ContributorsPage = () => { 🤝 Contributors + + setSearch(e.target.value)} + sx={{ flex: 1, minWidth: 200 }} + /> + setMinPRs(e.target.value)} + sx={{ width: 130 }} + /> + + PR Type + + + + Sort by Contributions + + + + + + + Showing {filtered.length} of {contributors.length} contributors + + - {contributors.map((contributor) => ( + {filtered.map((contributor) => ( - + - - - - - {contributor.login} - - - - {contributor.contributions} Contributions - - {/* - - Thank you for your valuable contributions to our - community! - */} - - - - - - - + + + + {contributor.login} + + + {contributor.contributions} Contributions + + + + + + + ))}