From 36a26adab2ef7a8d13fdc7b9e1cd085d7bfc3808 Mon Sep 17 00:00:00 2001 From: lyzno1 Date: Wed, 22 Oct 2025 14:59:42 +0800 Subject: [PATCH] fix: install from marketplace --- .../block-selector/featured-tools.tsx | 138 +++++++++--------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/web/app/components/workflow/block-selector/featured-tools.tsx b/web/app/components/workflow/block-selector/featured-tools.tsx index 53336f612b..ae2c6bbfd5 100644 --- a/web/app/components/workflow/block-selector/featured-tools.tsx +++ b/web/app/components/workflow/block-selector/featured-tools.tsx @@ -7,8 +7,7 @@ import type { Plugin } from '@/app/components/plugins/types' import { useGetLanguage } from '@/context/i18n' import BlockIcon from '../block-icon' import Tooltip from '@/app/components/base/tooltip' -import { RiLoader2Line, RiMoreLine } from '@remixicon/react' -import { useInstallPackageFromMarketPlace } from '@/service/use-plugins' +import { RiMoreLine } from '@remixicon/react' import Loading from '@/app/components/base/loading' import Link from 'next/link' import { getMarketplaceUrl } from '@/utils/var' @@ -18,6 +17,7 @@ import Tools from './tools' import { formatNumber } from '@/utils/format' import Action from '@/app/components/workflow/block-selector/market-place-plugin/action' import { ArrowDownDoubleLine, ArrowDownRoundFill } from '@/app/components/base/icons/src/vender/solid/arrows' +import InstallFromMarketplace from '@/app/components/plugins/install-plugin/install-from-marketplace' const MAX_RECOMMENDED_COUNT = 15 const INITIAL_VISIBLE_COUNT = 5 @@ -46,7 +46,6 @@ const FeaturedTools = ({ const { t } = useTranslation() const language = useGetLanguage() const [visibleCount, setVisibleCount] = useState(INITIAL_VISIBLE_COUNT) - const [installingIdentifier, setInstallingIdentifier] = useState(null) const [isCollapsed, setIsCollapsed] = useState(() => { if (typeof window === 'undefined') return false @@ -54,15 +53,6 @@ const FeaturedTools = ({ return stored === 'true' }) - const installMutation = useInstallPackageFromMarketPlace({ - onSuccess: async () => { - await onInstallSuccess?.() - }, - onSettled: () => { - setInstallingIdentifier(null) - }, - }) - useEffect(() => { if (typeof window === 'undefined') return @@ -100,7 +90,6 @@ const FeaturedTools = ({ ) const showMore = visibleCount < Math.min(MAX_RECOMMENDED_COUNT, plugins.length) - const isMutating = installMutation.isPending const showEmptyState = !isLoading && visiblePlugins.length === 0 return ( @@ -153,12 +142,8 @@ const FeaturedTools = ({ key={plugin.plugin_id} plugin={plugin} language={language} - installing={isMutating && installingIdentifier === plugin.latest_package_identifier} - onInstall={() => { - if (isMutating) - return - setInstallingIdentifier(plugin.latest_package_identifier) - installMutation.mutate(plugin.latest_package_identifier) + onInstallSuccess={async () => { + await onInstallSuccess?.() }} t={t} /> @@ -193,16 +178,14 @@ const FeaturedTools = ({ type FeaturedToolUninstalledItemProps = { plugin: Plugin language: string - installing: boolean - onInstall: () => void + onInstallSuccess?: () => Promise | void t: (key: string, options?: Record) => string } function FeaturedToolUninstalledItem({ plugin, language, - installing, - onInstall, + onInstallSuccess, t, }: FeaturedToolUninstalledItemProps) { const label = plugin.label?.[language] || plugin.name @@ -210,6 +193,7 @@ function FeaturedToolUninstalledItem({ const installCountLabel = t('plugin.install', { num: formatNumber(plugin.install_count || 0) }) const [actionOpen, setActionOpen] = useState(false) const [isActionHovered, setIsActionHovered] = useState(false) + const [isInstallModalOpen, setIsInstallModalOpen] = useState(false) useEffect(() => { if (!actionOpen) @@ -228,52 +212,53 @@ function FeaturedToolUninstalledItem({ }, [actionOpen]) return ( - - -
{label}
-
{description}
- - )} - disabled={!description || isActionHovered || actionOpen} - > -
{ - if (!actionOpen) - setIsActionHovered(false) - }} - > -
- -
-
{label}
+ <> + + +
{label}
+
{description}
-
-
- {installCountLabel} -
setIsActionHovered(true)} - onMouseLeave={() => { - if (!actionOpen) - setIsActionHovered(false) - }} - > - -
+ { @@ -287,8 +272,23 @@ function FeaturedToolUninstalledItem({
-
-
+ + {isInstallModalOpen && ( + { + setIsInstallModalOpen(false) + setIsActionHovered(false) + await onInstallSuccess?.() + }} + onClose={() => { + setIsInstallModalOpen(false) + setIsActionHovered(false) + }} + /> + )} + ) }