diff --git a/components/campaigns/AnnouncementHero.tsx b/components/campaigns/AnnouncementHero.tsx index 61ffb47b85e..bee864e495c 100644 --- a/components/campaigns/AnnouncementHero.tsx +++ b/components/campaigns/AnnouncementHero.tsx @@ -1,10 +1,10 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; import ArrowLeft from '../icons/ArrowLeft'; import ArrowRight from '../icons/ArrowRight'; import Container from '../layout/Container'; import Banner from './AnnouncementBanner'; -import { banners } from './banners'; +import { banners, shouldShowBanner } from './banners'; interface IAnnouncementHeroProps { className?: string; @@ -21,15 +21,15 @@ interface IAnnouncementHeroProps { export default function AnnouncementHero({ className = '', small = false }: IAnnouncementHeroProps) { const [activeIndex, setActiveIndex] = useState(0); - const len = banners.length; - const numberOfVisibleBanners = banners.filter((banner) => banner.show).length; + const visibleBanners = useMemo(() => banners.filter((banner) => shouldShowBanner(banner.cfpDeadline)), [banners]); + const numberOfVisibleBanners = visibleBanners.length; const goToPrevious = () => { - setActiveIndex((prevIndex) => (prevIndex === 0 ? len - 1 : prevIndex - 1)); + setActiveIndex((prevIndex) => (prevIndex === 0 ? numberOfVisibleBanners - 1 : prevIndex - 1)); }; const goToNext = () => { - setActiveIndex((prevIndex) => (prevIndex === len - 1 ? 0 : prevIndex + 1)); + setActiveIndex((prevIndex) => (prevIndex === numberOfVisibleBanners - 1 ? 0 : prevIndex + 1)); }; const goToIndex = (index: number) => { @@ -62,31 +62,28 @@ export default function AnnouncementHero({ className = '', small = false }: IAnn )}
- {banners.map( - (banner, index) => - banner.show && ( - - ) - )} + {visibleBanners.map((banner, index) => ( + + ))}
- {banners.map((banner, index) => ( + {visibleBanners.map((banner, index) => (
goToIndex(index)} /> diff --git a/components/campaigns/banners.ts b/components/campaigns/banners.ts index b6472dbf4a2..0620e6bdde9 100644 --- a/components/campaigns/banners.ts +++ b/components/campaigns/banners.ts @@ -3,7 +3,7 @@ * @returns Whether the banner should be shown * @description Check if the current date is after the deadline */ -function shouldShowBanner(cfpDeadline: string) { +export function shouldShowBanner(cfpDeadline: string) { const currentDate = new Date(); // G et the current date const deadline = new Date(cfpDeadline); // Convert the cfpDeadline string to a Date object @@ -15,18 +15,14 @@ function shouldShowBanner(cfpDeadline: string) { return true; } -const cfpDeadlineParis = '2024-10-12T06:00:00Z'; -const showBannerParis = shouldShowBanner(cfpDeadlineParis); - export const banners = [ { - title: "AsyncAPI Conf on Tour'24", - city: 'Paris', - dateLocation: '3rd - 5th of December, 2024 | France, Paris', - cfaText: 'Apply To Speak', - eventName: 'the end of Call for Speakers', - cfpDeadline: cfpDeadlineParis, - link: 'https://conference.asyncapi.com/venue/Paris', - show: showBannerParis + title: "AsyncAPI Online Conference'24", + city: 'YouTube', + dateLocation: '30th of October, 2024 | YouTube & LinkedIn', + cfaText: 'Join us Live', + eventName: 'the AsyncAPI Online Conference', + cfpDeadline: '2024-10-30T06:00:00Z', + link: 'https://www.youtube.com/live/F9wHxd-v2f0?si=kPCqgUzqAKC0FaqJ' } ];