fix: model page

pull/12372/head
zxhlyh 1 year ago
parent d5cb9f0193
commit e792e91777

@ -32,8 +32,7 @@ import {
} from '@/app/components/plugins/marketplace/hooks' } from '@/app/components/plugins/marketplace/hooks'
import type { Plugin } from '@/app/components/plugins/types' import type { Plugin } from '@/app/components/plugins/types'
import { PluginType } from '@/app/components/plugins/types' import { PluginType } from '@/app/components/plugins/types'
// import { getMarketplacePluginsByCollectionId } from '@/app/components/plugins/marketplace/utils' import { getMarketplacePluginsByCollectionId } from '@/app/components/plugins/marketplace/utils'
import type { MarketplaceCollection } from '@/app/components/plugins/marketplace/types'
type UseDefaultModelAndModelList = ( type UseDefaultModelAndModelList = (
defaultModel: DefaultModelResponse | undefined, defaultModel: DefaultModelResponse | undefined,
@ -242,34 +241,11 @@ export const useUpdateModelProviders = () => {
return updateModelProviders 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) => { export const useMarketplaceAllPlugins = (providers: ModelProvider[], searchText: string) => {
const exclude = useMemo(() => { const exclude = useMemo(() => {
return providers.map(provider => provider.provider.replace(/(.+)\/([^/]+)$/, '$1')) return providers.map(provider => provider.provider.replace(/(.+)\/([^/]+)$/, '$1'))
}, [providers]) }, [providers])
const [collectionPlugins, setCollectionPlugins] = useState<Plugin[]>([])
const { const {
plugins, plugins,
@ -278,6 +254,16 @@ export const useMarketplaceAllPlugins = (providers: ModelProvider[], searchText:
isLoading, isLoading,
} = useMarketplacePlugins() } = useMarketplacePlugins()
const getCollectionPlugins = useCallback(async () => {
const collectionPlugins = await getMarketplacePluginsByCollectionId('__model-settings-pinned-models')
setCollectionPlugins(collectionPlugins)
}, [])
useEffect(() => {
getCollectionPlugins()
}, [getCollectionPlugins])
useEffect(() => { useEffect(() => {
if (searchText) { if (searchText) {
queryPluginsWithDebounced({ queryPluginsWithDebounced({
@ -298,8 +284,23 @@ export const useMarketplaceAllPlugins = (providers: ModelProvider[], searchText:
} }
}, [queryPlugins, queryPluginsWithDebounced, searchText, exclude]) }, [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 { return {
plugins: plugins?.filter(plugin => plugin.type !== 'bundle'), plugins: allPlugins,
isLoading, isLoading,
} }
} }

@ -21,7 +21,6 @@ import {
} from './declarations' } from './declarations'
import { import {
useDefaultModel, useDefaultModel,
useMarketplace,
useMarketplaceAllPlugins, useMarketplaceAllPlugins,
useUpdateModelList, useUpdateModelList,
useUpdateModelProviders, useUpdateModelProviders,
@ -121,11 +120,6 @@ const ModelProviderPage = ({ searchText }: Props) => {
const [collapse, setCollapse] = useState(false) const [collapse, setCollapse] = useState(false)
const locale = getLocaleOnClient() const locale = getLocaleOnClient()
const {
marketplaceCollections,
marketplaceCollectionPluginsMap,
isLoading: isPluginsLoading,
} = useMarketplace()
const { const {
plugins: allPlugins, plugins: allPlugins,
isLoading: isAllPluginsLoading, isLoading: isAllPluginsLoading,
@ -213,20 +207,7 @@ const ModelProviderPage = ({ searchText }: Props) => {
</Link> </Link>
</div> </div>
</div> </div>
{!collapse && (isPluginsLoading || isAllPluginsLoading) && <Loading type='area' />} {!collapse && 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}
/>
)
}
{ {
!isAllPluginsLoading && !collapse && ( !isAllPluginsLoading && !collapse && (
<List <List

@ -125,7 +125,7 @@ export const AppContextProvider: FC<AppContextProviderProps> = ({ children }) =>
setCurrentWorkspace(currentWorkspaceResponse) setCurrentWorkspace(currentWorkspaceResponse)
}, [currentWorkspaceResponse]) }, [currentWorkspaceResponse])
const [theme, setTheme] = useState<Theme>(Theme.dark) const [theme, setTheme] = useState<Theme>(Theme.light)
const handleSetTheme = useCallback((theme: Theme) => { const handleSetTheme = useCallback((theme: Theme) => {
setTheme(theme) setTheme(theme)
globalThis.document.documentElement.setAttribute('data-theme', theme) globalThis.document.documentElement.setAttribute('data-theme', theme)

Loading…
Cancel
Save