Skip to content

Commit 2392521

Browse files
committed
fix: comment topping buttons showing for comment owner instead of operation owner
1 parent 740a1b9 commit 2392521

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/components/viewer/OperationViewer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export const OperationViewer: ComponentType<{
178178
<div className="flex-1" />
179179

180180
{operation.uploader === auth.username && (
181+
// FIXME: 用户名可以重名,这里会让重名用户都显示管理按钮,需要等后端支持 operation.uploaderId 后再修复
181182
<Popover2
182183
content={
183184
<ManageMenu

src/components/viewer/comment/CommentArea.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Alert, Button, Card, H4, NonIdealState, Tag } from '@blueprintjs/core'
22

3+
import { useOperation } from 'apis/query'
34
import clsx from 'clsx'
4-
import { useAtom } from 'jotai'
5+
import { useAtom, useAtomValue } from 'jotai'
56
import { find } from 'lodash-es'
67
import {
78
ReactNode,
@@ -58,6 +59,14 @@ export const CommentArea = withSuspensable(function ViewerComments({
5859
suspense: true,
5960
})
6061

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+
6170
const [replyTo, setReplyTo] = useState<CommentInfo>()
6271

6372
// clear replyTo if it's not in comments
@@ -86,6 +95,7 @@ export const CommentArea = withSuspensable(function ViewerComments({
8695
key={comment.commentId}
8796
className="mt-3"
8897
comment={comment}
98+
operationOwned={operationOwned}
8999
>
90100
{comment.subCommentsInfos.map((sub) => (
91101
<SubComment
@@ -136,10 +146,12 @@ export const CommentArea = withSuspensable(function ViewerComments({
136146
const MainComment = ({
137147
className,
138148
comment,
149+
operationOwned,
139150
children,
140151
}: {
141152
className?: string
142153
comment: MainCommentInfo
154+
operationOwned?: boolean
143155
children?: ReactNode
144156
}) => {
145157
return (
@@ -152,7 +164,7 @@ const MainComment = ({
152164
<div>
153165
<CommentHeader comment={comment} />
154166
<CommentContent comment={comment} />
155-
<CommentActions comment={comment} />
167+
<CommentActions comment={comment} operationOwned={operationOwned} />
156168
</div>
157169
{children}
158170
</Card>
@@ -240,9 +252,11 @@ const CommentContent = ({
240252
const CommentActions = ({
241253
className,
242254
comment,
255+
operationOwned,
243256
}: {
244257
className?: string
245258
comment: CommentInfo
259+
operationOwned?: boolean
246260
}) => {
247261
const [{ userId }] = useAtom(authAtom)
248262
const { replyTo, setReplyTo, reload } = useContext(CommentAreaContext)
@@ -287,7 +301,7 @@ const CommentActions = ({
287301
>
288302
回复
289303
</Button>
290-
{userId === comment.uploaderId && isMainComment(comment) && (
304+
{operationOwned && isMainComment(comment) && (
291305
<CommentTopButton comment={comment} />
292306
)}
293307
{userId === comment.uploaderId && (

0 commit comments

Comments
 (0)