import React, { useState } from 'react'; // eslint-disable-next-line import { PromptGroup } from '../../types'; import PromptGroupCard from './PromptGroupCard'; import { useApp } from '../../contexts/AppContext'; import CategorySelector from '../Category/CategorySelector'; import Input from '../common/Input'; const PromptGroupList: React.FC = () => { // eslint-disable-next-line const { promptGroups, categories } = useApp(); const [searchTerm, setSearchTerm] = useState(''); const [selectedCategory, setSelectedCategory] = useState(''); // 搜索和过滤提示词组 const filteredPromptGroups = promptGroups.filter((group) => { const matchesSearch = group.name.toLowerCase().includes(searchTerm.toLowerCase()) || (group.description?.toLowerCase() || '').includes(searchTerm.toLowerCase()); // 处理 category 可能是对象或字符串的情况 const groupCategoryId = typeof group.category === 'object' ? group.category._id : group.category; const matchesCategory = selectedCategory === '' || groupCategoryId === selectedCategory; return matchesSearch && matchesCategory; }); const handleSearch = (e: React.ChangeEvent) => { setSearchTerm(e.target.value); }; const handleCategoryChange = (categoryId: string) => { setSelectedCategory(categoryId); }; const resetFilters = () => { setSearchTerm(''); setSelectedCategory(''); }; return (
} />
{(searchTerm || selectedCategory) && ( )}
{filteredPromptGroups.length === 0 ? (

未找到提示词组

{searchTerm || selectedCategory ? '请尝试调整筛选条件' : '点击底部的"新建"按钮创建您的第一个提示词组'}

) : (
{filteredPromptGroups.map((group) => ( ))}
)}
); }; export default PromptGroupList;