Skip to content

Commit 6b989d2

Browse files
author
gemini2035
committed
perf: dataTotal about optimized
1 parent 1121264 commit 6b989d2

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

src/components/editor/operator/sheet/SheetOperator.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616

1717
export interface SheetOperatorProps {}
1818

19-
const paginationSize = 60
2019
// const defaultRarityFilter = Array.from(
2120
// new Array(Math.max(...OPERATORS.map(({ rarity }) => rarity)) + 1).keys(),
2221
// ).slice(Math.min(...OPERATORS.map(({ rarity }) => rarity)))
@@ -105,7 +104,7 @@ const SheetOperator: FC<SheetOperatorProps> = () => {
105104

106105
const {
107106
data: operatorsAfterFiltered,
108-
meta: { pagination: paginationAfterFiltered },
107+
meta: { dataTotal },
109108
} = useOperatorAfterFiltered(profFilter, pagination)
110109

111110
// prof listener
@@ -116,10 +115,8 @@ const SheetOperator: FC<SheetOperatorProps> = () => {
116115

117116
// pagination listener
118117
useEffect(() => {
119-
if (paginationAfterFiltered.total === pagination.total) return
120-
setPagination(paginationAfterFiltered)
121-
if (paginationAfterFiltered.current === 1) toTop()
122-
}, [pagination.total, paginationAfterFiltered])
118+
if (pagination.current === 1) toTop()
119+
}, [pagination])
123120

124121
return (
125122
<>
@@ -140,7 +137,7 @@ const SheetOperator: FC<SheetOperatorProps> = () => {
140137
</div>
141138
))}
142139
</div>
143-
<ShowMore {...{ pagination, setPagination }} />
140+
<ShowMore {...{ pagination, setPagination, dataTotal }} />
144141
</>
145142
) : (
146143
OperatorNoData

src/components/editor/operator/sheet/sheetOperator/ShowMore.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,28 @@ import { PaginationFilter } from './useOperatorFilter'
66

77
export interface ShowMoreProp {
88
pagination: PaginationFilter
9+
dataTotal: number
910
setPagination: Dispatch<SetStateAction<PaginationFilter>>
1011
}
1112

1213
export const defaultPagination: PaginationFilter = {
1314
current: 1,
1415
size: 60,
15-
total: 0,
1616
}
1717

1818
export const ShowMore: FC<ShowMoreProp> = ({
19-
pagination: { current, size, total },
19+
pagination: { current, size },
20+
dataTotal,
2021
setPagination,
2122
}) => {
2223
const lastIndex = current * size
2324

2425
return (
2526
<div className="flex items-center justify-center pt-3 cursor-default">
26-
{lastIndex >= total ? (
27+
{lastIndex >= dataTotal ? (
2728
<>
28-
<H6>已经展示全部干员了({total})</H6>
29-
{total > size && (
29+
<H6>已经展示全部干员了({dataTotal})</H6>
30+
{dataTotal > size && (
3031
<H6
3132
className="ml-1 cursor-pointer text-sm text-gray-500 hover:text-inherit hover:underline"
3233
onClick={() => setPagination(defaultPagination)}
@@ -45,7 +46,7 @@ export const ShowMore: FC<ShowMoreProp> = ({
4546
}))
4647
}
4748
>
48-
显示更多干员(剩余{total - lastIndex})
49+
显示更多干员(剩余{dataTotal - lastIndex})
4950
</H6>
5051
)}
5152
</div>

src/components/editor/operator/sheet/sheetOperator/useOperatorFilter.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export interface RarityFilter {
3131
export interface PaginationFilter {
3232
size: number
3333
current: number
34-
total: number
3534
}
3635

3736
const generateCustomizedOperInfo = (name: string): OperatorInfo => ({
@@ -53,7 +52,7 @@ export const useOperatorAfterFiltered = (
5352
const filterResult = useProfFilterHandle(profFilter)
5453
// rarity about
5554

56-
const total = filterResult.length
55+
const dataTotal = filterResult.length
5756
// pagination about
5857

5958
// filterResult
@@ -62,10 +61,7 @@ export const useOperatorAfterFiltered = (
6261
// return data after being paginated
6362
data: paginationFilterHandle(paginationFilter, filterResult),
6463
meta: {
65-
pagination: {
66-
...paginationFilter,
67-
total,
68-
},
64+
dataTotal,
6965
},
7066
}
7167
}

0 commit comments

Comments
 (0)