File tree Expand file tree Collapse file tree 4 files changed +26
-20
lines changed Expand file tree Collapse file tree 4 files changed +26
-20
lines changed Original file line number Diff line number Diff line change 1
- import { useAtomValue } from 'jotai'
2
1
import { noop } from 'lodash-es'
3
2
import {
4
3
CopilotSetPageRes ,
9
8
import useSWR from 'swr'
10
9
import useSWRInfinite from 'swr/infinite'
11
10
12
- import { authAtom } from 'store/auth'
13
11
import { OperationSetApi } from 'utils/maa-copilot-client'
14
12
import { useSWRRefresh } from 'utils/swr'
15
13
@@ -19,20 +17,18 @@ export type OrderBy = 'views' | 'hot' | 'id'
19
17
20
18
export interface UseOperationSetsParams {
21
19
keyword ?: string
22
- byMyself ?: boolean
20
+ creatorId ?: string
23
21
24
22
disabled ?: boolean
25
23
suspense ?: boolean
26
24
}
27
25
28
26
export function useOperationSets ( {
29
27
keyword,
30
- byMyself ,
28
+ creatorId ,
31
29
disabled,
32
30
suspense,
33
31
} : UseOperationSetsParams ) {
34
- const { userId } = useAtomValue ( authAtom )
35
-
36
32
const {
37
33
data : pages ,
38
34
error,
@@ -53,14 +49,13 @@ export function useOperationSets({
53
49
limit : 50 ,
54
50
page : pageIndex + 1 ,
55
51
keyword,
56
- creatorId : byMyself ? userId : undefined ,
52
+ creatorId,
57
53
} satisfies CopilotSetQuery ,
58
- byMyself ,
59
54
]
60
55
} ,
61
- async ( [ , req , byMyself ] ) => {
56
+ async ( [ , req ] ) => {
62
57
const res = await new OperationSetApi ( {
63
- sendToken : byMyself ? 'always' : ' optional', // 如果有 token 会用来获取自己的作业集
58
+ sendToken : ' optional', // 如果有 token 即可获取到私有的作业集
64
59
requireData : true ,
65
60
} ) . querySets ( { copilotSetQuery : req } )
66
61
return res . data
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ export interface UseOperationsParams {
19
19
levelKeyword ?: string
20
20
operator ?: string
21
21
operationIds ?: number [ ]
22
- byMyself ?: boolean
22
+ uploaderId ?: string
23
23
24
24
disabled ?: boolean
25
25
suspense ?: boolean
@@ -34,7 +34,7 @@ export function useOperations({
34
34
levelKeyword,
35
35
operator,
36
36
operationIds,
37
- byMyself ,
37
+ uploaderId ,
38
38
disabled,
39
39
suspense,
40
40
revalidateFirstPage,
@@ -84,7 +84,7 @@ export function useOperations({
84
84
orderBy,
85
85
desc : descending ,
86
86
copilotIds : operationIds ,
87
- uploaderId : byMyself ? 'me' : undefined ,
87
+ uploaderId,
88
88
} satisfies QueriesCopilotRequest ,
89
89
]
90
90
} ,
@@ -96,8 +96,7 @@ export function useOperations({
96
96
}
97
97
98
98
const res = await new OperationApi ( {
99
- sendToken :
100
- 'uploaderId' in req && req . uploaderId === 'me' ? 'always' : 'never' ,
99
+ sendToken : 'optional' ,
101
100
requireData : true ,
102
101
} ) . queriesCopilot ( req )
103
102
Original file line number Diff line number Diff line change @@ -65,11 +65,11 @@ export const Operations: ComponentType = withSuspensable(() => {
65
65
className = ""
66
66
icon = "user"
67
67
title = "只显示我发布的作品"
68
- active = { queryParams . byMyself }
68
+ active = { ! ! queryParams . uploaderId }
69
69
onClick = { ( ) => {
70
70
setQueryParams ( ( old ) => ( {
71
71
...old ,
72
- byMyself : ! old . byMyself ,
72
+ uploaderId : old . uploaderId ? undefined : authState . userId ,
73
73
} ) )
74
74
} }
75
75
>
@@ -209,7 +209,12 @@ export const Operations: ComponentType = withSuspensable(() => {
209
209
revalidateFirstPage = { queryParams . orderBy !== 'hot' }
210
210
/>
211
211
) }
212
- { listMode === 'operationSet' && < OperationSetList { ...queryParams } /> }
212
+ { listMode === 'operationSet' && (
213
+ < OperationSetList
214
+ { ...queryParams }
215
+ creatorId = { queryParams . uploaderId }
216
+ />
217
+ ) }
213
218
</ div >
214
219
</ >
215
220
)
Original file line number Diff line number Diff line change @@ -14,13 +14,16 @@ import {
14
14
useOperationSets ,
15
15
} from 'apis/operation-set'
16
16
import clsx from 'clsx'
17
+ import { useAtomValue } from 'jotai'
17
18
import { useState } from 'react'
18
19
19
20
import { AppToaster } from 'components/Toaster'
20
21
import { OperationSetEditorDialog } from 'components/operation-set/OperationSetEditor'
21
22
import { formatError } from 'utils/error'
22
23
import { useNetworkState } from 'utils/useNetworkState'
23
24
25
+ import { authAtom } from '../../store/auth'
26
+
24
27
interface AddToOperationSetButtonProps extends ButtonProps {
25
28
operationId : number
26
29
}
@@ -60,14 +63,17 @@ export function AddToOperationSet({
60
63
operationId,
61
64
onSuccess,
62
65
} : AddToOperationSetProps ) {
66
+ const auth = useAtomValue ( authAtom )
67
+
63
68
const {
64
69
operationSets,
65
70
isReachingEnd,
66
71
isValidating,
67
72
setSize,
68
73
error : listError ,
69
74
} = useOperationSets ( {
70
- byMyself : true ,
75
+ disabled : ! auth . userId ,
76
+ creatorId : auth . userId ,
71
77
} )
72
78
73
79
const {
@@ -82,7 +88,8 @@ export function AddToOperationSet({
82
88
{ } as Record < number , boolean > ,
83
89
)
84
90
85
- const error = submitError || listError
91
+ const error =
92
+ submitError || listError || ( ! auth . userId ? '未登录' : undefined )
86
93
87
94
const operationSetList = onlyShowAdded
88
95
? operationSets ?. filter (
You can’t perform that action at this time.
0 commit comments