dify/web/app/components/plugins/marketplace/search-params.ts
Coding On Star cb6c04637b
feat(web): add marketplace creator profiles and homepage redesign (#41538)
Co-authored-by: zxhlyh <jasonapring2015@outlook.com>
Co-authored-by: fatelei <fatelei@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: CodingOnStar <hanxujiang@dify.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: 姜涵煦 <hanxujiang@jianghanxudeMacBook-Pro-2.local>
Co-authored-by: L1nSn0w <l1nsn0w@qq.com>
Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
2026-09-04 08:09:45 +00:00

39 lines
1.6 KiB
TypeScript

import type { PluginsSearchParams, PluginsSort } from '@dify/contracts/marketplace'
import type { inferParserType } from 'nuqs/server'
import type { ActivePluginType } from './constants'
import { parseAsArrayOf, parseAsString, parseAsStringEnum } from 'nuqs/server'
import { DEFAULT_SORT, PLUGIN_CATEGORY_WITH_COLLECTIONS, PLUGIN_TYPE_SEARCH_MAP } from './constants'
import { getMarketplaceListFilterType } from './utils'
export const marketplaceSearchParamsParsers = {
category: parseAsStringEnum<ActivePluginType>(
Object.values(PLUGIN_TYPE_SEARCH_MAP) as ActivePluginType[],
)
.withDefault('all')
.withOptions({ history: 'replace', clearOnDefault: false, scroll: false }),
q: parseAsString.withDefault('').withOptions({ history: 'replace', scroll: false }),
tags: parseAsArrayOf(parseAsString).withDefault([]).withOptions({ history: 'replace' }),
languages: parseAsArrayOf(parseAsString).withDefault([]).withOptions({ history: 'replace' }),
}
export type MarketplaceSearchParams = inferParserType<typeof marketplaceSearchParamsParsers>
export const shouldSearchMarketplacePlugins = ({
category,
q,
tags,
}: Pick<MarketplaceSearchParams, 'category' | 'q' | 'tags'>) =>
Boolean(q || tags.length > 0 || !PLUGIN_CATEGORY_WITH_COLLECTIONS.has(category))
export const getMarketplacePluginsSearchParams = (
{ category, q, tags }: Pick<MarketplaceSearchParams, 'category' | 'q' | 'tags'>,
sort: PluginsSort = DEFAULT_SORT,
): PluginsSearchParams => ({
query: q,
category: category === PLUGIN_TYPE_SEARCH_MAP.all ? undefined : category,
tags,
sort_by: sort.sortBy,
sort_order: sort.sortOrder,
type: getMarketplaceListFilterType(category),
})