error fix

This commit is contained in:
hamid zarghami
2025-12-29 09:19:36 +03:30
parent 98b834b982
commit 87c457babe
2 changed files with 48 additions and 42 deletions
+3 -42
View File
@@ -6,6 +6,7 @@ import i18nConfig from "../../i18nConfig";
import initTranslations from '@/lib/i18n';
import TranslationsProvider from "@/components/utils/TranslationsProdiver";
import ToastContainer from "@/components/Toast";
import { ThemeColorSetter } from "@/components/ThemeColorSetter";
export const metadata: Metadata = {
title: 'Dashboard',
@@ -42,48 +43,7 @@ export default async function RootLayout({
dir='rtl'
className="h-svh overflow-hidden"
data-theme="light" >
<head>
<script
dangerouslySetInnerHTML={{
__html: `
(function() {
try {
const savedColor = localStorage.getItem('theme-primary-color');
if (savedColor) {
const hex = savedColor.replace('#', '');
const r = parseInt(hex.substring(0, 2), 16) / 255;
const g = parseInt(hex.substring(2, 4), 16) / 255;
const b = parseInt(hex.substring(4, 6), 16) / 255;
const lightness = 0.2126 * r + 0.7152 * g + 0.0722 * b;
const max = Math.max(r, g, b);
const min = Math.min(r, g, b);
const chroma = (max - min) * 0.15;
let hue = 0;
if (chroma !== 0) {
if (max === r) {
hue = ((g - b) / (max - min) + (g < b ? 6 : 0)) * 60;
} else if (max === g) {
hue = ((b - r) / (max - min) + 2) * 60;
} else {
hue = ((r - g) / (max - min) + 4) * 60;
}
}
const oklchColor = 'oklch(' + lightness.toFixed(3) + ' ' + chroma.toFixed(3) + ' ' + hue.toFixed(1) + ')';
document.documentElement.style.setProperty('--primary', oklchColor);
const brightness = (r * 299 + g * 587 + b * 114) / 1000;
const foregroundOklch = brightness > 0.5 ? 'oklch(0 0 0)' : 'oklch(1 0 0)';
document.documentElement.style.setProperty('--primary-foreground', foregroundOklch);
}
} catch (e) {}
})();
`,
}}
/>
</head>
<head />
<body
className={`antialiased bg-background h-svh overflow-hidden`}
@@ -93,6 +53,7 @@ export default async function RootLayout({
namespaces={i18nNamespaces}
locale={locale}
resources={resources}>
<ThemeColorSetter />
<div id="root" className="h-svh overflow-hidden">
{children}
</div>
+45
View File
@@ -0,0 +1,45 @@
'use client'
import { useEffect } from 'react'
export function ThemeColorSetter() {
useEffect(() => {
try {
const savedColor = localStorage.getItem('theme-primary-color')
if (savedColor) {
const hex = savedColor.replace('#', '')
const r = parseInt(hex.substring(0, 2), 16) / 255
const g = parseInt(hex.substring(2, 4), 16) / 255
const b = parseInt(hex.substring(4, 6), 16) / 255
const lightness = 0.2126 * r + 0.7152 * g + 0.0722 * b
const max = Math.max(r, g, b)
const min = Math.min(r, g, b)
const chroma = (max - min) * 0.15
let hue = 0
if (chroma !== 0) {
if (max === r) {
hue = ((g - b) / (max - min) + (g < b ? 6 : 0)) * 60
} else if (max === g) {
hue = ((b - r) / (max - min) + 2) * 60
} else {
hue = ((r - g) / (max - min) + 4) * 60
}
}
const oklchColor = `oklch(${lightness.toFixed(3)} ${chroma.toFixed(3)} ${hue.toFixed(1)})`
document.documentElement.style.setProperty('--primary', oklchColor)
const brightness = (r * 299 + g * 587 + b * 114) / 1000
const foregroundOklch = brightness > 0.5 ? 'oklch(0 0 0)' : 'oklch(1 0 0)'
document.documentElement.style.setProperty('--primary-foreground', foregroundOklch)
}
} catch (e) {
// Silent fail
}
}, [])
return null
}