aboutsummaryrefslogtreecommitdiff
path: root/src/app/Providers.tsx
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-01-24 13:09:50 +0000
committerFuwn <[email protected]>2026-01-24 13:09:50 +0000
commit396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b (patch)
treeb9df4ca6a70db45cfffbae6fdd7252e20fb8e93c /src/app/Providers.tsx
downloadumami-main.tar.xz
umami-main.zip
Initial commitHEADmain
Created from https://vercel.com/new
Diffstat (limited to 'src/app/Providers.tsx')
-rw-r--r--src/app/Providers.tsx62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/app/Providers.tsx b/src/app/Providers.tsx
new file mode 100644
index 0000000..ae1a000
--- /dev/null
+++ b/src/app/Providers.tsx
@@ -0,0 +1,62 @@
+'use client';
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
+import { RouterProvider, ZenProvider } from '@umami/react-zen';
+import { useRouter } from 'next/navigation';
+import { useEffect } from 'react';
+import { IntlProvider } from 'react-intl';
+import { ErrorBoundary } from '@/components/common/ErrorBoundary';
+import { useLocale } from '@/components/hooks';
+import 'chartjs-adapter-date-fns';
+
+const client = new QueryClient({
+ defaultOptions: {
+ queries: {
+ retry: false,
+ refetchOnWindowFocus: false,
+ staleTime: 1000 * 60,
+ },
+ },
+});
+
+function MessagesProvider({ children }) {
+ const { locale, messages, dir } = useLocale();
+
+ useEffect(() => {
+ document.documentElement.setAttribute('dir', dir);
+ document.documentElement.setAttribute('lang', locale);
+ }, [locale, dir]);
+
+ return (
+ <IntlProvider locale={locale} messages={messages[locale]} onError={() => null}>
+ {children}
+ </IntlProvider>
+ );
+}
+
+export function Providers({ children }) {
+ const router = useRouter();
+
+ function navigate(url: string) {
+ if (shouldUseNativeLink(url)) {
+ window.location.href = url;
+ } else {
+ router.push(url);
+ }
+ }
+
+ function shouldUseNativeLink(url: string) {
+ return url.startsWith('http');
+ }
+
+ return (
+ <ZenProvider>
+ <RouterProvider navigate={navigate}>
+ <MessagesProvider>
+ <QueryClientProvider client={client}>
+ <ErrorBoundary>{children}</ErrorBoundary>
+ </QueryClientProvider>
+ </MessagesProvider>
+ </RouterProvider>
+ </ZenProvider>
+ );
+}