fix: hide favico if systemFeatures is still pending

This commit is contained in:
NFish 2025-05-15 18:05:00 +08:00
parent 8bc1512fa1
commit 85832702f6
2 changed files with 25 additions and 3 deletions

View File

@ -9,11 +9,15 @@ import { getSystemFeatures } from '@/service/common'
import Loading from '@/app/components/base/loading'
type GlobalPublicStore = {
isPending: boolean
setIsPending: (isPending: boolean) => void
systemFeatures: SystemFeatures
setSystemFeatures: (systemFeatures: SystemFeatures) => void
}
export const useGlobalPublicStore = create<GlobalPublicStore>(set => ({
isPending: true,
setIsPending: (isPending: boolean) => set(() => ({ isPending })),
systemFeatures: defaultSystemFeatures,
setSystemFeatures: (systemFeatures: SystemFeatures) => set(() => ({ systemFeatures })),
}))
@ -25,11 +29,16 @@ const GlobalPublicStoreProvider: FC<PropsWithChildren> = ({
queryKey: ['systemFeatures'],
queryFn: getSystemFeatures,
})
const { setSystemFeatures } = useGlobalPublicStore()
const { setSystemFeatures, setIsPending } = useGlobalPublicStore()
useEffect(() => {
if (data)
setSystemFeatures({ ...defaultSystemFeatures, ...data })
}, [data, setSystemFeatures])
useEffect(() => {
setIsPending(isPending)
}, [isPending, setIsPending])
if (isPending)
return <div className='flex h-screen w-screen items-center justify-center'><Loading /></div>
return <>{children}</>

View File

@ -3,8 +3,21 @@ import { useGlobalPublicStore } from '@/context/global-public-context'
import { useFavicon, useTitle } from 'ahooks'
export default function useDocumentTitle(title: string) {
const isPending = useGlobalPublicStore(s => s.isPending)
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
const prefix = title ? `${title} - ` : ''
useTitle(systemFeatures.branding.enabled ? `${prefix}${systemFeatures.branding.application_title}` : `${prefix}Dify`)
useFavicon(systemFeatures.branding.enabled ? systemFeatures.branding.favicon : '/favicon.ico')
let titleStr = ''
let favicon = ''
if (isPending === false) {
if (systemFeatures.branding.enabled) {
titleStr = `${prefix}${systemFeatures.branding.application_title}`
favicon = systemFeatures.branding.favicon
}
else {
titleStr = `${prefix}Dify`
favicon = '/favicon.ico'
}
}
useTitle(titleStr)
useFavicon(favicon)
}