1
1
import { uniqBy } from 'lodash-es'
2
- import { QueriesCopilotRequest } from 'maa-copilot-client'
2
+ import {
3
+ BanCommentsStatusEnum ,
4
+ CopilotInfoStatusEnum ,
5
+ QueriesCopilotRequest ,
6
+ } from 'maa-copilot-client'
3
7
import useSWR from 'swr'
4
8
import useSWRInfinite from 'swr/infinite'
5
9
@@ -11,13 +15,18 @@ import { useSWRRefresh } from 'utils/swr'
11
15
12
16
export type OrderBy = 'views' | 'hot' | 'id'
13
17
18
+ export interface OperatorFilterParams {
19
+ included : string [ ]
20
+ excluded : string [ ]
21
+ }
22
+
14
23
export interface UseOperationsParams {
15
24
limit ?: number
16
25
orderBy ?: OrderBy
17
26
descending ?: boolean
18
27
keyword ?: string
19
28
levelKeyword ?: string
20
- operator ?: string
29
+ operator ?: OperatorFilterParams
21
30
operationIds ?: number [ ]
22
31
uploaderId ?: string
23
32
@@ -80,7 +89,12 @@ export function useOperations({
80
89
page : pageIndex + 1 ,
81
90
document : keyword ,
82
91
levelKeyword,
83
- operator,
92
+ operator : operator
93
+ ? [
94
+ ...operator . included ,
95
+ ...operator . excluded . map ( ( o ) => `~${ o } ` ) ,
96
+ ] . join ( ',' ) || undefined
97
+ : undefined ,
84
98
orderBy,
85
99
desc : descending ,
86
100
copilotIds : operationIds ,
@@ -178,16 +192,29 @@ export async function getOperation(req: { id: number }): Promise<Operation> {
178
192
}
179
193
}
180
194
181
- export async function createOperation ( req : { content : string } ) {
195
+ export async function createOperation ( req : {
196
+ content : string
197
+ status : CopilotInfoStatusEnum
198
+ } ) {
182
199
await new OperationApi ( ) . uploadCopilot ( { copilotCUDRequest : req } )
183
200
}
184
201
185
- export async function updateOperation ( req : { id : number ; content : string } ) {
202
+ export async function updateOperation ( req : {
203
+ id : number
204
+ content : string
205
+ status : CopilotInfoStatusEnum
206
+ } ) {
186
207
await new OperationApi ( ) . updateCopilot ( { copilotCUDRequest : req } )
187
208
}
188
209
189
210
export async function deleteOperation ( req : { id : number } ) {
190
- await new OperationApi ( ) . deleteCopilot ( { copilotCUDRequest : req } )
211
+ await new OperationApi ( ) . deleteCopilot ( {
212
+ copilotCUDRequest : {
213
+ content : '' ,
214
+ status : CopilotInfoStatusEnum . Public ,
215
+ ...req ,
216
+ } ,
217
+ } )
191
218
}
192
219
193
220
export async function rateOperation ( req : { id : number ; rating : OpRatingType } ) {
@@ -204,3 +231,13 @@ export async function rateOperation(req: { id: number; rating: OpRatingType }) {
204
231
} ,
205
232
} )
206
233
}
234
+
235
+ export async function banComments ( req : {
236
+ operationId : number
237
+ status : BanCommentsStatusEnum
238
+ } ) {
239
+ await new OperationApi ( ) . banComments ( {
240
+ copilotId : req . operationId ,
241
+ ...req ,
242
+ } )
243
+ }
0 commit comments