Skip to content

Commit b285b61

Browse files
authored
Merge pull request #338 from dragove/dev
feat: 添加支持作者评论字数上限为500
2 parents 7deab45 + bd573d6 commit b285b61

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

src/components/viewer/comment/CommentArea.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
useComments,
2121
} from '../../../apis/comment'
2222
import {
23+
MAX_COMMENT_LENGTH,
24+
AUTHOR_MAX_COMMENT_LENGTH,
2325
CommentInfo,
2426
CommentRating,
2527
MainCommentInfo,
@@ -62,11 +64,10 @@ export const CommentArea = withSuspensable(function ViewerComments({
6264

6365
const auth = useAtomValue(authAtom)
6466
const operation = useOperation({ id: operationId }).data
65-
// FIXME: 用户名可以重名,这里会让重名用户都显示置顶按钮,需要等后端支持 operation.uploaderId 后再修复
66-
const operationOwned =
67-
!!operation?.uploader &&
68-
!!auth.username &&
69-
operation.uploader === auth.username
67+
68+
const operationOwned = operation && auth.userId && operation.uploaderId === auth.userId
69+
70+
const maxLength = operationOwned ? AUTHOR_MAX_COMMENT_LENGTH : MAX_COMMENT_LENGTH
7071

7172
const [replyTo, setReplyTo] = useState<CommentInfo>()
7273

@@ -94,7 +95,7 @@ export const CommentArea = withSuspensable(function ViewerComments({
9495
return (
9596
<CommentAreaContext.Provider value={contextValue}>
9697
<div>
97-
<CommentForm primary className="mb-6" />
98+
<CommentForm primary className="mb-6" maxLength={maxLength} />
9899
{comments?.map((comment) => (
99100
<MainComment
100101
key={comment.commentId}
@@ -110,8 +111,8 @@ export const CommentArea = withSuspensable(function ViewerComments({
110111
sub.fromCommentId === comment.commentId
111112
? undefined
112113
: find(comment.subCommentsInfos, {
113-
commentId: sub.fromCommentId,
114-
})
114+
commentId: sub.fromCommentId,
115+
})
115116
}
116117
/>
117118
))}
@@ -261,6 +262,7 @@ const CommentActions = ({
261262
const [{ userId }] = useAtom(authAtom)
262263
const { operationOwned, replyTo, setReplyTo, reload } =
263264
useContext(CommentAreaContext)
265+
const maxLength = operationOwned ? AUTHOR_MAX_COMMENT_LENGTH : MAX_COMMENT_LENGTH
264266

265267
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false)
266268
const [pending, setPending] = useState(false)
@@ -331,7 +333,7 @@ const CommentActions = ({
331333
</p>
332334
</Alert>
333335
</div>
334-
{replyTo === comment && <CommentForm inputAutoFocus className="mt-4" />}
336+
{replyTo === comment && <CommentForm inputAutoFocus className="mt-4" maxLength={maxLength} />}
335337
</div>
336338
)
337339
}

src/components/viewer/comment/CommentForm.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ export interface CommentFormProps {
1616
primary?: boolean
1717
placeholder?: string
1818
inputAutoFocus?: boolean
19+
maxLength?: number
1920
}
2021

2122
export const CommentForm = ({
2223
className,
2324
primary,
2425
placeholder = '发一条友善的评论吧',
2526
inputAutoFocus,
27+
maxLength = MAX_COMMENT_LENGTH,
2628
}: CommentFormProps) => {
2729
const { operationId, replyTo, reload } = useContext(CommentAreaContext)
2830

@@ -82,7 +84,7 @@ export const CommentForm = ({
8284
rows={2}
8385
growVertically
8486
large
85-
maxLength={MAX_COMMENT_LENGTH}
87+
maxLength={maxLength}
8688
placeholder={placeholder}
8789
value={message}
8890
onChange={(e) => setMessage(e.target.value)}
@@ -111,7 +113,7 @@ export const CommentForm = ({
111113
</Checkbox>
112114

113115
<div className="ml-auto text-slate-500 text-sm">
114-
{message.length}/{MAX_COMMENT_LENGTH}
116+
{message.length}/{maxLength}
115117
</div>
116118
</div>
117119

src/models/comment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const enum CommentRating {
1111
}
1212

1313
export const MAX_COMMENT_LENGTH = 150
14+
export const AUTHOR_MAX_COMMENT_LENGTH = 500
1415

1516
export function isMainComment(
1617
comment: CommentInfo,

0 commit comments

Comments
 (0)