fix: reset pagination when switching operator market category filters (#205)

This commit is contained in:
Kecheng Sha
2025-12-29 15:16:33 +08:00
committed by GitHub
parent 081abf7d2f
commit e22f16166c
2 changed files with 461 additions and 451 deletions

View File

@@ -43,6 +43,8 @@ export default function useFetchData<T>(
type: [] as string[], type: [] as string[],
status: [] as string[], status: [] as string[],
tags: [] as string[], tags: [] as string[],
// 通用分类筛选(如算子市场的分类 ID 列表)
categories: [] as string[],
}, },
current: 1, current: 1,
pageSize: 12, pageSize: 12,

View File

@@ -51,6 +51,7 @@ export default function OperatorMarketPage() {
tableData, tableData,
pagination, pagination,
searchParams, searchParams,
setSearchParams,
fetchData, fetchData,
handleFiltersChange, handleFiltersChange,
handleKeywordChange, handleKeywordChange,
@@ -103,9 +104,6 @@ export default function OperatorMarketPage() {
]; ];
useEffect(() => { useEffect(() => {
if (Object.keys(selectedFilters).length === 0) {
return;
}
const filteredIds = Object.values(selectedFilters).reduce( const filteredIds = Object.values(selectedFilters).reduce(
(acc, filter: string[]) => { (acc, filter: string[]) => {
if (filter.length) { if (filter.length) {
@@ -117,8 +115,18 @@ export default function OperatorMarketPage() {
[] []
); );
fetchData({ categories: filteredIds?.length ? filteredIds : undefined }); // 分类筛选变化时:
}, [selectedFilters]); // 1. 将分类 ID 写入通用 searchParams.filter.categories,确保分页时条件不会丢失
// 2. 将页码重置为 1,避免从“全选”页的当前页跳入细分列表的同一页
setSearchParams((prev) => ({
...prev,
current: 1,
filter: {
...prev.filter,
categories: filteredIds,
},
}));
}, [selectedFilters, setSearchParams]);
return ( return (
<div className="h-full flex flex-col gap-4"> <div className="h-full flex flex-col gap-4">