Skip to content

Commit 920a3b0

Browse files
committed
fix: move react query provider to root layout
1 parent 18338b2 commit 920a3b0

File tree

10 files changed

+38
-47
lines changed

10 files changed

+38
-47
lines changed

apps/web/src/app/[locale]/account/userinfo.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ import { useTranslations } from "next-intl"
66
import { Badge } from "@karr/ui/components/badge"
77

88
import { apiFetch } from "@/util/apifetch"
9-
import { QueryProvider } from "@/components/QueryProvider"
109

1110
export default function UserInfo({ userid }: { userid: string }) {
12-
return (
13-
<QueryProvider>
14-
<FetchUserData userid={userid} />
15-
</QueryProvider>
16-
)
11+
return <FetchUserData userid={userid} />
1712
}
1813

1914
function FetchUserData({ userid }: { userid: string }) {

apps/web/src/app/[locale]/layout.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import { getMessages } from "next-intl/server"
66

77
import { Toaster } from "@karr/ui/components/sonner"
88

9-
import "@/assets/globals.css"
10-
119
import { routing } from "@/i18n/routing"
1210
import { APPLICATION_NAME } from "@/util/appname"
11+
import "@/assets/globals.css"
12+
import { Locale } from "@/../global"
1313

14-
import Footer from "../_components/footer"
15-
import Header from "../_components/header"
16-
import ThemeProvider from "../_components/ThemeProvider"
14+
import { Footer } from "~/_components/footer"
15+
import { Header } from "~/_components/header"
16+
import { Providers } from "~/_components/Providers"
1717

1818
const geistSans = localFont({
1919
src: "../../assets/fonts/GeistVF.woff",
@@ -36,12 +36,12 @@ export default async function RootLayout({
3636
params
3737
}: Readonly<{
3838
children: React.ReactNode
39-
params: Promise<{ locale: string }>
39+
params: Promise<{ locale: Locale }>
4040
}>) {
4141
const { locale } = await params
4242

4343
// Ensure that the incoming `locale` is valid
44-
if (!routing.locales.includes(locale as "en" | "fr")) {
44+
if (!routing.locales.includes(locale)) {
4545
notFound()
4646
}
4747

@@ -59,12 +59,7 @@ export default async function RootLayout({
5959
{/* <script src="https://unpkg.com/react-scan/dist/auto.global.js" async /> */}
6060
</head>
6161
<body>
62-
<ThemeProvider
63-
attribute="class"
64-
defaultTheme="system"
65-
enableSystem
66-
disableTransitionOnChange
67-
>
62+
<Providers>
6863
<NextIntlClientProvider messages={messages}>
6964
<div className="grid h-screen grid-cols-1 grid-rows-[auto_1fr]">
7065
<Header />
@@ -75,7 +70,7 @@ export default async function RootLayout({
7570
</div>
7671
<Toaster richColors />
7772
</NextIntlClientProvider>
78-
</ThemeProvider>
73+
</Providers>
7974
</body>
8075
</html>
8176
)
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import { Suspense } from "react"
21
import { useTranslations } from "next-intl"
32

4-
import Loading from "@/components/Loading"
5-
63
import NewTripForm from "./newTripForm"
74

85
export default function New() {
@@ -11,9 +8,7 @@ export default function New() {
118
<article className="mt-6 flex flex-col items-center justify-center gap-4 w-full">
129
<h3 className="mb-4">{t("title")}</h3>
1310

14-
<Suspense fallback={<Loading />}>
15-
<NewTripForm />
16-
</Suspense>
11+
<NewTripForm />
1712
</article>
1813
)
1914
}

apps/web/src/app/[locale]/trips/search/trips.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,9 @@ import { toast } from "@karr/ui/components/sonner"
2323

2424
import { apiFetch } from "@/util/apifetch"
2525
import Loading from "@/components/Loading"
26-
import { QueryProvider } from "@/components/QueryProvider"
2726

2827
export default function TripList({ userid }: { userid: string }) {
29-
return (
30-
<QueryProvider>
31-
<FetchTrips userid={userid} />
32-
</QueryProvider>
33-
)
28+
return <FetchTrips userid={userid} />
3429
}
3530

3631
function FetchTrips({ userid }: { userid: string }) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use client"
2+
3+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
4+
import { ThemeProvider } from "next-themes"
5+
6+
const queryClient = new QueryClient()
7+
8+
export function Providers({ children }: { children: React.ReactNode }) {
9+
return (
10+
<QueryClientProvider client={queryClient}>
11+
<ThemeProvider
12+
attribute="class"
13+
defaultTheme="system"
14+
enableSystem
15+
disableTransitionOnChange
16+
>
17+
{children}
18+
</ThemeProvider>
19+
</QueryClientProvider>
20+
)
21+
}

apps/web/src/app/_components/ThemeProvider.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

apps/web/src/app/_components/footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { LocaleSwitcher } from "./footer/LocaleSwitcher"
66
import { ThemeSwitch } from "./footer/ThemeSwitch"
77
import { isProduction, version } from "./footer/version"
88

9-
export default function Footer() {
9+
export function Footer() {
1010
return (
1111
<footer className="flex w-full flex-col items-center justify-between px-4 py-2">
1212
<Separator />
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import "server-only"
22

33
import packageJson from "../../../../../../package.json" with { type: "json" }
4+
import { PRODUCTION } from "@karr/config"
45

56
export const version = packageJson.version
6-
export const isProduction = process.env.NODE_ENV === "production"
7+
export const isProduction = PRODUCTION

apps/web/src/app/_components/header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const MemoizedAppName = memo(
1414
() => false // Never update
1515
)
1616

17-
export default async function Header() {
17+
export async function Header() {
1818
const isAuthenticated = await auth()
1919

2020
return (

config/karr.config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ADMIN_EMAIL: [email protected]
1010
FEDERATION: true
1111
FEDERATION_TARGETS:
1212
- name: Karr Live
13-
url: https://karr.mobi
13+
url: https://karr2.finxol.io
1414
DB_CONFIG:
1515
host: localhost
1616
port: 5432

0 commit comments

Comments
 (0)