mirror of https://github.com/langgenius/dify.git
fix: model page
This commit is contained in:
parent
d5cb9f0193
commit
e792e91777
|
|
@ -32,8 +32,7 @@ import {
|
|||
} from '@/app/components/plugins/marketplace/hooks'
|
||||
import type { Plugin } from '@/app/components/plugins/types'
|
||||
import { PluginType } from '@/app/components/plugins/types'
|
||||
// import { getMarketplacePluginsByCollectionId } from '@/app/components/plugins/marketplace/utils'
|
||||
import type { MarketplaceCollection } from '@/app/components/plugins/marketplace/types'
|
||||
import { getMarketplacePluginsByCollectionId } from '@/app/components/plugins/marketplace/utils'
|
||||
|
||||
type UseDefaultModelAndModelList = (
|
||||
defaultModel: DefaultModelResponse | undefined,
|
||||
|
|
@ -242,34 +241,11 @@ export const useUpdateModelProviders = () => {
|
|||
return updateModelProviders
|
||||
}
|
||||
|
||||
export const useMarketplace = () => {
|
||||
const [marketplaceCollections] = useState<MarketplaceCollection[]>([])
|
||||
const [marketplaceCollectionPluginsMap] = useState<Record<string, Plugin[]>>()
|
||||
const [isLoading] = useState(false)
|
||||
|
||||
// const getCollectionPlugins = useCallback(async () => {
|
||||
// setIsLoading(true)
|
||||
// const collectionPlugins = await getMarketplacePluginsByCollectionId('')
|
||||
// setIsLoading(false)
|
||||
|
||||
// setCollectionPlugins(collectionPlugins)
|
||||
// }, [])
|
||||
|
||||
// useEffect(() => {
|
||||
// getCollectionPlugins()
|
||||
// }, [getCollectionPlugins])
|
||||
|
||||
return {
|
||||
isLoading,
|
||||
marketplaceCollections,
|
||||
marketplaceCollectionPluginsMap,
|
||||
}
|
||||
}
|
||||
|
||||
export const useMarketplaceAllPlugins = (providers: ModelProvider[], searchText: string) => {
|
||||
const exclude = useMemo(() => {
|
||||
return providers.map(provider => provider.provider.replace(/(.+)\/([^/]+)$/, '$1'))
|
||||
}, [providers])
|
||||
const [collectionPlugins, setCollectionPlugins] = useState<Plugin[]>([])
|
||||
|
||||
const {
|
||||
plugins,
|
||||
|
|
@ -278,6 +254,16 @@ export const useMarketplaceAllPlugins = (providers: ModelProvider[], searchText:
|
|||
isLoading,
|
||||
} = useMarketplacePlugins()
|
||||
|
||||
const getCollectionPlugins = useCallback(async () => {
|
||||
const collectionPlugins = await getMarketplacePluginsByCollectionId('__model-settings-pinned-models')
|
||||
|
||||
setCollectionPlugins(collectionPlugins)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
getCollectionPlugins()
|
||||
}, [getCollectionPlugins])
|
||||
|
||||
useEffect(() => {
|
||||
if (searchText) {
|
||||
queryPluginsWithDebounced({
|
||||
|
|
@ -298,8 +284,23 @@ export const useMarketplaceAllPlugins = (providers: ModelProvider[], searchText:
|
|||
}
|
||||
}, [queryPlugins, queryPluginsWithDebounced, searchText, exclude])
|
||||
|
||||
const allPlugins = useMemo(() => {
|
||||
const allPlugins = [...collectionPlugins.filter(plugin => !exclude.includes(plugin.plugin_id))]
|
||||
|
||||
if (plugins?.length) {
|
||||
for (let i = 0; i < plugins.length; i++) {
|
||||
const plugin = plugins[i]
|
||||
|
||||
if (plugin.type !== 'bundle' && !allPlugins.find(p => p.plugin_id === plugin.plugin_id))
|
||||
allPlugins.push(plugin)
|
||||
}
|
||||
}
|
||||
|
||||
return allPlugins
|
||||
}, [plugins, collectionPlugins, exclude])
|
||||
|
||||
return {
|
||||
plugins: plugins?.filter(plugin => plugin.type !== 'bundle'),
|
||||
plugins: allPlugins,
|
||||
isLoading,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import {
|
|||
} from './declarations'
|
||||
import {
|
||||
useDefaultModel,
|
||||
useMarketplace,
|
||||
useMarketplaceAllPlugins,
|
||||
useUpdateModelList,
|
||||
useUpdateModelProviders,
|
||||
|
|
@ -121,11 +120,6 @@ const ModelProviderPage = ({ searchText }: Props) => {
|
|||
|
||||
const [collapse, setCollapse] = useState(false)
|
||||
const locale = getLocaleOnClient()
|
||||
const {
|
||||
marketplaceCollections,
|
||||
marketplaceCollectionPluginsMap,
|
||||
isLoading: isPluginsLoading,
|
||||
} = useMarketplace()
|
||||
const {
|
||||
plugins: allPlugins,
|
||||
isLoading: isAllPluginsLoading,
|
||||
|
|
@ -213,20 +207,7 @@ const ModelProviderPage = ({ searchText }: Props) => {
|
|||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
{!collapse && (isPluginsLoading || isAllPluginsLoading) && <Loading type='area' />}
|
||||
{
|
||||
!isPluginsLoading && !collapse && (
|
||||
<List
|
||||
marketplaceCollections={marketplaceCollections || []}
|
||||
marketplaceCollectionPluginsMap={marketplaceCollectionPluginsMap || {}}
|
||||
plugins={undefined}
|
||||
showInstallButton
|
||||
locale={locale}
|
||||
cardContainerClassName='grid grid-cols-2 gap-2'
|
||||
cardRender={cardRender}
|
||||
/>
|
||||
)
|
||||
}
|
||||
{!collapse && isAllPluginsLoading && <Loading type='area' />}
|
||||
{
|
||||
!isAllPluginsLoading && !collapse && (
|
||||
<List
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ export const AppContextProvider: FC<AppContextProviderProps> = ({ children }) =>
|
|||
setCurrentWorkspace(currentWorkspaceResponse)
|
||||
}, [currentWorkspaceResponse])
|
||||
|
||||
const [theme, setTheme] = useState<Theme>(Theme.dark)
|
||||
const [theme, setTheme] = useState<Theme>(Theme.light)
|
||||
const handleSetTheme = useCallback((theme: Theme) => {
|
||||
setTheme(theme)
|
||||
globalThis.document.documentElement.setAttribute('data-theme', theme)
|
||||
|
|
|
|||
Loading…
Reference in New Issue