From 9fe85e1134f706b25cb3e320039e97b130a188be Mon Sep 17 00:00:00 2001 From: brenopolanski Date: Fri, 9 Jun 2023 09:57:31 -0300 Subject: [PATCH] refactor(ad-banner): remove controls and transitions from AdBanner component --- .gitignore | 3 ++ components/AdBanner/index.js | 78 ++++++++---------------------------- pages/index.js | 8 ++-- yarn.lock | 6 +-- 4 files changed, 27 insertions(+), 68 deletions(-) diff --git a/.gitignore b/.gitignore index cb33574d61..4e25d86efc 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,6 @@ yarn-error.log* # vercel .vercel + +# others +build.log diff --git a/components/AdBanner/index.js b/components/AdBanner/index.js index 8f9ed84525..17530f9686 100755 --- a/components/AdBanner/index.js +++ b/components/AdBanner/index.js @@ -9,65 +9,41 @@ const BANNERS = [ image: "brave.png", name: "Brave", url: "https://brave.com/wallet/?mtm_campaign=q2&mtm_kwd=chainlist", + isActive: true, }, { image: "llamanodes.png", name: "LlamaNodes", url: "https://llamanodes.com", + isActive: true, + }, + { + image: "gmx.png", + name: "GMX", + url: "https://app.gmx.io/#/trade/?ref=chainlist", + isActive: false, }, - // { - // image: "gmx.png", - // name: "GMX", - // url: "https://app.gmx.io/#/trade/?ref=chainlist", - // }, ]; -const randomBanners = shuffleArray(BANNERS); +const randomBanners = shuffleArray(BANNERS.filter((banner) => banner.isActive)); +const currentIndex = 0 -export const AdBanner = ({ timer = 15000, startTransition = true, showControls = false }) => { +export const AdBanner = () => { const t = useTranslations("Common"); const [isMounted, setIsMounted] = useState(false); - const [currentIndex, setCurrentIndex] = useState(0); - // only render the image client-side to prevent hydration errors due to the random banners useEffect(() => { setIsMounted(true); }, []); - useEffect(() => { - const intervalId = setInterval(() => { - if (startTransition) { - return handleNextBanner(); - } - - return; - }, timer); - - return () => clearInterval(intervalId); - }, [currentIndex]); - - const handlePrevBanner = () => { - const isFirstBanner = currentIndex === 0; - const newIndex = isFirstBanner ? randomBanners.length - 1 : currentIndex - 1; - - setCurrentIndex(newIndex); - }; - - const handleNextBanner = () => { - const isLastBanner = currentIndex === randomBanners.length - 1; - const newIndex = isLastBanner ? 0 : currentIndex + 1; - - setCurrentIndex(newIndex); - }; - const srcLarge = `./banners/large/${randomBanners[currentIndex].image}`; const srcSmall = `./banners/small/${randomBanners[currentIndex].image}`; const srcName = randomBanners[currentIndex].name; return (
-
+
@@ -104,26 +80,6 @@ export const AdBanner = ({ timer = 15000, startTransition = true, showControls = {isMounted && {srcName}} - - {/* left arrow */} - {showControls && ( -
- ‹ -
- )} - - {/* right arrow */} - {showControls && ( -
- › -
- )}
diff --git a/pages/index.js b/pages/index.js index f9365d875b..b739c9c60c 100755 --- a/pages/index.js +++ b/pages/index.js @@ -69,10 +69,10 @@ function Home({ chains }) { {filteredChains.map((chain, idx) => { if (idx === 2) { return ( - <> - - - + + + + ) } diff --git a/yarn.lock b/yarn.lock index 8512ebda1f..413497f6c3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -752,9 +752,9 @@ camelcase@^7.0.0: integrity sha512-xlx1yCK2Oc1APsPXDL2LdlNP6+uu8OCDdhOBSVT279M/S+y75O30C2VuD8T2ogdePBBl7PfPF4504tnLgX3zfw== caniuse-lite@^1.0.30001400, caniuse-lite@^1.0.30001406, caniuse-lite@^1.0.30001426: - version "1.0.30001436" - resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001436.tgz" - integrity sha512-ZmWkKsnC2ifEPoWUvSAIGyOYwT+keAaaWPHiQ9DfMqS1t6tfuyFYoWR78TeZtznkEQ64+vGXH9cZrElwR2Mrxg== + version "1.0.30001497" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001497.tgz" + integrity sha512-I4/duVK4wL6rAK/aKZl3HXB4g+lIZvaT4VLAn2rCgJ38jVLb0lv2Xug6QuqmxXFVRJMF74SPPWPJ/1Sdm3vCzw== chalk-template@0.4.0: version "0.4.0"