Skip to content

Commit 97fa394

Browse files
committed
🐛 修复搜索清空问题
1 parent cb38ed0 commit 97fa394

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/pages/options/routes/ScriptList/ScriptTable.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,9 @@ export const ScriptTable = ({
495495
autoFocus
496496
defaultValue={filterKeys?.[0] || { type: "auto", keyword: "" }}
497497
onChange={(req) => {
498-
setFilterKeys([{ type: req.type, keyword: req.keyword }]);
499-
SearchFilter.requestFilterResult(req);
498+
SearchFilter.requestFilterResult(req).then(() => {
499+
setFilterKeys([{ type: req.type, keyword: req.keyword }]);
500+
});
500501
}}
501502
onSearch={(req) => {
502503
if (req.bySelect) return;

src/pages/options/routes/ScriptList/SearchFilter.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ const searchFilterCache: Map<string, SearchFilterCacheEntry> = new Map();
1212

1313
export class SearchFilter {
1414
static async requestFilterResult(req: SearchFilterRequest) {
15-
if (req.keyword === lastKeyword) {
16-
lastReqType = req.type;
17-
return Promise.resolve(this);
18-
} else {
19-
const res = await requestFilterResult({ value: req.keyword });
20-
lastReqType = req.type;
15+
lastReqType = req.type;
16+
if (req.keyword !== lastKeyword) {
2117
lastKeyword = req.keyword;
2218
searchFilterCache.clear();
19+
if (req.keyword === "") {
20+
return;
21+
}
22+
const res = await requestFilterResult({ value: req.keyword });
2323
if (res && Array.isArray(res)) {
2424
for (const entry of res) {
2525
searchFilterCache.set(entry.uuid, {
@@ -29,7 +29,6 @@ export class SearchFilter {
2929
});
3030
}
3131
}
32-
return this;
3332
}
3433
}
3534

0 commit comments

Comments
 (0)