-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
40 lines (35 loc) · 1.92 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use client';
import { type PropsWithChildren, useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import type { IRootState } from '@/store';
import { toggleRTL, toggleTheme, toggleMenu, toggleLayout, toggleAnimation, toggleNavbar, toggleSemidark } from '@/store/themeConfigSlice';
import Loading from '@/components/layouts/loading';
import { getTranslation } from '@/i18n';
function App({ children }: PropsWithChildren) {
const themeConfig = useSelector((state: IRootState) => state.themeConfig);
const dispatch = useDispatch();
const { initLocale } = getTranslation();
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
dispatch(toggleTheme(localStorage.getItem('theme') || themeConfig.theme));
dispatch(toggleMenu(localStorage.getItem('menu') || themeConfig.menu));
dispatch(toggleLayout(localStorage.getItem('layout') || themeConfig.layout));
dispatch(toggleRTL(localStorage.getItem('rtlClass') || themeConfig.rtlClass));
dispatch(toggleAnimation(localStorage.getItem('animation') || themeConfig.animation));
dispatch(toggleNavbar(localStorage.getItem('navbar') || themeConfig.navbar));
dispatch(toggleSemidark(localStorage.getItem('semidark') || themeConfig.semidark));
// locale
initLocale(themeConfig.locale);
setIsLoading(false);
}, [dispatch, initLocale, themeConfig.theme, themeConfig.menu, themeConfig.layout, themeConfig.rtlClass, themeConfig.animation, themeConfig.navbar, themeConfig.locale, themeConfig.semidark]);
return (
<div
className={`${(themeConfig.sidebar && 'toggle-sidebar') || ''} ${themeConfig.menu} ${themeConfig.layout} ${
themeConfig.rtlClass
} main-section relative font-nunito text-sm font-normal antialiased`}
>
{isLoading ? <Loading /> : children}
</div>
);
}
export default App;