Major changes include enhancements to the UI and modifications to the i18n loading logic to more effectively handle namespaces. Several components were updated to improve readability and layout consistency. The i18n loading logic now includes additional handling for waiting until all namespaces are loaded before the i18n instance is returned, with a warning if it takes longer than expected. Furthermore, code have been refactored for fonts, buttons, and other UI elements.
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import { cookies } from 'next/headers';
|
|
|
|
import { Toaster } from '@kit/ui/sonner';
|
|
import { cn } from '@kit/ui/utils';
|
|
|
|
import { RootProviders } from '~/components/root-providers';
|
|
import { heading, sans } from '~/lib/fonts';
|
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
|
import { generateRootMetadata } from '~/lib/root-metdata';
|
|
|
|
import '../styles/globals.css';
|
|
|
|
export default async function RootLayout({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode;
|
|
}) {
|
|
const { language } = await createI18nServerInstance();
|
|
const theme = getTheme();
|
|
const className = getClassName(theme);
|
|
|
|
return (
|
|
<html lang={language} className={className}>
|
|
<body>
|
|
<RootProviders theme={theme} lang={language}>
|
|
{children}
|
|
</RootProviders>
|
|
|
|
<Toaster richColors={false} />
|
|
</body>
|
|
</html>
|
|
);
|
|
}
|
|
|
|
function getClassName(theme?: string) {
|
|
const dark = theme === 'dark';
|
|
const light = !dark;
|
|
|
|
const font = [sans.variable, heading.variable].reduce<string[]>(
|
|
(acc, curr) => {
|
|
if (acc.includes(curr)) return acc;
|
|
|
|
return [...acc, curr];
|
|
},
|
|
[],
|
|
);
|
|
|
|
return cn('min-h-screen bg-background antialiased', ...font, {
|
|
dark,
|
|
light,
|
|
});
|
|
}
|
|
|
|
function getTheme() {
|
|
return cookies().get('theme')?.value;
|
|
}
|
|
|
|
export const generateMetadata = generateRootMetadata;
|