refactor: enhance I18n component with loading state and prefetch system features

pull/22810/head
twwu 7 months ago
parent 38b4829083
commit b7317bb650

@ -1,10 +1,13 @@
'use client' 'use client'
import type { FC } from 'react' import type { FC } from 'react'
import React, { useEffect } from 'react' import React, { useEffect, useState } from 'react'
import I18NContext from '@/context/i18n' import I18NContext from '@/context/i18n'
import type { Locale } from '@/i18n' import type { Locale } from '@/i18n'
import { setLocaleOnClient } from '@/i18n' import { setLocaleOnClient } from '@/i18n'
import Loading from './base/loading'
import { usePrefetchQuery } from '@tanstack/react-query'
import { getSystemFeatures } from '@/service/common'
export type II18nProps = { export type II18nProps = {
locale: Locale locale: Locale
@ -14,10 +17,22 @@ const I18n: FC<II18nProps> = ({
locale, locale,
children, children,
}) => { }) => {
const [loading, setLoading] = useState(true)
usePrefetchQuery({
queryKey: ['systemFeatures'],
queryFn: getSystemFeatures,
})
useEffect(() => { useEffect(() => {
setLocaleOnClient(locale, false) setLocaleOnClient(locale, false).then(() => {
setLoading(false)
})
}, [locale]) }, [locale])
if (loading)
return <div className='flex h-screen w-screen items-center justify-center'><Loading type='app' /></div>
return ( return (
<I18NContext.Provider value={{ <I18NContext.Provider value={{
locale, locale,

Loading…
Cancel
Save