fix: show loading icon when fetching system features

This commit is contained in:
NFish 2025-03-15 11:59:58 +08:00
parent e0232c67cc
commit 7da45ba589

View File

@ -6,6 +6,7 @@ import { useEffect } from 'react'
import type { SystemFeatures } from '@/types/feature' import type { SystemFeatures } from '@/types/feature'
import { defaultSystemFeatures } from '@/types/feature' import { defaultSystemFeatures } from '@/types/feature'
import { getSystemFeatures } from '@/service/common' import { getSystemFeatures } from '@/service/common'
import Loading from '@/app/components/base/loading'
type GlobalPublicStore = { type GlobalPublicStore = {
systemFeatures: SystemFeatures systemFeatures: SystemFeatures
@ -20,7 +21,7 @@ export const useGlobalPublicStore = create<GlobalPublicStore>(set => ({
const GlobalPublicStoreProvider: FC<PropsWithChildren> = ({ const GlobalPublicStoreProvider: FC<PropsWithChildren> = ({
children, children,
}) => { }) => {
const { data } = useQuery({ const { isPending, data } = useQuery({
queryKey: ['systemFeatures'], queryKey: ['systemFeatures'],
queryFn: getSystemFeatures, queryFn: getSystemFeatures,
}) })
@ -29,6 +30,8 @@ const GlobalPublicStoreProvider: FC<PropsWithChildren> = ({
if (data) if (data)
setSystemFeatures({ ...defaultSystemFeatures, ...data }) setSystemFeatures({ ...defaultSystemFeatures, ...data })
}, [data, setSystemFeatures]) }, [data, setSystemFeatures])
if (isPending)
return <div className='w-screen h-screen flex items-center justify-center'><Loading /></div>
return <>{children}</> return <>{children}</>
} }
export default GlobalPublicStoreProvider export default GlobalPublicStoreProvider