'use client' import { useEffect, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiCloseLine } from '@remixicon/react' import type { Collection } from './types' import cn from '@/utils/classnames' import { useTabSearchParams } from '@/hooks/use-tab-searchparams' import TabSliderNew from '@/app/components/base/tab-slider-new' import LabelFilter from '@/app/components/tools/labels/filter' import Input from '@/app/components/base/input' import { DotsGrid } from '@/app/components/base/icons/src/vender/line/general' import { Colors } from '@/app/components/base/icons/src/vender/line/others' import { Route } from '@/app/components/base/icons/src/vender/line/mapsAndTravel' import CustomCreateCard from '@/app/components/tools/provider/custom-create-card' import ContributeCard from '@/app/components/tools/provider/contribute' import ProviderCard from '@/app/components/tools/provider/card' import ProviderDetail from '@/app/components/tools/provider/detail' import Empty from '@/app/components/tools/add-tool-modal/empty' import { fetchCollectionList } from '@/service/tools' const ProviderList = () => { const { t } = useTranslation() const [activeTab, setActiveTab] = useTabSearchParams({ defaultTab: 'builtin', }) const options = [ { value: 'builtin', text: t('tools.type.builtIn'), icon: }, { value: 'api', text: t('tools.type.custom'), icon: }, { value: 'workflow', text: t('tools.type.workflow'), icon: }, ] const [tagFilterValue, setTagFilterValue] = useState([]) const handleTagsChange = (value: string[]) => { setTagFilterValue(value) } const [keywords, setKeywords] = useState('') const handleKeywordsChange = (value: string) => { setKeywords(value) } const [collectionList, setCollectionList] = useState([]) const filteredCollectionList = useMemo(() => { return collectionList.filter((collection) => { if (collection.type !== activeTab) return false if (tagFilterValue.length > 0 && (!collection.labels || collection.labels.every(label => !tagFilterValue.includes(label)))) return false if (keywords) return collection.name.toLowerCase().includes(keywords.toLowerCase()) return true }) }, [activeTab, tagFilterValue, keywords, collectionList]) const getProviderList = async () => { const list = await fetchCollectionList() setCollectionList([...list]) } useEffect(() => { getProviderList() }, []) const [currentProvider, setCurrentProvider] = useState() useEffect(() => { if (currentProvider && collectionList.length > 0) { const newCurrentProvider = collectionList.find(collection => collection.id === currentProvider.id) setCurrentProvider(newCurrentProvider) } }, [collectionList, currentProvider]) return ( { setActiveTab(state) if (state !== activeTab) setCurrentProvider(undefined) }} options={options} /> handleKeywordsChange(e.target.value)} onClear={() => handleKeywordsChange('')} /> {activeTab === 'builtin' && } {activeTab === 'api' && } {filteredCollectionList.map(collection => ( setCurrentProvider(collection)} key={collection.id} collection={collection} /> ))} {!filteredCollectionList.length && } {currentProvider && } setCurrentProvider(undefined)}> ) } ProviderList.displayName = 'ToolProviderList' export default ProviderList