Skip to content

Commit 233778f

Browse files
committed
refactor: use Slider component for sliders
1 parent 74146ab commit 233778f

File tree

1 file changed

+66
-5
lines changed

1 file changed

+66
-5
lines changed

src/pages/index.tsx

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ import type {
1414
} from "@/lib/types"
1515

1616
import BentoBox from "@/components/BentoBox"
17+
import BentoCard from "@/components/BentoBox/BentoCard"
18+
import Title from "@/components/BentoBox/Title"
1719
import SvgButtonLink from "@/components/Buttons/SvgButtonLink"
1820
import CodeModal from "@/components/CodeModal"
1921
import HomeHero from "@/components/Hero/HomeHero"
20-
import { useHome } from "@/components/Homepage/useHome"
2122
import AngleBrackets from "@/components/icons/angle-brackets.svg"
2223
import Calendar from "@/components/icons/calendar.svg"
2324
import CalendarAdd from "@/components/icons/calendar-add.svg"
2425
import { TwImage } from "@/components/Image"
2526
import MainArticle from "@/components/MainArticle"
2627
import PageMetadata from "@/components/PageMetadata"
27-
import PostsSwiper from "@/components/PostsSwiper"
28-
import SwiperCards from "@/components/SwiperCards"
28+
import Swiper from "@/components/Swiper"
2929
import { TranslatathonBanner } from "@/components/Translatathon/TranslatathonBanner"
3030
import { ButtonLink } from "@/components/ui/buttons/Button"
3131
import {
@@ -52,6 +52,7 @@ import { existsNamespace } from "@/lib/utils/existsNamespace"
5252
import { getLastDeployDate } from "@/lib/utils/getLastDeployDate"
5353
import { polishRSSList } from "@/lib/utils/rss"
5454
import { runOnlyOnce } from "@/lib/utils/runOnlyOnce"
55+
import { breakpointAsNumber } from "@/lib/utils/screen"
5556
import { getLocaleTimestamp } from "@/lib/utils/time"
5657
import { getRequiredNamespacesForPage } from "@/lib/utils/translations"
5758

@@ -64,6 +65,9 @@ import {
6465
RSS_DISPLAY_COUNT,
6566
} from "@/lib/constants"
6667

68+
import "swiper/css/effect-cards"
69+
70+
import { useHome } from "@/hooks/useHome"
6771
import { fetchCommunityEvents } from "@/lib/api/calendarEvents"
6872
import { fetchEthPrice } from "@/lib/api/fetchEthPrice"
6973
import { fetchGrowThePie } from "@/lib/api/fetchGrowThePie"
@@ -178,6 +182,7 @@ const HomePage = ({
178182
popularTopics,
179183
upcomingEvents,
180184
joinActions,
185+
bentoItems,
181186
} = useHome()
182187

183188
return (
@@ -221,7 +226,26 @@ const HomePage = ({
221226
</div>
222227

223228
{/* Mobile */}
224-
<SwiperCards className="lg:hidden" />
229+
<div className="-mx-4 w-[100vw] overflow-hidden px-4 sm:-mx-6 sm:px-6 lg:hidden">
230+
<Title />
231+
<Swiper
232+
options={{ effect: "cards", createElements: true }}
233+
className={cn(
234+
"[&_.swiper-slide]:overflow-visible [&_.swiper-slide]:rounded-2xl [&_.swiper-slide]:shadow-card-hover",
235+
"[&_.swiper]:mx-auto [&_.swiper]:mt-4 [&_.swiper]:!flex [&_.swiper]:h-fit [&_.swiper]:max-w-128 [&_.swiper]:flex-col [&_.swiper]:items-center"
236+
)}
237+
>
238+
{bentoItems.map((item) => (
239+
<BentoCard
240+
key={item.title}
241+
imgHeight={220}
242+
{...item}
243+
className={cn(item.className, "bg-background text-body")}
244+
imgWidth={undefined} // Intentionally last to override box
245+
/>
246+
))}
247+
</Swiper>
248+
</div>
225249

226250
{/* Desktop */}
227251
<BentoBox className="hidden lg:block" />
@@ -452,7 +476,44 @@ const HomePage = ({
452476
</h3>
453477
<p>{t("page-index:page-index-posts-subtitle")}</p>
454478

455-
<PostsSwiper items={rssItems} className="mt-4 md:mt-16" />
479+
<Swiper
480+
className="mt-4 md:mt-16"
481+
options={{
482+
spaceBetween: 32,
483+
breakpoints: {
484+
[breakpointAsNumber.sm]: {
485+
slidesPerView: 2,
486+
slidesPerGroup: 2,
487+
},
488+
[breakpointAsNumber.lg]: {
489+
slidesPerView: 3,
490+
slidesPerGroup: 3,
491+
},
492+
},
493+
}}
494+
>
495+
{rssItems.map(({ pubDate, title, source, link, imgSrc }) => (
496+
<Card key={title} href={link}>
497+
<CardBanner>
498+
{/* eslint-disable-next-line @next/next/no-img-element */}
499+
<img src={imgSrc} alt="" />
500+
</CardBanner>
501+
<CardContent>
502+
<CardTitle>{title}</CardTitle>
503+
{isValidDate(pubDate) && (
504+
<CardSubTitle>
505+
{new Intl.DateTimeFormat(locale, {
506+
month: "long",
507+
day: "numeric",
508+
year: "numeric",
509+
}).format(new Date(pubDate))}
510+
</CardSubTitle>
511+
)}
512+
<CardHighlight>{source}</CardHighlight>
513+
</CardContent>
514+
</Card>
515+
))}
516+
</Swiper>
456517

457518
<div className="mt-8 flex flex-col gap-4 rounded-2xl border p-8">
458519
<p className="text-lg">{t("page-index:page-index-posts-action")}</p>

0 commit comments

Comments
 (0)