Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor: simplify marketplace component structure by removing unused… (#29095)

zhsama31481581e8db
diff --git a/web/app/(commonLayout)/plugins/page.tsx b/web/app/(commonLayout)/plugins/page.tsx
index d07c4307ad0..ad61b16ba26 100644
--- a/web/app/(commonLayout)/plugins/page.tsx
+++ b/web/app/(commonLayout)/plugins/page.tsx
@@ -8,7 +8,7 @@ const PluginList = async () => {
return (
<PluginPage
plugins={<PluginsPanel />}
- marketplace={<Marketplace locale={locale} pluginTypeSwitchClassName='top-[60px]' searchBoxAutoAnimate={false} showSearchParams={false} />}
+ marketplace={<Marketplace locale={locale} pluginTypeSwitchClassName='top-[60px]' showSearchParams={false} />}
/>
)
}
diff --git a/web/app/components/plugins/marketplace/context.tsx b/web/app/components/plugins/marketplace/context.tsx
index fca80852711..78f452452a9 100644
--- a/web/app/components/plugins/marketplace/context.tsx
+++ b/web/app/components/plugins/marketplace/context.tsx
@@ -41,8 +41,6 @@ import { useInstalledPluginList } from '@/service/use-plugins'
import { debounce, noop } from 'lodash-es'
export type MarketplaceContextValue = {
- intersected: boolean
- setIntersected: (intersected: boolean) => void
searchPluginText: string
handleSearchPluginTextChange: (text: string) => void
filterPluginTags: string[]
@@ -67,8 +65,6 @@ export type MarketplaceContextValue = {
}
export const MarketplaceContext = createContext<MarketplaceContextValue>({
- intersected: true,
- setIntersected: noop,
searchPluginText: '',
handleSearchPluginTextChange: noop,
filterPluginTags: [],
@@ -121,7 +117,6 @@ export const MarketplaceContextProvider = ({
const hasValidTags = !!tagsFromSearchParams.length
const hasValidCategory = getValidCategoryKeys(searchParams?.category)
const categoryFromSearchParams = hasValidCategory || PLUGIN_TYPE_SEARCH_MAP.all
- const [intersected, setIntersected] = useState(true)
const [searchPluginText, setSearchPluginText] = useState(queryFromSearchParams)
const searchPluginTextRef = useRef(searchPluginText)
const [filterPluginTags, setFilterPluginTags] = useState<string[]>(tagsFromSearchParams)
@@ -300,8 +295,6 @@ export const MarketplaceContextProvider = ({
return (
<MarketplaceContext.Provider
value={{
- intersected,
- setIntersected,
searchPluginText,
handleSearchPluginTextChange,
filterPluginTags,
diff --git a/web/app/components/plugins/marketplace/hooks.ts b/web/app/components/plugins/marketplace/hooks.ts
index 49b07d7af6d..93891511e43 100644
--- a/web/app/components/plugins/marketplace/hooks.ts
+++ b/web/app/components/plugins/marketplace/hooks.ts
@@ -259,34 +259,3 @@ export const useMarketplaceContainerScroll = (
}
}, [handleScroll])
}
-
-export const useSearchBoxAutoAnimate = (searchBoxAutoAnimate?: boolean) => {
- const [searchBoxCanAnimate, setSearchBoxCanAnimate] = useState(true)
-
- const handleSearchBoxCanAnimateChange = useCallback(() => {
- if (!searchBoxAutoAnimate) {
- const clientWidth = document.documentElement.clientWidth
-
- if (clientWidth < 1400)
- setSearchBoxCanAnimate(false)
- else
- setSearchBoxCanAnimate(true)
- }
- }, [searchBoxAutoAnimate])
-
- useEffect(() => {
- handleSearchBoxCanAnimateChange()
- }, [handleSearchBoxCanAnimateChange])
-
- useEffect(() => {
- window.addEventListener('resize', handleSearchBoxCanAnimateChange)
-
- return () => {
- window.removeEventListener('resize', handleSearchBoxCanAnimateChange)
- }
- }, [handleSearchBoxCanAnimateChange])
-
- return {
- searchBoxCanAnimate,
- }
-}
diff --git a/web/app/components/plugins/marketplace/index.tsx b/web/app/components/plugins/marketplace/index.tsx
index 800c0966396..952a9db90f0 100644
--- a/web/app/components/plugins/marketplace/index.tsx
+++ b/web/app/components/plugins/marketplace/index.tsx
@@ -1,8 +1,6 @@
import { MarketplaceContextProvider } from './context'
import Description from './description'
-import IntersectionLine from './intersection-line'
-import SearchBoxWrapper from './search-box/search-box-wrapper'
-import PluginTypeSwitch from './plugin-type-switch'
+import StickySearchAndSwitchWrapper from './sticky-search-and-switch-wrapper'
import ListWrapper from './list/list-wrapper'
import type { MarketplaceCollection, SearchParams } from './types'
import type { Plugin } from '@/app/components/plugins/types'
@@ -11,23 +9,19 @@ import { TanstackQueryInitializer } from '@/context/query-client'
type MarketplaceProps = {
locale: string
- searchBoxAutoAnimate?: boolean
showInstallButton?: boolean
shouldExclude?: boolean
searchParams?: SearchParams
pluginTypeSwitchClassName?: string
- intersectionContainerId?: string
scrollContainerId?: string
showSearchParams?: boolean
}
const Marketplace = async ({
locale,
- searchBoxAutoAnimate = true,
showInstallButton = true,
shouldExclude,
searchParams,
pluginTypeSwitchClassName,
- intersectionContainerId,
scrollContainerId,
showSearchParams = true,
}: MarketplaceProps) => {
@@ -48,15 +42,9 @@ const Marketplace = async ({
showSearchParams={showSearchParams}
>
<Description locale={locale} />
- <IntersectionLine intersectionContainerId={intersectionContainerId} />
- <SearchBoxWrapper
+ <StickySearchAndSwitchWrapper
locale={locale}
- searchBoxAutoAnimate={searchBoxAutoAnimate}
- />
- <PluginTypeSwitch
- locale={locale}
- className={pluginTypeSwitchClassName}
- searchBoxAutoAnimate={searchBoxAutoAnimate}
+ pluginTypeSwitchClassName={pluginTypeSwitchClassName}
showSearchParams={showSearchParams}
/>
<ListWrapper
diff --git a/web/app/components/plugins/marketplace/intersection-line/hooks.ts b/web/app/components/plugins/marketplace/intersection-line/hooks.ts
deleted file mode 100644
index 0104cc62694..00000000000
--- a/web/app/components/plugins/marketplace/intersection-line/hooks.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-import { useEffect } from 'react'
-import { useMarketplaceContext } from '@/app/components/plugins/marketplace/context'
-
-export const useScrollIntersection = (
- anchorRef: React.RefObject<HTMLDivElement | null>,
- intersectionContainerId = 'marketplace-container',
-) => {
- const intersected = useMarketplaceContext(v => v.intersected)
- const setIntersected = useMarketplaceContext(v => v.setIntersected)
-
- useEffect(() => {
- const container = document.getElementById(intersectionContainerId)
- let observer: IntersectionObserver | undefined
- if (container && anchorRef.current) {
- observer = new IntersectionObserver((entries) => {
- const isIntersecting = entries[0].isIntersecting
-
- if (isIntersecting && !intersected)
- setIntersected(true)
-
- if (!isIntersecting && intersected)
- setIntersected(false)
- }, {
- root: container,
- })
- observer.observe(anchorRef.current)
- }
- return () => observer?.disconnect()
- }, [anchorRef, intersected, setIntersected, intersectionContainerId])
-}
diff --git a/web/app/components/plugins/marketplace/intersection-line/index.tsx b/web/app/components/plugins/marketplace/intersection-line/index.tsx
deleted file mode 100644
index c495d7f507c..00000000000
--- a/web/app/components/plugins/marketplace/intersection-line/index.tsx
+++ /dev/null
@@ -1,21 +0,0 @@
-'use client'
-
-import { useRef } from 'react'
-import { useScrollIntersection } from './hooks'
-
-type IntersectionLineProps = {
- intersectionContainerId?: string
-}
-const IntersectionLine = ({
- intersectionContainerId,
-}: IntersectionLineProps) => {
- const ref = useRef<HTMLDivElement>(null)
-
- useScrollIntersection(ref, intersectionContainerId)
-
- return (
- <div ref={ref} className='mb-4 h-px shrink-0 bg-transparent'></div>
- )
-}
-
-export default IntersectionLine
diff --git a/web/app/components/plugins/marketplace/plugin-type-switch.tsx b/web/app/components/plugins/marketplace/plugin-type-switch.tsx
index 249be1ef836..e63ecfe591a 100644
--- a/web/app/components/plugins/marketplace/plugin-type-switch.tsx
+++ b/web/app/components/plugins/marketplace/plugin-type-switch.tsx
@@ -12,10 +12,7 @@ import {
import { useCallback, useEffect } from 'react'
import { PluginCategoryEnum } from '../types'
import { useMarketplaceContext } from './context'
-import {
- useMixedTranslation,
- useSearchBoxAutoAnimate,
-} from './hooks'
+import { useMixedTranslation } from './hooks'
export const PLUGIN_TYPE_SEARCH_MAP = {
all: 'all',
@@ -30,19 +27,16 @@ export const PLUGIN_TYPE_SEARCH_MAP = {
type PluginTypeSwitchProps = {
locale?: string
className?: string
- searchBoxAutoAnimate?: boolean
showSearchParams?: boolean
}
const PluginTypeSwitch = ({
locale,
className,
- searchBoxAutoAnimate,
showSearchParams,
}: PluginTypeSwitchProps) => {
const { t } = useMixedTranslation(locale)
const activePluginType = useMarketplaceContext(s => s.activePluginType)
const handleActivePluginTypeChange = useMarketplaceContext(s => s.handleActivePluginTypeChange)
- const { searchBoxCanAnimate } = useSearchBoxAutoAnimate(searchBoxAutoAnimate)
const options = [
{
@@ -105,7 +99,6 @@ const PluginTypeSwitch = ({
return (
<div className={cn(
'flex shrink-0 items-center justify-center space-x-2 bg-background-body py-3',
- searchBoxCanAnimate && 'sticky top-[56px] z-10',
className,
)}>
{
diff --git a/web/app/components/plugins/marketplace/search-box/search-box-wrapper.tsx b/web/app/components/plugins/marketplace/search-box/search-box-wrapper.tsx
index e73a23f6ad6..cca72f657ae 100644
--- a/web/app/components/plugins/marketplace/search-box/search-box-wrapper.tsx
+++ b/web/app/components/plugins/marketplace/search-box/search-box-wrapper.tsx
@@ -1,36 +1,24 @@
'use client'
import { useMarketplaceContext } from '../context'
-import {
- useMixedTranslation,
- useSearchBoxAutoAnimate,
-} from '../hooks'
+import { useMixedTranslation } from '../hooks'
import SearchBox from './index'
-import cn from '@/utils/classnames'
type SearchBoxWrapperProps = {
locale?: string
- searchBoxAutoAnimate?: boolean
}
const SearchBoxWrapper = ({
locale,
- searchBoxAutoAnimate,
}: SearchBoxWrapperProps) => {
const { t } = useMixedTranslation(locale)
- const intersected = useMarketplaceContext(v => v.intersected)
const searchPluginText = useMarketplaceContext(v => v.searchPluginText)
const handleSearchPluginTextChange = useMarketplaceContext(v => v.handleSearchPluginTextChange)
const filterPluginTags = useMarketplaceContext(v => v.filterPluginTags)
const handleFilterPluginTagsChange = useMarketplaceContext(v => v.handleFilterPluginTagsChange)
- const { searchBoxCanAnimate } = useSearchBoxAutoAnimate(searchBoxAutoAnimate)
return (
<SearchBox
- wrapperClassName={cn(
- 'z-[0] mx-auto w-[640px] shrink-0',
- searchBoxCanAnimate && 'sticky top-3 z-[11]',
- !intersected && searchBoxCanAnimate && 'w-[508px] transition-[width] duration-300',
- )}
+ wrapperClassName='z-[11] mx-auto w-[640px] shrink-0'
inputClassName='w-full'
search={searchPluginText}
onSearchChange={handleSearchPluginTextChange}
diff --git a/web/app/components/plugins/marketplace/sticky-search-and-switch-wrapper.tsx b/web/app/components/plugins/marketplace/sticky-search-and-switch-wrapper.tsx
new file mode 100644
index 00000000000..cca8876f099
--- /dev/null
+++ b/web/app/components/plugins/marketplace/sticky-search-and-switch-wrapper.tsx
@@ -0,0 +1,37 @@
+'use client'
+
+import SearchBoxWrapper from './search-box/search-box-wrapper'
+import PluginTypeSwitch from './plugin-type-switch'
+import cn from '@/utils/classnames'
+
+type StickySearchAndSwitchWrapperProps = {
+ locale?: string
+ pluginTypeSwitchClassName?: string
+ showSearchParams?: boolean
+}
+
+const StickySearchAndSwitchWrapper = ({
+ locale,
+ pluginTypeSwitchClassName,
+ showSearchParams,
+}: StickySearchAndSwitchWrapperProps) => {
+ const hasCustomTopClass = pluginTypeSwitchClassName?.includes('top-')
+
+ return (
+ <div
+ className={cn(
+ 'mt-4 bg-background-body',
+ hasCustomTopClass && 'sticky z-10',
+ pluginTypeSwitchClassName,
+ )}
+ >
+ <SearchBoxWrapper locale={locale} />
+ <PluginTypeSwitch
+ locale={locale}
+ showSearchParams={showSearchParams}
+ />
+ </div>
+ )
+}
+
+export default StickySearchAndSwitchWrapper