From b7317bb6505c4ee0e39f87c0f821634c7ef7b7e8 Mon Sep 17 00:00:00 2001 From: twwu Date: Wed, 23 Jul 2025 14:04:43 +0800 Subject: [PATCH] refactor: enhance I18n component with loading state and prefetch system features --- web/app/components/i18n.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/web/app/components/i18n.tsx b/web/app/components/i18n.tsx index f04f8d6cbe..374b1f608f 100644 --- a/web/app/components/i18n.tsx +++ b/web/app/components/i18n.tsx @@ -1,10 +1,13 @@ 'use client' import type { FC } from 'react' -import React, { useEffect } from 'react' +import React, { useEffect, useState } from 'react' import I18NContext from '@/context/i18n' import type { Locale } 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 = { locale: Locale @@ -14,10 +17,22 @@ const I18n: FC = ({ locale, children, }) => { + const [loading, setLoading] = useState(true) + + usePrefetchQuery({ + queryKey: ['systemFeatures'], + queryFn: getSystemFeatures, + }) + useEffect(() => { - setLocaleOnClient(locale, false) + setLocaleOnClient(locale, false).then(() => { + setLoading(false) + }) }, [locale]) + if (loading) + return
+ return (