-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
104 changed files
with
1,267 additions
and
832 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,18 +1,77 @@ | ||
import Link from "next/link"; | ||
import { AllHTMLAttributes, ReactEventHandler, useState } from "react"; | ||
|
||
interface BadgeProps | ||
extends Omit<AllHTMLAttributes<HTMLDivElement>, "id" | "name" | "type"> { | ||
name: string; | ||
id: string | number; | ||
avatar: string; | ||
tokens: string | number; | ||
owned?: boolean; | ||
disableLink?: boolean; | ||
disableOwnedHighlight?: boolean; | ||
} | ||
|
||
const Badge: React.FC<BadgeProps> = ({ | ||
name, | ||
id, | ||
avatar, | ||
tokens, | ||
owned, | ||
disableLink = false, | ||
disableOwnedHighlight = false, | ||
...rest | ||
}) => { | ||
const [badgeLoaded, setBadgeLoaded] = useState(false); | ||
const [fallbackRan, setFallbackRan] = useState(false); | ||
|
||
const highlightBadge = owned || !disableOwnedHighlight || !badgeLoaded; | ||
|
||
const imageOnError: ReactEventHandler<HTMLImageElement> = (e) => { | ||
// prevent infinite loop fallback | ||
if (fallbackRan) { | ||
setBadgeLoaded(true); | ||
return; | ||
} | ||
|
||
setBadgeLoaded(false); | ||
e.currentTarget.src = "/images/badges/badge-not-found.svg"; | ||
setFallbackRan(true); | ||
}; | ||
|
||
export default function Badge({ name, id, avatar, tokens, owned }) { | ||
return ( | ||
<Link | ||
href={`/badge/${id}`} | ||
className={`h-full w-full ${owned ? "opacity-100" : "opacity-30"}`} | ||
<div | ||
className={`h-full w-full ${ | ||
highlightBadge ? "opacity-100" : "opacity-30" | ||
}`} | ||
id={id.toString()} | ||
{...rest} | ||
> | ||
<div> | ||
<img src={avatar} alt={name}></img> | ||
</div> | ||
<div className="flex flex-col justify-items-center text-center font-iregular"> | ||
<div>{name}</div> | ||
<div>{tokens} 💰 </div> | ||
</div> | ||
</Link> | ||
<Link href={disableLink ? "" : `/badge/${id}`}> | ||
<div className="flex aspect-square w-full select-none items-center justify-center"> | ||
{!badgeLoaded && <BadgeSkeleton />} | ||
|
||
<img | ||
src={avatar} | ||
alt={name} | ||
onLoad={() => setBadgeLoaded(true)} | ||
onError={imageOnError} | ||
/> | ||
</div> | ||
|
||
<div className="flex flex-col justify-items-center text-center font-iregular"> | ||
<div>{name}</div> | ||
<div>{tokens} 💰 </div> | ||
</div> | ||
</Link> | ||
</div> | ||
); | ||
} | ||
}; | ||
|
||
export default Badge; | ||
|
||
const BadgeSkeleton = () => { | ||
return ( | ||
<div className="aspect-square w-10/12 animate-pulse rounded-full bg-gray-500 opacity-5" /> | ||
); | ||
}; |
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,35 @@ | ||
import { faArrowUp } from "@fortawesome/free-solid-svg-icons"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { useEffect, useState } from "react"; | ||
|
||
export default function GoToTop() { | ||
const [showButton, setShowButton] = useState(false); | ||
|
||
useEffect(() => { | ||
window.addEventListener("scroll", () => { | ||
if (window.scrollY > 400) { | ||
setShowButton(true); | ||
} else { | ||
setShowButton(false); | ||
} | ||
}); | ||
}, []); | ||
|
||
const goToTop = () => { | ||
window.scrollTo({ | ||
top: 0, | ||
behavior: "smooth", | ||
}); | ||
}; | ||
|
||
return ( | ||
<button | ||
className={`transition-translate fixed right-5 bottom-5 h-12 w-12 cursor-pointer rounded-full bg-white duration-300 ${ | ||
showButton ? "" : "translate-y-52" | ||
}`} | ||
onClick={goToTop} | ||
> | ||
<FontAwesomeIcon icon={faArrowUp} className="text-3xl text-black" /> | ||
</button> | ||
); | ||
} |
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
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
Oops, something went wrong.