Spaces:
Sleeping
Sleeping
Update src/components/PromptGroup/PromptGroupList.tsx
Browse files
src/components/PromptGroup/PromptGroupList.tsx
CHANGED
|
@@ -1,100 +1,101 @@
|
|
| 1 |
-
import React, { useState } from 'react';
|
| 2 |
-
// eslint-disable-next-line
|
| 3 |
-
import { PromptGroup } from '../../types';
|
| 4 |
-
import PromptGroupCard from './PromptGroupCard';
|
| 5 |
-
import { useApp } from '../../contexts/AppContext';
|
| 6 |
-
import CategorySelector from '../Category/CategorySelector';
|
| 7 |
-
import Input from '../common/Input';
|
| 8 |
-
|
| 9 |
-
const PromptGroupList: React.FC = () => {
|
| 10 |
-
// eslint-disable-next-line
|
| 11 |
-
const { promptGroups, categories } = useApp();
|
| 12 |
-
const [searchTerm, setSearchTerm] = useState('');
|
| 13 |
-
const [selectedCategory, setSelectedCategory] = useState<string>('');
|
| 14 |
-
|
| 15 |
-
// 搜索和过滤提示词组
|
| 16 |
-
const filteredPromptGroups = promptGroups.filter((group) => {
|
| 17 |
-
const matchesSearch =
|
| 18 |
-
group.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
| 19 |
-
group.description.toLowerCase().includes(searchTerm.toLowerCase());
|
| 20 |
-
|
| 21 |
-
const matchesCategory =
|
| 22 |
-
selectedCategory === '' || group.category === selectedCategory;
|
| 23 |
-
|
| 24 |
-
return matchesSearch && matchesCategory;
|
| 25 |
-
});
|
| 26 |
-
|
| 27 |
-
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
|
| 28 |
-
setSearchTerm(e.target.value);
|
| 29 |
-
};
|
| 30 |
-
|
| 31 |
-
const handleCategoryChange = (categoryId: string) => {
|
| 32 |
-
setSelectedCategory(categoryId);
|
| 33 |
-
};
|
| 34 |
-
|
| 35 |
-
const resetFilters = () => {
|
| 36 |
-
setSearchTerm('');
|
| 37 |
-
setSelectedCategory('');
|
| 38 |
-
};
|
| 39 |
-
|
| 40 |
-
return (
|
| 41 |
-
<div>
|
| 42 |
-
<div className="mb-4 flex flex-col sm:flex-row gap-3">
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
</
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
<
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
<
|
| 80 |
-
<
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
| 100 |
export default PromptGroupList;
|
|
|
|
| 1 |
+
import React, { useState } from 'react';
|
| 2 |
+
// eslint-disable-next-line
|
| 3 |
+
import { PromptGroup } from '../../types';
|
| 4 |
+
import PromptGroupCard from './PromptGroupCard';
|
| 5 |
+
import { useApp } from '../../contexts/AppContext';
|
| 6 |
+
import CategorySelector from '../Category/CategorySelector';
|
| 7 |
+
import Input from '../common/Input';
|
| 8 |
+
|
| 9 |
+
const PromptGroupList: React.FC = () => {
|
| 10 |
+
// eslint-disable-next-line
|
| 11 |
+
const { promptGroups, categories } = useApp();
|
| 12 |
+
const [searchTerm, setSearchTerm] = useState('');
|
| 13 |
+
const [selectedCategory, setSelectedCategory] = useState<string>('');
|
| 14 |
+
|
| 15 |
+
// 搜索和过滤提示词组
|
| 16 |
+
const filteredPromptGroups = promptGroups.filter((group) => {
|
| 17 |
+
const matchesSearch =
|
| 18 |
+
group.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
| 19 |
+
group.description.toLowerCase().includes(searchTerm.toLowerCase());
|
| 20 |
+
|
| 21 |
+
const matchesCategory =
|
| 22 |
+
selectedCategory === '' || group.category === selectedCategory;
|
| 23 |
+
|
| 24 |
+
return matchesSearch && matchesCategory;
|
| 25 |
+
});
|
| 26 |
+
|
| 27 |
+
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
|
| 28 |
+
setSearchTerm(e.target.value);
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
const handleCategoryChange = (categoryId: string) => {
|
| 32 |
+
setSelectedCategory(categoryId);
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
const resetFilters = () => {
|
| 36 |
+
setSearchTerm('');
|
| 37 |
+
setSelectedCategory('');
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
return (
|
| 41 |
+
<div>
|
| 42 |
+
<div className="mb-4 flex flex-col sm:flex-row gap-3">
|
| 43 |
+
<Input
|
| 44 |
+
placeholder="搜索提示词组..."
|
| 45 |
+
value={searchTerm}
|
| 46 |
+
onChange={handleSearch}
|
| 47 |
+
className="flex-1"
|
| 48 |
+
style={{ paddingLeft: "40px" }} /* Add explicit inline padding */
|
| 49 |
+
icon={
|
| 50 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
| 51 |
+
<circle cx="11" cy="11" r="8"></circle>
|
| 52 |
+
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
|
| 53 |
+
</svg>
|
| 54 |
+
}
|
| 55 |
+
/>
|
| 56 |
+
<div className="flex gap-2">
|
| 57 |
+
<CategorySelector
|
| 58 |
+
selectedCategory={selectedCategory}
|
| 59 |
+
onChange={handleCategoryChange}
|
| 60 |
+
/>
|
| 61 |
+
{(searchTerm || selectedCategory) && (
|
| 62 |
+
<button
|
| 63 |
+
className="ios-navbar-button"
|
| 64 |
+
onClick={resetFilters}
|
| 65 |
+
>
|
| 66 |
+
清除筛选
|
| 67 |
+
</button>
|
| 68 |
+
)}
|
| 69 |
+
</div>
|
| 70 |
+
</div>
|
| 71 |
+
|
| 72 |
+
{filteredPromptGroups.length === 0 ? (
|
| 73 |
+
<div className="ios-empty-state">
|
| 74 |
+
<div className="ios-empty-state-icon">
|
| 75 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
| 76 |
+
<circle cx="11" cy="11" r="8"></circle>
|
| 77 |
+
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
|
| 78 |
+
</svg>
|
| 79 |
+
</div>
|
| 80 |
+
<h3 className="ios-empty-state-title">未找到提示词组</h3>
|
| 81 |
+
<p className="ios-empty-state-text">
|
| 82 |
+
{searchTerm || selectedCategory
|
| 83 |
+
? '请尝试调整筛选条件'
|
| 84 |
+
: '点击底部的"新建"按钮创建您的第一个提示词组'}
|
| 85 |
+
</p>
|
| 86 |
+
</div>
|
| 87 |
+
) : (
|
| 88 |
+
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
| 89 |
+
{filteredPromptGroups.map((group) => (
|
| 90 |
+
<PromptGroupCard
|
| 91 |
+
key={group._id}
|
| 92 |
+
promptGroup={group}
|
| 93 |
+
/>
|
| 94 |
+
))}
|
| 95 |
+
</div>
|
| 96 |
+
)}
|
| 97 |
+
</div>
|
| 98 |
+
);
|
| 99 |
+
};
|
| 100 |
+
|
| 101 |
export default PromptGroupList;
|