Skip to content

Commit

Permalink
refactor: remove unnecessary providers
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierniki committed Nov 13, 2023
1 parent 2298d0a commit dbc385a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 34 deletions.
9 changes: 3 additions & 6 deletions src/app/[lang]/article/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { notFound } from "next/navigation"
import { Metadata } from "next/types"
import { NextIntlClientProvider } from "next-intl"
import { HeroArticleCard } from "@/components/ArticleCard/HeroArticleCard"
import { RecommendedArticles } from "@/components/RecommendedArticles/RecommendedArticles"
import { RichText } from "@/components/RichText/RichText"
Expand All @@ -9,6 +6,8 @@ import { env } from "@/env.mjs"
import { Locale } from "@/i18n/i18n"
import { getArticleBySlug, getArticleMetadataBySlug } from "@/lib/client"
import { getMatadataObj } from "@/utils/getMetadataObj"
import { notFound } from "next/navigation"
import { Metadata } from "next/types"

type ArticlePageProps = { params: { slug: string; lang: Locale } }

Expand Down Expand Up @@ -56,9 +55,7 @@ export default async function Web({ params: { slug, lang } }: ArticlePageProps)
<div className="mb-5 border-t py-5">
<ShareOnSocial articleUrl={articleUrl} articleTitle={title} />
</div>
<NextIntlClientProvider locale={lang}>
<RecommendedArticles id={article.id} />
</NextIntlClientProvider>
<RecommendedArticles id={article.id} />
</>
)
}
9 changes: 4 additions & 5 deletions src/app/[lang]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { notFound } from "next/navigation"
import { NextIntlClientProvider } from "next-intl"
import { unstable_setRequestLocale } from "next-intl/server"
import { Footer } from "@/components/Footer/Footer"
import { Navigation } from "@/components/Navigation/Navigation"
import { env } from "@/env.mjs"
import { i18n, type Locale } from "@/i18n/i18n"
import "@/styles/tailwind.css"
import { setTranslations } from "@/i18n/setTranslations"
import { getNavigation } from "@/lib/client"
import "@/styles/tailwind.css"
import { unstable_setRequestLocale } from "next-intl/server"
import { notFound } from "next/navigation"
import { GoogleAnalytics } from "../GoogleAnalytics"
import Providers from "../Providers"

Expand Down Expand Up @@ -45,7 +44,7 @@ export default async function Layout({ children, params }: { children: React.Rea
const { navigation, footer, logo } = await getNavigation(locale)

return (
<html lang={locale} style={{ scrollbarGutter: "stable" }}>
<html lang={locale}>
<GoogleAnalytics />
<Providers translations={translations} locale={locale}>
<body className="flex min-h-screen flex-col items-center">
Expand Down
7 changes: 2 additions & 5 deletions src/components/CategoryArticles/CategoryArticles.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { notFound } from "next/navigation"
import { NextIntlClientProvider } from "next-intl"
import { useLocale } from "@/i18n/i18n"
import { getTranslations } from "@/i18n/setTranslations"
import { listArticlesByCategory } from "@/lib/client"
import { CategoryArticlesInfiniteDynamic } from "./CategoryArticlesInfiniteDynamic"
import { getTranslations } from "@/i18n/setTranslations"

export const CATEGORY_ARTICLES_PER_PAGE = 4

Expand All @@ -29,9 +28,7 @@ export async function CategoryArticles({ category }: CategoryArticlesProps) {
<p className="text-xl font-bold">&quot;{category}&quot;</p>
</div>
<div className="mx-auto w-full">
<NextIntlClientProvider locale={locale}>
<CategoryArticlesInfiniteDynamic category={category} initialArticles={articles} />
</NextIntlClientProvider>
<CategoryArticlesInfiniteDynamic category={category} initialArticles={articles} />
</div>
</section>
)
Expand Down
5 changes: 1 addition & 4 deletions src/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Image from "next/image"
import Link from "next/link"
import { NextIntlClientProvider } from "next-intl"
import { useLocale } from "@/i18n/i18n"
import FacebookIcon from "../../../public/icons/facebook.svg"
import InstagramIcon from "../../../public/icons/instagram.svg"
Expand Down Expand Up @@ -67,9 +66,7 @@ export async function Footer({ footer, logoUrl }: FooterProps) {
</nav>
<div className="flex flex-col justify-between gap-10 md:max-w-[30%] lg:items-end lg:gap-3">
<div className="w-fit lg:w-auto">
<NextIntlClientProvider locale={locale}>
<DynamicLangSelect />
</NextIntlClientProvider>
<DynamicLangSelect />
</div>
{logoUrl && (
<Link
Expand Down
5 changes: 1 addition & 4 deletions src/components/RecentArticles/RecentArticles.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { NextIntlClientProvider } from "next-intl"
import { useLocale } from "@/i18n/i18n"
import { getRecentArticlesWithMain } from "@/lib/client"
import { RecentArticlesInfiniteDynamic } from "./RecentArticlesInfiniteDynamic"
Expand Down Expand Up @@ -26,9 +25,7 @@ export async function RecentArticles({ title }: RecentArticlesProps) {
tagsPosition="over"
/>
</div>
<NextIntlClientProvider locale={locale}>
<RecentArticlesInfiniteDynamic initialArticles={initialArticles} />
</NextIntlClientProvider>
<RecentArticlesInfiniteDynamic initialArticles={initialArticles} />
</section>
)
}
12 changes: 2 additions & 10 deletions src/components/RichText/RichText.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable jsx-a11y/heading-has-content */
import { cn } from "@/utils/cn"
import { RichText as HygraphRichText } from "@graphcms/rich-text-react-renderer"
import { EmbedReferences, RichTextContent } from "@graphcms/rich-text-types"
import Image from "next/image"
import { NextIntlClientProvider } from "next-intl"
import { useLocale } from "@/i18n/i18n"
import { cn } from "@/utils/cn"
import { CodeSnippetDynamic } from "../CodeSnippet/CodeSnippetDynamic"
import { QuizDynamic } from "../Quiz/QuizDynamic"

Expand All @@ -17,8 +15,6 @@ export function RichText({
references?: EmbedReferences
pClassName?: string
}) {
const locale = useLocale()

return (
<HygraphRichText
references={references}
Expand Down Expand Up @@ -50,11 +46,7 @@ export function RichText({
),
embed: {
Quiz: (props) => {
return (
<NextIntlClientProvider locale={locale}>
<QuizDynamic id={props.id} />
</NextIntlClientProvider>
)
return props.id ? <QuizDynamic id={props.id} /> : <></>
},
},
}}
Expand Down

0 comments on commit dbc385a

Please sign in to comment.