Skip to content

Commit 86e40b2

Browse files
csantosrMrRoiz
authored andcommitted
chore: middleware to proxy and improving typing
1 parent b7b2fba commit 86e40b2

10 files changed

Lines changed: 26 additions & 40 deletions

File tree

app/[lang]/dictionaries.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ export const hasLocale = (locale: string): locale is Locale =>
1111
locale in dictionaries
1212

1313
export const getDictionary = async (locale: Locale) => dictionaries[locale]()
14+
15+
export type Dictionary = Awaited<ReturnType<typeof getDictionary>>;

app/[lang]/game/_components/card.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { type FC, useEffect, useRef, useState } from "react";
22
import { cn } from "@/lib/cls";
33
import { Button } from "@/primitives/components/ui/button";
4+
import { Dictionary } from "@/dictionaries";
45

56
const transitionClass = "duration-700";
67
// biome-ignore lint/style/noNonNullAssertion: Trust me bro
78
const changeOnMs = Number(transitionClass.split("-")[1]!) / 3;
89

9-
type Dictionary = Awaited<ReturnType<typeof import("@/dictionaries").getDictionary>>;
10-
1110
export const GameCard: FC<{
1211
player: { name: string; isSpy: boolean };
1312
onFinishCheck: () => void;

app/[lang]/game/local/play/_components/game.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { type FC, useCallback, useMemo, useState } from "react";
55
import { GameCard } from "@/game/_components/card";
66
import { gameSettingsAtom } from "../../_store/game-settings";
77
import { GameTimer } from "./timer";
8-
9-
type Dictionary = Awaited<ReturnType<typeof import("@/dictionaries").getDictionary>>;
8+
import { Dictionary } from "@/dictionaries";
109

1110
export const Game: FC<{ dict: Dictionary }> = ({ dict }) => {
1211
const gameSettings = useAtomValue(gameSettingsAtom);

app/[lang]/game/local/play/_components/timer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
import { type FC, useEffect, useState } from "react";
44
import { cn } from "@/lib/cls";
55
import { Button } from "@/primitives/components/ui/button";
6+
import { Dictionary } from "@/dictionaries";
67

78
const TIMER_DURATION = 120; // 2 minutes in seconds
89

9-
type Dictionary = Awaited<ReturnType<typeof import("@/dictionaries").getDictionary>>;
10-
1110
interface PlayerRole {
1211
name: string;
1312
isSpy: boolean;

app/[lang]/game/local/play/page.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ import { notFound } from 'next/navigation';
22
import { getDictionary, hasLocale } from '@/dictionaries';
33
import { Game } from "./_components/game";
44

5-
const Page = async ({
6-
params,
7-
}: {
8-
params: { lang: string };
9-
}) => {
10-
if (!hasLocale(params.lang)) notFound();
5+
const Page = async ({ params }: PageProps<'/[lang]/game/local/play'>) => {
6+
const { lang } = await params
7+
if (!hasLocale(lang)) notFound();
118

12-
const dict = await getDictionary(params.lang);
9+
const dict = await getDictionary(lang);
1310

1411
return <Game dict={dict} />;
1512
};

app/[lang]/game/local/setup/_components/form.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ import {
2626
InputGroupInput,
2727
} from "@/primitives/components/ui/input-group";
2828
import { gameSettingsAtom } from "../../_store/game-settings";
29+
import { Dictionary } from "@/dictionaries";
2930

3031
const MIN_PLAYERS = 3;
3132

32-
type Dictionary = Awaited<ReturnType<typeof import("@/dictionaries").getDictionary>>;
33-
3433
const createLocalGameFormSchema = (dict: Dictionary) => z
3534
.object({
3635
players: z

app/[lang]/game/local/setup/page.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ import { notFound } from 'next/navigation';
22
import { getDictionary, hasLocale } from '@/dictionaries';
33
import { LocalUsersForm } from "./_components/form";
44

5-
const Page = async ({
6-
params,
7-
}: {
8-
params: { lang: string };
9-
}) => {
10-
if (!hasLocale(params.lang)) notFound();
5+
const Page = async ({ params }: PageProps<'/[lang]/game/local/setup'>) => {
6+
const { lang } = await params
7+
if (!hasLocale(lang)) notFound();
118

12-
const dict = await getDictionary(params.lang);
9+
const dict = await getDictionary(lang);
1310

1411
return (
1512
<div className="w-2/3">
16-
<LocalUsersForm dict={dict} lang={params.lang} />
13+
<LocalUsersForm dict={dict} lang={lang} />
1714
</div>
1815
);
1916
};

app/[lang]/game/page.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ import { Button } from "@/primitives/components/ui/button";
44
import { notFound } from 'next/navigation'
55
import { getDictionary, hasLocale } from '@/dictionaries'
66

7-
const Page = async ({
8-
params,
9-
}: {
10-
params: { lang: string };
11-
}) => {
12-
if (!hasLocale(params.lang)) notFound()
7+
const Page = async ({ params }: PageProps<'/[lang]/game'>) => {
8+
const { lang } = await params
9+
if (!hasLocale(lang)) notFound()
1310

14-
const dict = await getDictionary(params.lang)
11+
const dict = await getDictionary(lang)
1512

16-
const otherLang = params.lang === 'en' ? 'es' : 'en';
17-
const langButtonText = params.lang === 'en' ? '¿Español?' : 'English?';
13+
const otherLang = lang === 'en' ? 'es' : 'en';
14+
const langButtonText = lang === 'en' ? '¿Español?' : 'English?';
1815

1916
return (
2017
<div className="relative flex flex-col gap-4">
@@ -28,7 +25,7 @@ const Page = async ({
2825
</Link>
2926
<FuzzyText>Guesspy</FuzzyText>
3027
<div className="flex flex-col gap-3 sm:flex-row sm:justify-center sm:gap-10">
31-
<Link className="w-full sm:w-auto" href={`/${params.lang}/game/local/setup`}>
28+
<Link className="w-full sm:w-auto" href={`/${lang}/game/local/setup`}>
3229
<Button className="w-full sm:w-auto">{dict.game.local}</Button>
3330
</Link>
3431
<Button disabled>{dict.game.room}</Button>

app/layout.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,12 @@ export const metadata: Metadata = {
3535
],
3636
};
3737

38-
export default function RootLayout({
38+
export default async function RootLayout({
3939
children,
4040
params,
41-
}: Readonly<{
42-
children: React.ReactNode;
43-
params: { lang: string };
44-
}>) {
41+
}: LayoutProps<'/[lang]/game'>) {
4542
return (
46-
<html lang={params.lang} suppressHydrationWarning>
43+
<html lang={(await params).lang} suppressHydrationWarning>
4744
<body
4845
className={`${geistSans.variable} ${geistMono.variable} antialiased`}>
4946
<ThemeProvider

middleware.js renamed to proxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function getLocale(request) {
1212
return match(languages, locales, defaultLocale)
1313
}
1414

15-
export function middleware(request) {
15+
export function proxy(request) {
1616
const { pathname } = request.nextUrl
1717

1818
const pathnameHasLocale = locales.some(

0 commit comments

Comments
 (0)