1
1
import { Alert , Button , Card , H4 , NonIdealState , Tag } from '@blueprintjs/core'
2
2
3
+ import { useOperation } from 'apis/query'
3
4
import clsx from 'clsx'
4
- import { useAtom } from 'jotai'
5
+ import { useAtom , useAtomValue } from 'jotai'
5
6
import { find } from 'lodash-es'
6
7
import {
7
8
ReactNode ,
@@ -58,6 +59,14 @@ export const CommentArea = withSuspensable(function ViewerComments({
58
59
suspense : true ,
59
60
} )
60
61
62
+ const auth = useAtomValue ( authAtom )
63
+ const operation = useOperation ( { id : operationId } ) . data ?. data
64
+ // FIXME: 用户名可以重名,这里会让重名用户都显示置顶按钮,需要等后端支持 operation.uploaderId 后再修复
65
+ const operationOwned =
66
+ ! ! operation ?. uploader &&
67
+ ! ! auth . username &&
68
+ operation . uploader === auth . username
69
+
61
70
const [ replyTo , setReplyTo ] = useState < CommentInfo > ( )
62
71
63
72
// clear replyTo if it's not in comments
@@ -86,6 +95,7 @@ export const CommentArea = withSuspensable(function ViewerComments({
86
95
key = { comment . commentId }
87
96
className = "mt-3"
88
97
comment = { comment }
98
+ operationOwned = { operationOwned }
89
99
>
90
100
{ comment . subCommentsInfos . map ( ( sub ) => (
91
101
< SubComment
@@ -136,10 +146,12 @@ export const CommentArea = withSuspensable(function ViewerComments({
136
146
const MainComment = ( {
137
147
className,
138
148
comment,
149
+ operationOwned,
139
150
children,
140
151
} : {
141
152
className ?: string
142
153
comment : MainCommentInfo
154
+ operationOwned ?: boolean
143
155
children ?: ReactNode
144
156
} ) => {
145
157
return (
@@ -152,7 +164,7 @@ const MainComment = ({
152
164
< div >
153
165
< CommentHeader comment = { comment } />
154
166
< CommentContent comment = { comment } />
155
- < CommentActions comment = { comment } />
167
+ < CommentActions comment = { comment } operationOwned = { operationOwned } />
156
168
</ div >
157
169
{ children }
158
170
</ Card >
@@ -240,9 +252,11 @@ const CommentContent = ({
240
252
const CommentActions = ( {
241
253
className,
242
254
comment,
255
+ operationOwned,
243
256
} : {
244
257
className ?: string
245
258
comment : CommentInfo
259
+ operationOwned ?: boolean
246
260
} ) => {
247
261
const [ { userId } ] = useAtom ( authAtom )
248
262
const { replyTo, setReplyTo, reload } = useContext ( CommentAreaContext )
@@ -287,7 +301,7 @@ const CommentActions = ({
287
301
>
288
302
回复
289
303
</ Button >
290
- { userId === comment . uploaderId && isMainComment ( comment ) && (
304
+ { operationOwned && isMainComment ( comment ) && (
291
305
< CommentTopButton comment = { comment } />
292
306
) }
293
307
{ userId === comment . uploaderId && (
0 commit comments