From b91c417d02ce6b5520f59b1b6333550f1e6123a3 Mon Sep 17 00:00:00 2001 From: zhsama Date: Tue, 2 Dec 2025 18:57:19 +0800 Subject: [PATCH] refactor: centralize scroll bottom threshold constant in marketplace components --- web/app/components/plugins/marketplace/constants.ts | 2 ++ web/app/components/plugins/marketplace/hooks.ts | 3 +-- web/app/components/plugins/marketplace/index.tsx | 7 ++++--- web/app/components/tools/marketplace/hooks.ts | 3 +-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/web/app/components/plugins/marketplace/constants.ts b/web/app/components/plugins/marketplace/constants.ts index 6bd4e29604..92c3e7278f 100644 --- a/web/app/components/plugins/marketplace/constants.ts +++ b/web/app/components/plugins/marketplace/constants.ts @@ -2,3 +2,5 @@ export const DEFAULT_SORT = { sortBy: 'install_count', sortOrder: 'DESC', } + +export const SCROLL_BOTTOM_THRESHOLD = 100 diff --git a/web/app/components/plugins/marketplace/hooks.ts b/web/app/components/plugins/marketplace/hooks.ts index e1e5d34e2b..49b07d7af6 100644 --- a/web/app/components/plugins/marketplace/hooks.ts +++ b/web/app/components/plugins/marketplace/hooks.ts @@ -23,12 +23,11 @@ import { getMarketplaceCollectionsAndPlugins, getMarketplacePluginsByCollectionId, } from './utils' +import { SCROLL_BOTTOM_THRESHOLD } from './constants' import i18n from '@/i18n-config/i18next-config' import { postMarketplace } from '@/service/base' import type { PluginsFromMarketplaceResponse } from '@/app/components/plugins/types' -const SCROLL_BOTTOM_THRESHOLD = 100 - export const useMarketplaceCollectionsAndPlugins = () => { const [queryParams, setQueryParams] = useState() const [marketplaceCollectionsOverride, setMarketplaceCollections] = useState() diff --git a/web/app/components/plugins/marketplace/index.tsx b/web/app/components/plugins/marketplace/index.tsx index d6189a92a1..800c096639 100644 --- a/web/app/components/plugins/marketplace/index.tsx +++ b/web/app/components/plugins/marketplace/index.tsx @@ -4,7 +4,8 @@ import IntersectionLine from './intersection-line' import SearchBoxWrapper from './search-box/search-box-wrapper' import PluginTypeSwitch from './plugin-type-switch' import ListWrapper from './list/list-wrapper' -import type { SearchParams } from './types' +import type { MarketplaceCollection, SearchParams } from './types' +import type { Plugin } from '@/app/components/plugins/types' import { getMarketplaceCollectionsAndPlugins } from './utils' import { TanstackQueryInitializer } from '@/context/query-client' @@ -30,8 +31,8 @@ const Marketplace = async ({ scrollContainerId, showSearchParams = true, }: MarketplaceProps) => { - let marketplaceCollections: any = [] - let marketplaceCollectionPluginsMap = {} + let marketplaceCollections: MarketplaceCollection[] = [] + let marketplaceCollectionPluginsMap: Record = {} if (!shouldExclude) { const marketplaceCollectionsAndPluginsData = await getMarketplaceCollectionsAndPlugins() marketplaceCollections = marketplaceCollectionsAndPluginsData.marketplaceCollections diff --git a/web/app/components/tools/marketplace/hooks.ts b/web/app/components/tools/marketplace/hooks.ts index 54f8b845bd..904eeb95a8 100644 --- a/web/app/components/tools/marketplace/hooks.ts +++ b/web/app/components/tools/marketplace/hooks.ts @@ -8,12 +8,11 @@ import { useMarketplaceCollectionsAndPlugins, useMarketplacePlugins, } from '@/app/components/plugins/marketplace/hooks' +import { SCROLL_BOTTOM_THRESHOLD } from '@/app/components/plugins/marketplace/constants' import { PluginCategoryEnum } from '@/app/components/plugins/types' import { getMarketplaceListCondition } from '@/app/components/plugins/marketplace/utils' import { useAllToolProviders } from '@/service/use-tools' -const SCROLL_BOTTOM_THRESHOLD = 100 - export const useMarketplace = (searchPluginText: string, filterPluginTags: string[]) => { const { data: toolProvidersData, isSuccess } = useAllToolProviders() const exclude = useMemo(() => {