Files
homaroma/apps/website/src/components/ClientProviders.tsx
T
2026-07-21 21:22:40 -04:00

38 lines
1.2 KiB
TypeScript

"use client";
import '../lib/i18n';
import CartDrawer from './CartDrawer';
import ScrollToTop from './ScrollToTop';
import { useEffect, type ReactNode } from 'react';
import i18n from '../lib/i18n';
import { useCartStore } from '../store/cartStore';
import { useWishlistStore } from '../store/wishlistStore';
import { useAuthStore } from '../store/authStore';
import { DEFAULT_LOCALE, SUPPORTED_LOCALES } from '../lib/locales';
export default function ClientProviders({ children }: { children: ReactNode }) {
useEffect(() => {
// With Locale Routing, the URL is the source of truth for language.
// Sync i18n to match the current URL if needed.
const pathLang = window.location.pathname.split('/')[1];
const targetLang = pathLang && (SUPPORTED_LOCALES as readonly string[]).includes(pathLang) ? pathLang : DEFAULT_LOCALE;
if (targetLang !== i18n.language) {
void i18n.changeLanguage(targetLang);
}
}, [])
useEffect(() => {
void useCartStore.persist.rehydrate()
void useWishlistStore.persist.rehydrate()
void useAuthStore.persist.rehydrate()
}, [])
return (
<>
<ScrollToTop />
{children}
<CartDrawer />
</>
);
}