File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change
1
+ import { uniqBy } from 'lodash-es'
1
2
import { QueriesCopilotRequest } from 'maa-copilot-client'
2
3
import useSWR from 'swr'
3
4
import useSWRInfinite from 'swr/infinite'
@@ -22,6 +23,7 @@ export interface UseOperationsParams {
22
23
23
24
disabled ?: boolean
24
25
suspense ?: boolean
26
+ revalidateFirstPage ?: boolean
25
27
}
26
28
27
29
export function useOperations ( {
@@ -35,6 +37,7 @@ export function useOperations({
35
37
byMyself,
36
38
disabled,
37
39
suspense,
40
+ revalidateFirstPage,
38
41
} : UseOperationsParams ) {
39
42
const {
40
43
error,
@@ -98,11 +101,14 @@ export function useOperations({
98
101
requireData : true ,
99
102
} ) . queriesCopilot ( req )
100
103
101
- const parsedOperations : Operation [ ] = res . data . data . map ( ( operation ) => ( {
104
+ let parsedOperations : Operation [ ] = res . data . data . map ( ( operation ) => ( {
102
105
...operation ,
103
106
parsedContent : toCopilotOperation ( operation ) ,
104
107
} ) )
105
108
109
+ // 如果 revalidateFirstPage=false,从第二页开始可能会有重复数据,需要去重
110
+ parsedOperations = uniqBy ( parsedOperations , ( o ) => o . id )
111
+
106
112
return {
107
113
...res . data ,
108
114
data : parsedOperations ,
@@ -111,6 +117,7 @@ export function useOperations({
111
117
{
112
118
suspense,
113
119
focusThrottleInterval : 1000 * 60 * 30 ,
120
+ revalidateFirstPage,
114
121
} ,
115
122
)
116
123
Original file line number Diff line number Diff line change @@ -219,7 +219,12 @@ export const Operations: ComponentType = withSuspensable(() => {
219
219
220
220
< div className = "tabular-nums" >
221
221
{ listMode === 'operation' && (
222
- < OperationList { ...queryParams } operator = { selectedOperatorQuery } />
222
+ < OperationList
223
+ { ...queryParams }
224
+ operator = { selectedOperatorQuery }
225
+ // 按热度排序时列表前几页的变化不会太频繁,可以不刷新第一页,节省点流量
226
+ revalidateFirstPage = { queryParams . orderBy !== 'hot' }
227
+ />
223
228
) }
224
229
{ listMode === 'operationSet' && < OperationSetList { ...queryParams } /> }
225
230
</ div >
You can’t perform that action at this time.
0 commit comments