mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 02:43:49 +08:00
refactor: streamline ListTopInfo component and enhance category handling in marketplace for improved clarity and performance
This commit is contained in:
parent
8e788714e4
commit
1f724d0f33
@ -15,7 +15,7 @@ export const SCROLL_BOTTOM_THRESHOLD = 100
|
|||||||
export const CATEGORY_ALL = 'all'
|
export const CATEGORY_ALL = 'all'
|
||||||
|
|
||||||
export const PLUGIN_TYPE_SEARCH_MAP = {
|
export const PLUGIN_TYPE_SEARCH_MAP = {
|
||||||
all: CATEGORY_ALL,
|
[CATEGORY_ALL]: CATEGORY_ALL,
|
||||||
model: PluginCategoryEnum.model,
|
model: PluginCategoryEnum.model,
|
||||||
tool: PluginCategoryEnum.tool,
|
tool: PluginCategoryEnum.tool,
|
||||||
agent: PluginCategoryEnum.agent,
|
agent: PluginCategoryEnum.agent,
|
||||||
@ -38,7 +38,7 @@ export const PLUGIN_CATEGORY_WITH_COLLECTIONS = new Set<ActivePluginType>(
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const TEMPLATE_CATEGORY_MAP = {
|
export const TEMPLATE_CATEGORY_MAP = {
|
||||||
all: CATEGORY_ALL,
|
[CATEGORY_ALL]: CATEGORY_ALL,
|
||||||
marketing: 'marketing',
|
marketing: 'marketing',
|
||||||
sales: 'sales',
|
sales: 'sales',
|
||||||
support: 'support',
|
support: 'support',
|
||||||
|
|||||||
@ -4,20 +4,18 @@ import { useTranslation } from '#i18n'
|
|||||||
import {
|
import {
|
||||||
useActivePluginCategory,
|
useActivePluginCategory,
|
||||||
useActiveTemplateCategory,
|
useActiveTemplateCategory,
|
||||||
|
useCreationType,
|
||||||
useFilterPluginTags,
|
useFilterPluginTags,
|
||||||
} from '../atoms'
|
} from '../atoms'
|
||||||
import { usePluginCategoryText, useTemplateCategoryText } from '../category-switch/category-text'
|
import { usePluginCategoryText, useTemplateCategoryText } from '../category-switch/category-text'
|
||||||
import {
|
import {
|
||||||
CATEGORY_ALL,
|
CATEGORY_ALL,
|
||||||
TEMPLATE_CATEGORY_MAP,
|
|
||||||
} from '../constants'
|
} from '../constants'
|
||||||
|
import { CREATION_TYPE } from '../search-params'
|
||||||
import SortDropdown from '../sort-dropdown'
|
import SortDropdown from '../sort-dropdown'
|
||||||
|
|
||||||
type ListTopInfoProps = {
|
const ListTopInfo = () => {
|
||||||
variant: 'plugins' | 'templates'
|
const [creationType] = useCreationType()
|
||||||
}
|
|
||||||
|
|
||||||
const ListTopInfo = ({ variant }: ListTopInfoProps) => {
|
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [filterPluginTags] = useFilterPluginTags()
|
const [filterPluginTags] = useFilterPluginTags()
|
||||||
const [activePluginCategory] = useActivePluginCategory()
|
const [activePluginCategory] = useActivePluginCategory()
|
||||||
@ -25,7 +23,9 @@ const ListTopInfo = ({ variant }: ListTopInfoProps) => {
|
|||||||
const getPluginCategoryText = usePluginCategoryText()
|
const getPluginCategoryText = usePluginCategoryText()
|
||||||
const getTemplateCategoryText = useTemplateCategoryText()
|
const getTemplateCategoryText = useTemplateCategoryText()
|
||||||
|
|
||||||
const hasTags = variant === 'plugins' && filterPluginTags.length > 0
|
const isPluginsView = creationType === CREATION_TYPE.plugins
|
||||||
|
|
||||||
|
const hasTags = isPluginsView && filterPluginTags.length > 0
|
||||||
|
|
||||||
if (hasTags) {
|
if (hasTags) {
|
||||||
return (
|
return (
|
||||||
@ -38,26 +38,20 @@ const ListTopInfo = ({ variant }: ListTopInfoProps) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const isPlugins = variant === 'plugins'
|
const isAllCategory = isPluginsView
|
||||||
const isAllCategory = isPlugins
|
|
||||||
? activePluginCategory === CATEGORY_ALL
|
? activePluginCategory === CATEGORY_ALL
|
||||||
: activeTemplateCategory === TEMPLATE_CATEGORY_MAP.all
|
: activeTemplateCategory === CATEGORY_ALL
|
||||||
|
|
||||||
const categoryText = isPlugins
|
const categoryText = isPluginsView
|
||||||
? getPluginCategoryText(activePluginCategory)
|
? getPluginCategoryText(activePluginCategory)
|
||||||
: getTemplateCategoryText(activeTemplateCategory)
|
: getTemplateCategoryText(activeTemplateCategory)
|
||||||
|
|
||||||
const title = isPlugins
|
const title = t(
|
||||||
? isAllCategory
|
`marketplace.listTopInfo.${creationType}${isAllCategory ? 'TitleAll' : 'TitleByCategory'}`,
|
||||||
? t('marketplace.listTopInfo.pluginsTitleAll', { ns: 'plugin' })
|
isAllCategory
|
||||||
: t('marketplace.listTopInfo.pluginsTitleByCategory', { ns: 'plugin', category: categoryText })
|
? { ns: 'plugin' }
|
||||||
: isAllCategory
|
: { ns: 'plugin', category: categoryText },
|
||||||
? t('marketplace.listTopInfo.templatesTitleAll', { ns: 'plugin' })
|
)
|
||||||
: t('marketplace.listTopInfo.templatesTitleByCategory', { ns: 'plugin', category: categoryText })
|
|
||||||
|
|
||||||
const subtitleKey = isPlugins
|
|
||||||
? 'marketplace.listTopInfo.pluginsSubtitle'
|
|
||||||
: 'marketplace.listTopInfo.templatesSubtitle'
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mb-4 flex items-center justify-between pt-3">
|
<div className="mb-4 flex items-center justify-between pt-3">
|
||||||
@ -66,7 +60,7 @@ const ListTopInfo = ({ variant }: ListTopInfoProps) => {
|
|||||||
{title}
|
{title}
|
||||||
</p>
|
</p>
|
||||||
<p className="system-xs-regular truncate text-text-tertiary">
|
<p className="system-xs-regular truncate text-text-tertiary">
|
||||||
{t(subtitleKey, { ns: 'plugin' })}
|
{t(`marketplace.listTopInfo.${creationType}Subtitle`, { ns: 'plugin' })}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<SortDropdown />
|
<SortDropdown />
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import Loading from '@/app/components/base/loading'
|
import Loading from '@/app/components/base/loading'
|
||||||
|
import { useMarketplaceSearchMode } from '../atoms'
|
||||||
import { isPluginsData, useMarketplaceData } from '../state'
|
import { isPluginsData, useMarketplaceData } from '../state'
|
||||||
import FlatList from './flat-list'
|
import FlatList from './flat-list'
|
||||||
import ListTopInfo from './list-top-info'
|
import ListTopInfo from './list-top-info'
|
||||||
@ -13,16 +14,14 @@ type ListWrapperProps = {
|
|||||||
const ListWrapper = ({ showInstallButton }: ListWrapperProps) => {
|
const ListWrapper = ({ showInstallButton }: ListWrapperProps) => {
|
||||||
const marketplaceData = useMarketplaceData()
|
const marketplaceData = useMarketplaceData()
|
||||||
const { isLoading, page, isFetchingNextPage } = marketplaceData
|
const { isLoading, page, isFetchingNextPage } = marketplaceData
|
||||||
|
const isSearchMode = useMarketplaceSearchMode()
|
||||||
|
|
||||||
const renderContent = () => {
|
const renderContent = () => {
|
||||||
if (isPluginsData(marketplaceData)) {
|
if (isPluginsData(marketplaceData)) {
|
||||||
const { pluginCollections, pluginCollectionPluginsMap, plugins } = marketplaceData
|
const { pluginCollections, pluginCollectionPluginsMap, plugins } = marketplaceData
|
||||||
return plugins !== undefined
|
return plugins !== undefined
|
||||||
? (
|
? (
|
||||||
<>
|
<FlatList variant="plugins" items={plugins} showInstallButton={showInstallButton} />
|
||||||
<ListTopInfo variant="plugins" />
|
|
||||||
<FlatList variant="plugins" items={plugins} showInstallButton={showInstallButton} />
|
|
||||||
</>
|
|
||||||
)
|
)
|
||||||
: (
|
: (
|
||||||
<ListWithCollection
|
<ListWithCollection
|
||||||
@ -37,10 +36,7 @@ const ListWrapper = ({ showInstallButton }: ListWrapperProps) => {
|
|||||||
const { templateCollections, templateCollectionTemplatesMap, templates } = marketplaceData
|
const { templateCollections, templateCollectionTemplatesMap, templates } = marketplaceData
|
||||||
return templates !== undefined
|
return templates !== undefined
|
||||||
? (
|
? (
|
||||||
<>
|
<FlatList variant="templates" items={templates} />
|
||||||
<ListTopInfo variant="templates" />
|
|
||||||
<FlatList variant="templates" items={templates} />
|
|
||||||
</>
|
|
||||||
)
|
)
|
||||||
: (
|
: (
|
||||||
<ListWithCollection
|
<ListWithCollection
|
||||||
@ -56,12 +52,15 @@ const ListWrapper = ({ showInstallButton }: ListWrapperProps) => {
|
|||||||
style={{ scrollbarGutter: 'stable' }}
|
style={{ scrollbarGutter: 'stable' }}
|
||||||
className="relative flex grow flex-col bg-background-default-subtle px-12 py-2"
|
className="relative flex grow flex-col bg-background-default-subtle px-12 py-2"
|
||||||
>
|
>
|
||||||
{isLoading && page === 1 && (
|
{isSearchMode && <ListTopInfo />}
|
||||||
<div className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2">
|
<div className="relative grow">
|
||||||
<Loading />
|
{isLoading && page === 1 && (
|
||||||
</div>
|
<div className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2">
|
||||||
)}
|
<Loading />
|
||||||
{(!isLoading || page > 1) && renderContent()}
|
</div>
|
||||||
|
)}
|
||||||
|
{(!isLoading || page > 1) && renderContent()}
|
||||||
|
</div>
|
||||||
{isFetchingNextPage && <Loading className="my-3" />}
|
{isFetchingNextPage && <Loading className="my-3" />}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user