From 8af8a0f46de15ad73db130c38e87fa562f008f46 Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Thu, 31 Oct 2024 15:41:02 +0800 Subject: [PATCH] fix: tool list --- .../plugins/marketplace/empty/line.tsx | 2 +- web/app/components/tools/marketplace/hooks.ts | 52 ++++++++++++++++--- .../components/tools/marketplace/index.tsx | 8 ++- web/app/components/tools/provider-list.tsx | 10 ++-- 4 files changed, 61 insertions(+), 11 deletions(-) diff --git a/web/app/components/plugins/marketplace/empty/line.tsx b/web/app/components/plugins/marketplace/empty/line.tsx index b505b7846a..19837aa862 100644 --- a/web/app/components/plugins/marketplace/empty/line.tsx +++ b/web/app/components/plugins/marketplace/empty/line.tsx @@ -9,7 +9,7 @@ const Line = ({ - + diff --git a/web/app/components/tools/marketplace/hooks.ts b/web/app/components/tools/marketplace/hooks.ts index 0486db71d2..d84e548653 100644 --- a/web/app/components/tools/marketplace/hooks.ts +++ b/web/app/components/tools/marketplace/hooks.ts @@ -3,28 +3,68 @@ import { useEffect, useState, } from 'react' +import { useDebounceFn } from 'ahooks' import type { Plugin } from '@/app/components/plugins/types' -import type { MarketplaceCollection } from '@/app/components/plugins/marketplace/types' -import { getMarketplaceCollectionsAndPlugins } from '@/app/components/plugins/marketplace/utils' +import type { + MarketplaceCollection, + PluginsSearchParams, +} from '@/app/components/plugins/marketplace/types' +import { + getMarketplaceCollectionsAndPlugins, + getMarketplacePlugins, +} from '@/app/components/plugins/marketplace/utils' -export const useMarketplace = () => { +export const useMarketplace = (searchPluginText: string, filterPluginTags: string[]) => { const [marketplaceCollections, setMarketplaceCollections] = useState([]) const [marketplaceCollectionPluginsMap, setMarketplaceCollectionPluginsMap] = useState>({}) const [isLoading, setIsLoading] = useState(true) - const getMarketplaceCollections = useCallback(async () => { + const [plugins, setPlugins] = useState() + + const handleUpldateMarketplaceCollections = useCallback(async () => { setIsLoading(true) const { marketplaceCollections, marketplaceCollectionPluginsMap } = await getMarketplaceCollectionsAndPlugins() setIsLoading(false) + setMarketplaceCollections(marketplaceCollections) setMarketplaceCollectionPluginsMap(marketplaceCollectionPluginsMap) + setPlugins(undefined) }, []) + + const handleUpdatePlugins = async (query: PluginsSearchParams) => { + setIsLoading(true) + const { marketplacePlugins } = await getMarketplacePlugins(query) + setIsLoading(false) + + setPlugins(marketplacePlugins) + } + + const { run: handleUpdatePluginsWithDebounced } = useDebounceFn(handleUpdatePlugins, { + wait: 500, + }) + useEffect(() => { - getMarketplaceCollections() - }, [getMarketplaceCollections]) + if (searchPluginText || filterPluginTags.length) { + if (searchPluginText) { + handleUpdatePluginsWithDebounced({ + query: searchPluginText, + tags: filterPluginTags, + }) + return + } + handleUpdatePlugins({ + query: searchPluginText, + tags: filterPluginTags, + }) + } + else { + handleUpldateMarketplaceCollections() + } + }, [searchPluginText, filterPluginTags, handleUpdatePluginsWithDebounced, handleUpldateMarketplaceCollections]) return { isLoading, marketplaceCollections, marketplaceCollectionPluginsMap, + plugins, } } diff --git a/web/app/components/tools/marketplace/index.tsx b/web/app/components/tools/marketplace/index.tsx index 64ec83f460..2bb935db14 100644 --- a/web/app/components/tools/marketplace/index.tsx +++ b/web/app/components/tools/marketplace/index.tsx @@ -4,16 +4,21 @@ import List from '@/app/components/plugins/marketplace/list' import Loading from '@/app/components/base/loading' type MarketplaceProps = { + searchPluginText: string + filterPluginTags: string[] onMarketplaceScroll: () => void } const Marketplace = ({ + searchPluginText, + filterPluginTags, onMarketplaceScroll, }: MarketplaceProps) => { const { isLoading, marketplaceCollections, marketplaceCollectionPluginsMap, - } = useMarketplace() + plugins, + } = useMarketplace(searchPluginText, filterPluginTags) return (
@@ -55,6 +60,7 @@ const Marketplace = ({ ) diff --git a/web/app/components/tools/provider-list.tsx b/web/app/components/tools/provider-list.tsx index 24baf9f0e1..acec3dad7e 100644 --- a/web/app/components/tools/provider-list.tsx +++ b/web/app/components/tools/provider-list.tsx @@ -126,9 +126,13 @@ const ProviderList = () => {
{ enable_marketplace && ( - { - containerRef.current?.scrollTo({ top: containerRef.current.scrollHeight, behavior: 'smooth' }) - }} /> + { + containerRef.current?.scrollTo({ top: containerRef.current.scrollHeight, behavior: 'smooth' }) + }} + searchPluginText={keywords} + filterPluginTags={tagFilterValue} + /> ) }