samlax12 commited on
Commit
8f4172c
·
verified ·
1 Parent(s): 66c1245

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
- <Input
44
- placeholder="搜索提示词组..."
45
- value={searchTerm}
46
- onChange={handleSearch}
47
- className="flex-1"
48
- icon={
49
- <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">
50
- <circle cx="11" cy="11" r="8"></circle>
51
- <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
52
- </svg>
53
- }
54
- />
55
- <div className="flex gap-2">
56
- <CategorySelector
57
- selectedCategory={selectedCategory}
58
- onChange={handleCategoryChange}
59
- />
60
- {(searchTerm || selectedCategory) && (
61
- <button
62
- className="ios-navbar-button"
63
- onClick={resetFilters}
64
- >
65
- 清除筛选
66
- </button>
67
- )}
68
- </div>
69
- </div>
70
-
71
- {filteredPromptGroups.length === 0 ? (
72
- <div className="ios-empty-state">
73
- <div className="ios-empty-state-icon">
74
- <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">
75
- <circle cx="11" cy="11" r="8"></circle>
76
- <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
77
- </svg>
78
- </div>
79
- <h3 className="ios-empty-state-title">未找到提示词组</h3>
80
- <p className="ios-empty-state-text">
81
- {searchTerm || selectedCategory
82
- ? '请尝试调整筛选条件'
83
- : '点击底部的"新建"按钮创建您的第一个提示词组'}
84
- </p>
85
- </div>
86
- ) : (
87
- <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
88
- {filteredPromptGroups.map((group) => (
89
- <PromptGroupCard
90
- key={group._id}
91
- promptGroup={group}
92
- />
93
- ))}
94
- </div>
95
- )}
96
- </div>
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;