fix: fetch installed plugin instead of all plugins

This commit is contained in:
Joel 2025-06-27 19:35:18 +08:00
parent 07c99745fa
commit 0af646d947
2 changed files with 20 additions and 15 deletions

View File

@ -1,7 +1,7 @@
'use client' 'use client'
import type { FC } from 'react' import type { FC } from 'react'
import React from 'react' import React from 'react'
import type { Plugin } from '@/app/components/plugins/types' import type { PluginDetail } from '@/app/components/plugins/types'
import Icon from '@/app/components/plugins/card/base/card-icon' import Icon from '@/app/components/plugins/card/base/card-icon'
import { renderI18nObject } from '@/i18n' import { renderI18nObject } from '@/i18n'
import { useGetLanguage } from '@/context/i18n' import { useGetLanguage } from '@/context/i18n'
@ -9,7 +9,7 @@ import { MARKETPLACE_API_PREFIX } from '@/config'
import Checkbox from '@/app/components/base/checkbox' import Checkbox from '@/app/components/base/checkbox'
type Props = { type Props = {
payload: Plugin payload: PluginDetail
isChecked?: boolean isChecked?: boolean
onCheckChange: () => void onCheckChange: () => void
} }
@ -21,7 +21,8 @@ const ToolItem: FC<Props> = ({
}) => { }) => {
const language = useGetLanguage() const language = useGetLanguage()
const { plugin_id, label, org } = payload const { plugin_id, declaration } = payload
const { label, author: org } = declaration
return ( return (
<div className='p-1'> <div className='p-1'>
<div <div

View File

@ -1,12 +1,12 @@
'use client' 'use client'
import type { FC } from 'react' import type { FC } from 'react'
import React, { useCallback, useState } from 'react' import React, { useCallback, useMemo, useState } from 'react'
import { import {
PortalToFollowElem, PortalToFollowElem,
PortalToFollowElemContent, PortalToFollowElemContent,
PortalToFollowElemTrigger, PortalToFollowElemTrigger,
} from '@/app/components/base/portal-to-follow-elem' } from '@/app/components/base/portal-to-follow-elem'
import { useFetchPluginListOrBundleList } from '@/service/use-plugins' import { useInstalledPluginList } from '@/service/use-plugins'
import { PLUGIN_TYPE_SEARCH_MAP } from '../../marketplace/plugin-type-switch' import { PLUGIN_TYPE_SEARCH_MAP } from '../../marketplace/plugin-type-switch'
import SearchBox from '@/app/components/plugins/marketplace/search-box' import SearchBox from '@/app/components/plugins/marketplace/search-box'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
@ -66,13 +66,17 @@ const ToolPicker: FC<Props> = ({
const [pluginType, setPluginType] = useState(PLUGIN_TYPE_SEARCH_MAP.all) const [pluginType, setPluginType] = useState(PLUGIN_TYPE_SEARCH_MAP.all)
const [query, setQuery] = useState('') const [query, setQuery] = useState('')
const [tags, setTags] = useState<string[]>([]) const [tags, setTags] = useState<string[]>([])
const { data, isLoading } = useFetchPluginListOrBundleList({ const { data, isLoading } = useInstalledPluginList()
query, const filteredList = useMemo(() => {
tags, const list = data ? data.plugins : []
category: pluginType, return list.filter((plugin) => {
}) return (
const isBundle = pluginType === PLUGIN_TYPE_SEARCH_MAP.bundle (pluginType === PLUGIN_TYPE_SEARCH_MAP.all || plugin.declaration.category === pluginType)
const list = (isBundle ? data?.data?.bundles : data?.data?.plugins) || [] && (tags.length === 0 || tags.some(tag => plugin.declaration.tags.includes(tag)))
&& (query === '' || plugin.plugin_id.toLowerCase().includes(query.toLowerCase()))
)
})
}, [data, pluginType, query, tags])
const handleCheckChange = useCallback((pluginId: string) => { const handleCheckChange = useCallback((pluginId: string) => {
return () => { return () => {
const newValue = value.includes(pluginId) const newValue = value.includes(pluginId)
@ -84,7 +88,7 @@ const ToolPicker: FC<Props> = ({
const listContent = ( const listContent = (
<div className='max-h-[396px] overflow-y-auto'> <div className='max-h-[396px] overflow-y-auto'>
{list.map(item => ( {filteredList.map(item => (
<ToolItem <ToolItem
key={item.plugin_id} key={item.plugin_id}
payload={item} payload={item}
@ -149,8 +153,8 @@ const ToolPicker: FC<Props> = ({
} }
</div> </div>
</div> </div>
{!isLoading && list.length > 0 && listContent} {!isLoading && filteredList.length > 0 && listContent}
{!isLoading && list.length === 0 && noData} {!isLoading && filteredList.length === 0 && noData}
{isLoading && loadingContent} {isLoading && loadingContent}
</div> </div>
</PortalToFollowElemContent> </PortalToFollowElemContent>