Skip to content

Commit

Permalink
chore: move ConfigProvider to layout.tsx, as all pages need it (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueBrain authored Apr 28, 2024
1 parent 58dfecc commit e928169
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 58 deletions.
14 changes: 5 additions & 9 deletions src/app/language/[language]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@ import React from "react";
import { getNileConfig } from "@/static/NileConfig";
import { LanguageProvider } from "@/providers/LanguageProvider";
import { LayoutCommon } from "@/components/LayoutCommon";
import { ConfigProvider } from "@/providers/ConfigProvider";
import { Listing } from "./Listing";

export default async function Home({ params }: { params: { language: string } }) {
const { language } = params;
const nileConfig = await getNileConfig();

return (
<main>
<ConfigProvider config={nileConfig}>
<LanguageProvider initialLanguage={language}>
<LayoutCommon>
<Listing />
</LayoutCommon>
</LanguageProvider>
</ConfigProvider>
<LanguageProvider initialLanguage={language}>
<LayoutCommon>
<Listing />
</LayoutCommon>
</LanguageProvider>
</main>
);
}
Expand Down
12 changes: 3 additions & 9 deletions src/app/languages/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import React from "react";
import { getNileConfig } from "@/static/NileConfig";
import { LayoutCommon } from "@/components/LayoutCommon";
import { ConfigProvider } from "@/providers/ConfigProvider";
import { Listing } from "./Listing";

export default async function Home() {
const nileConfig = await getNileConfig();

return (
<main>
<ConfigProvider config={nileConfig}>
<LayoutCommon>
<Listing />
</LayoutCommon>
</ConfigProvider>
<LayoutCommon>
<Listing />
</LayoutCommon>
</main>
);
}
10 changes: 8 additions & 2 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,31 @@ import type { Metadata } from "next";
import "./globals.css";
import '@mantine/core/styles.css';
import { ColorSchemeScript, MantineProvider } from '@mantine/core';
import { getNileConfig } from "@/static/NileConfig";
import { ConfigProvider } from "@/providers/ConfigProvider";

export const metadata: Metadata = {
title: "OpenTTD Web Translator",
description: "Translate OpenTTD into your language",
};

export default function RootLayout({
export default async function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
const nileConfig = await getNileConfig();

return (
<html lang="en">
<head>
<ColorSchemeScript defaultColorScheme="auto" />
</head>
<body>
<MantineProvider defaultColorScheme="auto">
{children}
<ConfigProvider config={nileConfig}>
{children}
</ConfigProvider>
</MantineProvider>
</body>
</html>
Expand Down
14 changes: 5 additions & 9 deletions src/app/project/[project]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import React from "react";
import { getNileConfig } from "@/static/NileConfig";
import { ConfigProvider } from "@/providers/ConfigProvider";
import { ProjectProvider } from "@/providers/ProjectProvider";
import { LayoutCommon } from "@/components/LayoutCommon";
import { Listing } from "./Listing";

export default async function Home({ params }: { params: { project: string } }) {
const { project } = params;
const nileConfig = await getNileConfig();

return (
<main>
<ConfigProvider config={nileConfig}>
<ProjectProvider initialProject={project}>
<LayoutCommon>
<Listing />
</LayoutCommon>
</ProjectProvider>
</ConfigProvider>
<ProjectProvider initialProject={project}>
<LayoutCommon>
<Listing />
</LayoutCommon>
</ProjectProvider>
</main>
);
}
Expand Down
12 changes: 3 additions & 9 deletions src/app/projects/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import React from "react";
import { getNileConfig } from "@/static/NileConfig";
import { LayoutCommon } from "@/components/LayoutCommon";
import { ConfigProvider } from "@/providers/ConfigProvider";
import { Listing } from "./Listing";

export default async function Home() {
const nileConfig = await getNileConfig();

return (
<main>
<ConfigProvider config={nileConfig}>
<LayoutCommon>
<Listing />
</LayoutCommon>
</ConfigProvider>
<LayoutCommon>
<Listing />
</LayoutCommon>
</main>
);
}
18 changes: 7 additions & 11 deletions src/app/string/[project]/[language]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@ import React from "react";
import { getNileConfig } from "@/static/NileConfig";
import { LanguageProvider } from "@/providers/LanguageProvider";
import { ValidatorProvider } from "@/providers/ValidatorProvider";
import { ConfigProvider } from "@/providers/ConfigProvider";
import { ProjectProvider } from "@/providers/ProjectProvider";
import { Listing } from "./Listing";
import { LayoutCommon } from "@/components/LayoutCommon";

export default async function Home({ params }: { params: { project: string, language: string } }) {
const { project, language } = params;
const nileConfig = await getNileConfig();

return (
<main>
<ValidatorProvider>
<ConfigProvider config={nileConfig}>
<ProjectProvider initialProject={project}>
<LanguageProvider initialLanguage={language}>
<LayoutCommon>
<Listing />
</LayoutCommon>
</LanguageProvider>
</ProjectProvider>
</ConfigProvider>
<ProjectProvider initialProject={project}>
<LanguageProvider initialLanguage={language}>
<LayoutCommon>
<Listing />
</LayoutCommon>
</LanguageProvider>
</ProjectProvider>
</ValidatorProvider>
</main>
);
Expand Down
14 changes: 5 additions & 9 deletions src/app/translation/[project]/[language]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@ import React from "react";
import { getNileConfig } from "@/static/NileConfig";
import { LanguageProvider } from "@/providers/LanguageProvider";
import { ValidatorProvider } from "@/providers/ValidatorProvider";
import { ConfigProvider } from "@/providers/ConfigProvider";
import { ProjectProvider } from "@/providers/ProjectProvider";
import { Listing } from "./Listing";

export default async function Home({ params }: { params: { project: string, language: string } }) {
const { project, language } = params;
const nileConfig = await getNileConfig();

return (
<main>
<ValidatorProvider>
<ConfigProvider config={nileConfig}>
<ProjectProvider initialProject={project}>
<LanguageProvider initialLanguage={language}>
<Listing />
</LanguageProvider>
</ProjectProvider>
</ConfigProvider>
<ProjectProvider initialProject={project}>
<LanguageProvider initialLanguage={language}>
<Listing />
</LanguageProvider>
</ProjectProvider>
</ValidatorProvider>
</main>
);
Expand Down

0 comments on commit e928169

Please sign in to comment.