2025-04-27 17:00:41 +08:00
import { Toaster as Sonner } from '@/components/ui/sonner' ;
import { Toaster } from '@/components/ui/toaster' ;
2024-04-12 11:41:00 +08:00
import i18n from '@/locales/config' ;
2024-07-19 09:07:36 +08:00
import { QueryClient , QueryClientProvider } from '@tanstack/react-query' ;
2024-12-10 10:42:04 +07:00
import { App , ConfigProvider , ConfigProviderProps , theme } from 'antd' ;
2025-02-24 19:30:33 +08:00
import pt_BR from 'antd/lib/locale/pt_BR' ;
2025-04-27 17:00:41 +08:00
import deDE from 'antd/locale/de_DE' ;
2024-04-07 17:41:29 +08:00
import enUS from 'antd/locale/en_US' ;
2025-08-28 09:42:42 +06:00
import ru_RU from 'antd/locale/ru_RU' ;
2024-11-21 17:43:08 +07:00
import vi_VN from 'antd/locale/vi_VN' ;
2024-04-07 17:41:29 +08:00
import zhCN from 'antd/locale/zh_CN' ;
2024-04-12 11:41:00 +08:00
import zh_HK from 'antd/locale/zh_HK' ;
2024-04-16 19:06:47 +08:00
import dayjs from 'dayjs' ;
import advancedFormat from 'dayjs/plugin/advancedFormat' ;
import customParseFormat from 'dayjs/plugin/customParseFormat' ;
import localeData from 'dayjs/plugin/localeData' ;
import weekOfYear from 'dayjs/plugin/weekOfYear' ;
import weekYear from 'dayjs/plugin/weekYear' ;
2024-06-05 10:46:06 +08:00
import weekday from 'dayjs/plugin/weekday' ;
2024-07-19 09:07:36 +08:00
import React , { ReactNode , useEffect , useState } from 'react' ;
2024-12-10 10:42:04 +07:00
import { ThemeProvider , useTheme } from './components/theme-provider' ;
2025-05-02 21:27:21 +08:00
import { SidebarProvider } from './components/ui/sidebar' ;
2025-01-15 14:39:33 +08:00
import { TooltipProvider } from './components/ui/tooltip' ;
2025-07-31 12:14:00 +08:00
import { ThemeEnum } from './constants/common' ;
2024-07-25 14:38:17 +08:00
import storage from './utils/authorization-util' ;
2024-04-16 19:06:47 +08:00
dayjs . extend ( customParseFormat ) ;
dayjs . extend ( advancedFormat ) ;
dayjs . extend ( weekday ) ;
dayjs . extend ( localeData ) ;
dayjs . extend ( weekOfYear ) ;
dayjs . extend ( weekYear ) ;
2024-04-12 11:41:00 +08:00
const AntLanguageMap = {
en : enUS ,
zh : zhCN ,
'zh-TRADITIONAL' : zh_HK ,
2025-08-28 09:42:42 +06:00
ru : ru_RU ,
2024-11-21 17:43:08 +07:00
vi : vi_VN ,
2025-02-05 07:20:24 -03:00
'pt-BR' : pt_BR ,
2025-03-11 09:13:58 +01:00
de : deDE ,
2024-04-12 11:41:00 +08:00
} ;
2025-05-30 12:14:44 +08:00
if ( process . env . NODE_ENV === 'development' ) {
const whyDidYouRender = require ( '@welldone-software/why-did-you-render' ) ;
whyDidYouRender ( React , {
trackAllPureComponents : true ,
trackExtraHooks : [ ] ,
logOnDifferentValues : true ,
} ) ;
}
2024-06-05 10:46:06 +08:00
const queryClient = new QueryClient ( ) ;
2024-04-07 17:41:29 +08:00
type Locale = ConfigProviderProps [ 'locale' ] ;
2024-12-10 10:42:04 +07:00
function Root ( { children } : React . PropsWithChildren ) {
const { theme : themeragflow } = useTheme ( ) ;
2024-04-12 11:41:00 +08:00
const getLocale = ( lng : string ) = >
AntLanguageMap [ lng as keyof typeof AntLanguageMap ] ? ? enUS ;
2024-04-07 17:41:29 +08:00
const [ locale , setLocal ] = useState < Locale > ( getLocale ( storage . getLanguage ( ) ) ) ;
2024-04-12 11:41:00 +08:00
i18n . on ( 'languageChanged' , function ( lng : string ) {
2024-04-07 17:41:29 +08:00
storage . setLanguage ( lng ) ;
setLocal ( getLocale ( lng ) ) ;
} ) ;
2024-12-10 10:42:04 +07:00
return (
< >
< ConfigProvider
theme = { {
token : {
fontFamily : 'Inter' ,
} ,
algorithm :
themeragflow === 'dark'
? theme . darkAlgorithm
: theme . defaultAlgorithm ,
} }
locale = { locale }
>
2025-06-30 15:39:38 +08:00
< SidebarProvider className = "h-full" >
2025-05-02 21:27:21 +08:00
< App > { children } < / App >
< / SidebarProvider >
2025-04-27 17:00:41 +08:00
< Sonner position = { 'top-right' } expand richColors closeButton > < / Sonner >
< Toaster / >
2024-12-10 10:42:04 +07:00
< / ConfigProvider >
2025-08-25 14:06:06 +08:00
{ /* <ReactQueryDevtools buttonPosition={'top-left'} initialIsOpen={false} /> */ }
2024-12-10 10:42:04 +07:00
< / >
) ;
}
const RootProvider = ( { children } : React . PropsWithChildren ) = > {
2024-04-07 17:41:29 +08:00
useEffect ( ( ) = > {
2024-04-08 10:41:03 +08:00
// Because the language is saved in the backend, a token is required to obtain the api. However, the login page cannot obtain the language through the getUserInfo api, so the language needs to be saved in localstorage.
const lng = storage . getLanguage ( ) ;
if ( lng ) {
i18n . changeLanguage ( lng ) ;
}
} , [ ] ) ;
2024-01-29 15:02:27 +08:00
2024-04-02 15:44:09 +08:00
return (
2025-01-15 14:39:33 +08:00
< TooltipProvider >
< QueryClientProvider client = { queryClient } >
2025-07-31 12:14:00 +08:00
< ThemeProvider
2025-10-14 19:06:50 +08:00
defaultTheme = { ThemeEnum . Dark }
2025-07-31 12:14:00 +08:00
storageKey = "ragflow-ui-theme"
>
2025-01-15 14:39:33 +08:00
< Root > { children } < / Root >
< / ThemeProvider >
< / QueryClientProvider >
< / TooltipProvider >
2024-03-20 18:20:42 +08:00
) ;
2024-04-07 17:41:29 +08:00
} ;
export function rootContainer ( container : ReactNode ) {
return < RootProvider > { container } < / RootProvider > ;
2024-01-29 15:02:27 +08:00
}