This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display repos' contributors avatars (#383)
closes #333
- Loading branch information
1 parent
2fc96d4
commit ecebb1e
Showing
5 changed files
with
114 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { AiOutlineStar } from "react-icons/ai"; | ||
import { FaRegDotCircle } from "react-icons/fa"; | ||
import useContributions from "../hooks/useContributions"; | ||
import { getAvatarLink } from "../lib/github"; | ||
import humanizeNumber from "../lib/humanizeNumber"; | ||
import StackedAvatar from "./StackedAvatar"; | ||
|
||
export declare interface SearchedRepoCardProps { | ||
data: DbRepo; | ||
} | ||
|
||
const SearchedRepoCard = ({ data: { full_name, name, description, issues, stars } }: SearchedRepoCardProps) => { | ||
const { data: contributions } = useContributions(full_name); | ||
|
||
return ( | ||
<a | ||
href={`https://app.opensauced.pizza/repos/${full_name}`} | ||
rel="noreferrer" | ||
target="_blank" | ||
> | ||
<div className="flex flex-col hover:bg-gray-50 "> | ||
<div className="flex flex-col px-10 md:px-3.5 py-2.5"> | ||
<div className="flex items-center gap-x-2.5 mb-1"> | ||
<div className="w-6 h-6 overflow-hidden border-gray-400 border-px bg-red-100 rounded-full"> | ||
<img | ||
alt={full_name} | ||
className="w-full h-full" | ||
src={getAvatarLink(full_name.replace(`/${String(name)}`, ""))} | ||
/> | ||
</div> | ||
|
||
<p className="text-base text-gray-500 font-semibold"> | ||
{full_name} | ||
</p> | ||
</div> | ||
|
||
<p className="text-sm text-gray-500"> | ||
{description} | ||
</p> | ||
|
||
<div className="flex justify-between mt-2"> | ||
<div className="flex gap-x-1"> | ||
<StackedAvatar contributors={contributions} /> | ||
</div> | ||
|
||
<div className="flex gap-x-1.5"> | ||
<div className="flex items-center gap-x-1"> | ||
<FaRegDotCircle aria-hidden="true" /> | ||
|
||
<p className="text-gray-500 text-xs"> | ||
{humanizeNumber(issues)} | ||
</p> | ||
</div> | ||
|
||
<div className="flex items-center gap-x-1"> | ||
<AiOutlineStar | ||
aria-hidden="true" | ||
className="mr-1" | ||
/> | ||
|
||
<p className="text-gray-500 text-xs"> | ||
{humanizeNumber(stars)} | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</a> | ||
); | ||
}; | ||
|
||
export default SearchedRepoCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import useSWR from "swr"; | ||
|
||
interface PaginatedContributorsResponse { | ||
readonly data: DbContribution[]; | ||
readonly meta: PageMetaDto; | ||
} | ||
|
||
const useContributions = (repoName: string, limit = 10, orderBy = "recent") => { | ||
const baseEndpoint = `repos/${repoName}/contributions`; | ||
const limitQuery = `&limit=${limit}`; | ||
const orderByQuery = orderBy ? `&updated_at=${orderBy}` : ""; | ||
const endpointString = `${baseEndpoint}?${limitQuery}${orderByQuery}`; | ||
|
||
const { data, error, mutate } = useSWR<PaginatedContributorsResponse, Error>(endpointString); | ||
|
||
return { | ||
data: data?.data ?? [], | ||
meta: data?.meta ?? { itemCount: 0 }, | ||
isLoading: !error && !data, | ||
isError: !!error, | ||
mutate, | ||
}; | ||
}; | ||
|
||
export default useContributions; |