From 998c580dfc5536aff6ab3fcceadd2564fcfd8b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1rio=20Guimar=C3=A3es?= <49988070+Darguima@users.noreply.github.com> Date: Mon, 29 Jan 2024 10:06:11 +0000 Subject: [PATCH] fix: Badgedex (#645) * badge mage fake preview fix * staff badge margin fix * fix badges owning * fix margins in top bar * preventing component to update after search * fixing highlight --- components/Badge/index.tsx | 32 ++++++++++----------- layout/Attendee/Badgedex/Badgedex.tsx | 1 + layout/Staff/Badges/Badges.tsx | 40 +++++++++++++-------------- 3 files changed, 35 insertions(+), 38 deletions(-) diff --git a/components/Badge/index.tsx b/components/Badge/index.tsx index 0b8c03bb..c83a81e5 100644 --- a/components/Badge/index.tsx +++ b/components/Badge/index.tsx @@ -1,5 +1,5 @@ import Link from "next/link"; -import { AllHTMLAttributes, ReactEventHandler, useState } from "react"; +import { AllHTMLAttributes, memo, useState } from "react"; interface BadgeProps extends Omit, "id" | "name" | "type"> { @@ -7,7 +7,7 @@ interface BadgeProps id: string | number; avatar: string; tokens: string | number; - owned?: boolean; + owned: boolean; disableLink?: boolean; disableOwnedHighlight?: boolean; } @@ -23,21 +23,9 @@ const Badge: React.FC = ({ ...rest }) => { const [badgeLoaded, setBadgeLoaded] = useState(false); - const [fallbackRan, setFallbackRan] = useState(false); + const [badge404, setBadge404] = useState(false); - const highlightBadge = owned || !disableOwnedHighlight || !badgeLoaded; - - const imageOnError: ReactEventHandler = (e) => { - // prevent infinite loop fallback - if (fallbackRan) { - setBadgeLoaded(true); - return; - } - - setBadgeLoaded(false); - e.currentTarget.src = "/images/badges/badge-not-found.svg"; - setFallbackRan(true); - }; + const highlightBadge = owned || disableOwnedHighlight || !badgeLoaded; return (
= ({
{!badgeLoaded && } + {badge404 && + {name} + } + {name} setBadgeLoaded(true)} - onError={imageOnError} + onError={() => { setBadge404(true); setBadgeLoaded(true); }} + hidden={!badgeLoaded || badge404} />
@@ -68,7 +64,7 @@ const Badge: React.FC = ({ ); }; -export default Badge; +export default memo(Badge); const BadgeSkeleton = () => { return ( diff --git a/layout/Attendee/Badgedex/Badgedex.tsx b/layout/Attendee/Badgedex/Badgedex.tsx index 73d2b48a..1106bae7 100644 --- a/layout/Attendee/Badgedex/Badgedex.tsx +++ b/layout/Attendee/Badgedex/Badgedex.tsx @@ -71,6 +71,7 @@ function Badgedex() {
+
{currentBadges.map((badge) => ( ) : ( <> -
-
-

- Filter by -

- +
+
+

Filter by

-
- { - setSearchInput(e.target.value); - }} - name="search" - id="search" - className="mt-1 w-full rounded-full border-2 border-pink-500 py-2 pl-3 pr-10 text-sm text-black focus:border-pink-500" - /> +
+
+ { + setSearchInput(e.target.value); + }} + name="search" + id="search" + className="mt-1 w-full rounded-full border-2 border-quinary py-2 pl-3 pr-10 text-sm text-black outline-none focus:border-quinary/50" + /> +
-
+ +
{allBadges .filter((badge) => badge.type == filter || filter == null) .filter( @@ -123,7 +123,7 @@ function Badges() { name={badge.name} avatar={badge.avatar} tokens={badge.tokens} - owned={badge.owned} + owned={true} disableLink={true} disableOwnedHighlight={true} onClick={() => handleBadgeSelected(badge)}