Skip to content

Commit 2b382f9

Browse files
committed
refactor: use await getLocale
avoid prop drilling locale
1 parent f3ccf83 commit 2b382f9

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

app/[locale]/layout.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ export default async function LocaleLayout({
6767
<Matomo />
6868
</Suspense>
6969

70-
<BaseLayout
71-
locale={locale}
72-
lastDeployLocaleTimestamp={lastDeployLocaleTimestamp}
73-
>
70+
<BaseLayout lastDeployLocaleTimestamp={lastDeployLocaleTimestamp}>
7471
{children}
7572
</BaseLayout>
7673
</Providers>

src/components/Nav/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { getTranslations } from "next-intl/server"
1+
import { getLocale, getTranslations } from "next-intl/server"
22

33
import { EthHomeIcon } from "@/components/icons"
44

55
import { BaseLink } from "../ui/Link"
66

77
import ClientSideNav from "./Client"
88

9-
const Nav = async ({ locale }) => {
9+
const Nav = async () => {
10+
const locale = await getLocale()
1011
const t = await getTranslations({ locale, namespace: "common" })
1112

1213
return (

src/components/SkipLink.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1+
import { getLocale, getTranslations } from "next-intl/server"
2+
13
import { MAIN_CONTENT_ID } from "@/lib/constants"
24

35
import { BaseLink } from "./ui/Link"
46

5-
export const SkipLink = ({ children }: { children: string }) => (
6-
<div className="bg-primary-low-contrast focus-within:p-4">
7-
<BaseLink
8-
href={"#" + MAIN_CONTENT_ID}
9-
className="absolute -top-14 rounded border bg-primary px-4 py-2 leading-8 text-background no-underline hover:no-underline focus:static"
10-
>
11-
{children}
12-
</BaseLink>
13-
</div>
14-
)
7+
export const SkipLink = async () => {
8+
const locale = await getLocale()
9+
const t = await getTranslations({ locale, namespace: "common" })
10+
11+
return (
12+
<div className="bg-primary-low-contrast focus-within:p-4">
13+
<BaseLink
14+
href={"#" + MAIN_CONTENT_ID}
15+
className="absolute -top-14 rounded border bg-primary px-4 py-2 leading-8 text-background no-underline hover:no-underline focus:static"
16+
>
17+
{t("skip-to-main-content")}
18+
</BaseLink>
19+
</div>
20+
)
21+
}

src/layouts/BaseLayout.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// import { join } from "path"
22
import dynamic from "next/dynamic"
3-
import { getTranslations } from "next-intl/server"
43

54
import type { Root } from "@/lib/types"
65

@@ -22,9 +21,7 @@ export const BaseLayout = async ({
2221
// contentIsOutdated,
2322
// contentNotTranslated,
2423
lastDeployLocaleTimestamp,
25-
locale,
2624
}: Root) => {
27-
const t = await getTranslations({ locale, namespace: "common" })
2825
// const { locale, asPath } = useRouter()
2926

3027
// const CONTRIBUTING = "/contributing/"
@@ -53,9 +50,9 @@ export const BaseLayout = async ({
5350
* The Skip Link is positioned above the container to ensure it is not affecting the
5451
* layout on initial load.
5552
*/}
56-
<SkipLink>{t("skip-to-main-content")}</SkipLink>
53+
<SkipLink />
5754
<div className="mx-auto max-w-screen-2xl">
58-
<Nav locale={locale} />
55+
<Nav />
5956

6057
{/* TODO: FIX TRANSLATION BANNER LOGIC FOR https://github.com/ethereum/ethereum-org-website/issues/11305 */}
6158
{/* <TranslationBanner

src/lib/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export type AppPropsWithLayout = AppProps & {
5050
export type Root = {
5151
children: ReactNode
5252
lastDeployLocaleTimestamp: string
53-
locale: string
5453
}
5554

5655
export type BasePageProps = Pick<Root, "lastDeployLocaleTimestamp">

0 commit comments

Comments
 (0)