Skip to content

Commit 1a54803

Browse files
authored
Merge pull request #15553 from ethereum/homepage-ssr
refactor: homepage to SSR
2 parents 03180a1 + 96486a2 commit 1a54803

File tree

101 files changed

+1579
-1364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1579
-1364
lines changed

app/[locale]/10years/_components/CountDown.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22

33
import { useEffect, useState } from "react"
44

5-
import { cn } from "@/lib/utils/cn"
5+
import type { TimeLeftLabels } from "@/lib/types"
66

7-
import { useTranslation } from "@/hooks/useTranslation"
7+
import { cn } from "@/lib/utils/cn"
88

99
interface CountDownProps {
1010
className?: string
11+
timeLeftLabels: TimeLeftLabels
12+
expiredLabel: string
1113
}
1214

13-
const CountDown = ({ className }: CountDownProps) => {
14-
const { t } = useTranslation("page-10-year-anniversary")
15+
const CountDown = ({
16+
className,
17+
timeLeftLabels,
18+
expiredLabel,
19+
}: CountDownProps) => {
1520
const [timeLeft, setTimeLeft] = useState({
1621
days: 0,
1722
hours: 0,
@@ -49,11 +54,7 @@ const CountDown = ({ className }: CountDownProps) => {
4954
}, [])
5055

5156
if (isExpired) {
52-
return (
53-
<div className="text-center text-2xl font-bold">
54-
{t("page-10-year-countdown-expired")}
55-
</div>
56-
)
57+
return <div className="text-center text-2xl font-bold">{expiredLabel}</div>
5758
}
5859

5960
return (
@@ -68,7 +69,9 @@ const CountDown = ({ className }: CountDownProps) => {
6869
{timeLeft.days}
6970
</div>
7071
<div className="font-mono text-xs text-accent-a">
71-
{t("page-10-year-countdown-days")}
72+
{timeLeft.days === 1
73+
? timeLeftLabels.days.singular
74+
: timeLeftLabels.days.plural}
7275
</div>
7376
</div>
7477
<div
@@ -81,7 +84,9 @@ const CountDown = ({ className }: CountDownProps) => {
8184
{timeLeft.hours}
8285
</div>
8386
<div className="font-mono text-xs text-accent-a">
84-
{t("page-10-year-countdown-hours")}
87+
{timeLeft.hours === 1
88+
? timeLeftLabels.hours.singular
89+
: timeLeftLabels.hours.plural}
8590
</div>
8691
</div>
8792
<div
@@ -94,7 +99,9 @@ const CountDown = ({ className }: CountDownProps) => {
9499
{timeLeft.minutes}
95100
</div>
96101
<div className="font-mono text-xs text-accent-a">
97-
{t("page-10-year-countdown-minutes")}
102+
{timeLeft.minutes === 1
103+
? timeLeftLabels.minutes.singular
104+
: timeLeftLabels.minutes.plural}
98105
</div>
99106
</div>
100107
<div
@@ -107,7 +114,9 @@ const CountDown = ({ className }: CountDownProps) => {
107114
{timeLeft.seconds}
108115
</div>
109116
<div className="font-mono text-xs text-accent-a">
110-
{t("page-10-year-countdown-seconds")}
117+
{timeLeft.seconds === 1
118+
? timeLeftLabels.seconds.singular
119+
: timeLeftLabels.seconds.plural}
111120
</div>
112121
</div>
113122
</div>

app/[locale]/10years/_components/TenYearHomeBanner.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
"use client"
1+
import { getTranslations } from "next-intl/server"
22

33
import ParallaxImage from "@/components/Image/ParallaxImage"
44
import { ButtonLink } from "@/components/ui/buttons/Button"
55

66
import Countdown from "./CountDown"
7+
import { getTimeUnitTranslations } from "./utils"
78

8-
import { useTranslation } from "@/hooks/useTranslation"
99
import TenYearGraphicImage from "@/public/images/10-year-anniversary/10-year-logo.png"
1010
import TenYearDesktopText from "@/public/images/10-year-anniversary/10yeartext.svg"
1111
import TenYearMobileText from "@/public/images/10-year-anniversary/10yeartext-mobile.svg"
1212

13-
const TenYearHomeBanner = () => {
14-
const { t } = useTranslation("page-10-year-anniversary")
13+
const TenYearHomeBanner = async ({ locale }: { locale: string }) => {
14+
const t = await getTranslations({
15+
locale,
16+
namespace: "page-10-year-anniversary",
17+
})
18+
19+
const timeLeftLabels = await getTimeUnitTranslations(locale)
1520

1621
return (
1722
<div className="relative rounded-2xl bg-[url('/images/10-year-anniversary/10-year-background.png')] bg-cover bg-center text-center">
@@ -23,6 +28,7 @@ const TenYearHomeBanner = () => {
2328
className="mx-auto -mb-2 -mt-16 max-w-[min(100%,500px)] object-contain sm:-mt-24 md:-mt-32"
2429
/>
2530
<div className="mt-4 flex justify-center">
31+
<h2 className="sr-only">{t("page-10-year-banner-header")}</h2>
2632
<TenYearDesktopText className="mb-4 hidden object-contain text-body md:block" />
2733
<TenYearMobileText className="mb-4 block object-contain text-5xl text-body md:hidden" />
2834
</div>
@@ -32,7 +38,12 @@ const TenYearHomeBanner = () => {
3238
</p>
3339
<p>{t("page-10-year-banner-tagline")}</p>
3440
</div>
35-
<Countdown className="mb-8 mt-4 bg-background" />
41+
<Countdown
42+
className="mb-8 mt-4 bg-background"
43+
timeLeftLabels={timeLeftLabels}
44+
expiredLabel={t("page-10-year-countdown-expired")}
45+
/>
46+
3647
<ButtonLink href="/10years/">{t("page-10-year-banner-cta")}</ButtonLink>
3748
</div>
3849
</div>

app/[locale]/10years/_components/utils.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { getTranslations } from "next-intl/server"
2+
3+
import { TimeLeftLabels } from "@/lib/types"
4+
15
import { formatDate, isValidDate } from "@/lib/utils/date"
26

37
import { DEFAULT_LOCALE } from "@/lib/constants"
@@ -29,3 +33,29 @@ export const parseStoryDates = (
2933
...story,
3034
date: parseDate(date, locale),
3135
}))
36+
37+
export const getTimeUnitTranslations = async (locale: string) => {
38+
const t = await getTranslations({
39+
locale,
40+
namespace: "page-10-year-anniversary",
41+
})
42+
const timeLeftLabels: TimeLeftLabels = {
43+
days: {
44+
singular: t("page-10-year-countdown-day"),
45+
plural: t("page-10-year-countdown-days"),
46+
},
47+
hours: {
48+
singular: t("page-10-year-countdown-hour"),
49+
plural: t("page-10-year-countdown-hours"),
50+
},
51+
minutes: {
52+
singular: t("page-10-year-countdown-minute"),
53+
plural: t("page-10-year-countdown-minutes"),
54+
},
55+
seconds: {
56+
singular: t("page-10-year-countdown-second"),
57+
plural: t("page-10-year-countdown-seconds"),
58+
},
59+
}
60+
return timeLeftLabels
61+
}

app/[locale]/10years/page.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { adoptionCards, adoptionStyles } from "./_components/data"
3232
import InnovationSwiper from "./_components/InnovationSwiper"
3333
import Stories from "./_components/Stories"
3434
import TenYearHero from "./_components/TenYearHero"
35-
import { parseStoryDates } from "./_components/utils"
35+
import { getTimeUnitTranslations, parseStoryDates } from "./_components/utils"
3636

3737
import { fetch10YearEvents } from "@/lib/api/fetch10YearEvents"
3838
import { fetch10YearStories } from "@/lib/api/fetch10YearStories"
@@ -74,6 +74,8 @@ const Page = async ({ params }: { params: Promise<{ locale: Lang }> }) => {
7474
namespace: "page-10-year-anniversary",
7575
})
7676

77+
const timeLeftLabels = await getTimeUnitTranslations(locale)
78+
7779
return (
7880
<I18nProvider locale={locale} messages={messages}>
7981
<MainArticle className="mx-auto flex w-full flex-col items-center">
@@ -92,7 +94,10 @@ const Page = async ({ params }: { params: Promise<{ locale: Lang }> }) => {
9294
</div>
9395
</div>
9496
<div className="flex flex-1 flex-row items-center justify-center">
95-
<CountDown />
97+
<CountDown
98+
timeLeftLabels={timeLeftLabels}
99+
expiredLabel={t("page-10-year-countdown-expired")}
100+
/>
96101
</div>
97102
</div>
98103

0 commit comments

Comments
 (0)