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 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use async hooks and beta api for hot repos (#296)
- Loading branch information
Showing
22 changed files
with
354 additions
and
239 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
VITE_SUPABASE_URL=https://lkkownkrbkmblczeoyqb.supabase.co | ||
VITE_SUPABASE_API_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJvbGUiOiJhbm9uIiwiaWF0IjoxNjQyNDU2MTc0LCJleHAiOjE5NTgwMzIxNzR9.c6nlkT05GnNacQ6OYuGcjBsILmGsSDwEEtN2zZVXFgY | ||
VITE_POSTHOG_ID=phc_DFcN3mLP4ocKAUBKr5xyMbAnPwcl93q41ZmhoLG7GCv | ||
VITE_POSTHOG_ID=phc_DFcN3mLP4ocKAUBKr5xyMbAnPwcl93q41ZmhoLG7GCv | ||
VITE_API_URL=https://beta.api.opensauced.pizza/v1 |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,139 @@ | ||
import { useEffect, useState } from "react"; | ||
import { RiCheckboxCircleFill } from "react-icons/ri"; | ||
import { FaArrowAltCircleUp } from "react-icons/fa"; | ||
import { AiOutlineStar } from "react-icons/ai"; | ||
import { BiGitPullRequest } from "react-icons/bi"; | ||
import { VscIssues } from "react-icons/vsc"; | ||
import Skeleton from "react-loading-skeleton"; | ||
import { getAvatarLink } from "../lib/github"; | ||
import humanizeNumber from "../lib/humanizeNumber"; | ||
import StackedAvatar from "./StackedAvatar"; | ||
import useRepo from "../hooks/useRepo"; | ||
import useVotedRepos from "../hooks/useVotedRepos"; | ||
|
||
export declare interface HotRepoCardProps { | ||
repoName: string; | ||
} | ||
|
||
const HotRepoCard = ({ repoName }: HotRepoCardProps): JSX.Element => { | ||
const { votedReposIds, checkVoted, voteHandler } = useVotedRepos(); | ||
const { repo, isLoading, isError } = useRepo(repoName); | ||
const [isVoted, setIsVoted] = useState(false); | ||
|
||
useEffect(() => { | ||
repo && setIsVoted(checkVoted(repo.id)); | ||
}, [votedReposIds, repo]); | ||
|
||
if (isError) { | ||
return ( | ||
<div className="p-4 border rounded-2xl bg-white w-full space-y-1 relative"> | ||
{`${repoName} failed to load`} | ||
</div> | ||
); | ||
} | ||
|
||
if (isLoading) { | ||
return ( | ||
<div className="p-4 border rounded-2xl bg-white w-full space-y-1 relative"> | ||
<Skeleton | ||
enableAnimation | ||
count={5} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
const { id, full_name, name, description, issues, stars, contributions } = repo!; | ||
const repo_id = parseInt(`${id}`); | ||
const owner = full_name.replace(`/${String(name)}`, "").trim(); | ||
|
||
return ( | ||
<div className="p-4 border rounded-2xl bg-white w-full space-y-1 relative"> | ||
<div className="flex justify-between w-full"> | ||
<div className="flex space-x-1 items-center"> | ||
<img | ||
alt="Hot Repo Icon" | ||
className="h-4 w-4 rounded-md overflow-hidden" | ||
src={getAvatarLink(owner)} | ||
/> | ||
|
||
<span className="text-sm font-medium text-lightSlate11"> | ||
{owner} | ||
</span> | ||
</div> | ||
|
||
<button | ||
className={`px-2 py-0.5 border rounded-lg flex justify-center items-center space-x-1 text-xs transition-all duration-200 ${ | ||
isVoted ? "bg-lightOrange01" : "bg-lightSlate01" | ||
} ${isVoted ? "text-saucyRed border-saucyRed " : "text-lightSlate11 border-lightSlate06 "}`} | ||
onClick={async () => voteHandler(0, repo_id)} | ||
> | ||
<span> | ||
{isVoted ? "voted" : "upvote"} | ||
</span> | ||
|
||
{isVoted | ||
? ( | ||
<RiCheckboxCircleFill className="" />) | ||
: ( | ||
<FaArrowAltCircleUp className="fill-lightSlate09" /> | ||
)} | ||
</button> | ||
</div> | ||
|
||
<div className="flex flex-col pb-10"> | ||
<a | ||
className="text-xl font-semibold" | ||
href={`https://app.opensauced.pizza/repos/${full_name}`} | ||
rel="noopener noreferrer" | ||
target="_blank" | ||
> | ||
{name} | ||
</a> | ||
|
||
<p className="text-gray-500 font-medium text-xs w-5/6"> | ||
{description} | ||
</p> | ||
</div> | ||
|
||
<div className="flex items-center justify-between absolute bottom-3 inset-x-0 px-4"> | ||
<div className="flex space-x-3 text-xs"> | ||
<div className="flex text-sm space-x-1 justify-center items-center"> | ||
<VscIssues | ||
className="fill-lightSlate10" | ||
size={16} | ||
/> | ||
|
||
<span className="text-lightSlate11"> | ||
{humanizeNumber(issues)} | ||
</span> | ||
</div> | ||
|
||
<div className="flex text-sm space-x-1 justify-center items-center"> | ||
<AiOutlineStar | ||
className="fill-lightSlate10" | ||
size={16} | ||
/> | ||
|
||
<span className="text-lightSlate11"> | ||
{humanizeNumber(stars)} | ||
</span> | ||
</div> | ||
|
||
<div className="flex text-sm space-x-1 justify-center items-center"> | ||
<BiGitPullRequest | ||
className="fill-lightSlate10" | ||
size={16} | ||
/> | ||
|
||
<span className="text-lightSlate11">0</span> | ||
</div> | ||
</div> | ||
|
||
<StackedAvatar contributors={contributions} /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default HotRepoCard; |
Oops, something went wrong.