File tree Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -61,10 +61,7 @@ export const CommentArea = withSuspensable(function ViewerComments({
61
61
62
62
// clear replyTo if it's not in comments
63
63
useEffect ( ( ) => {
64
- if (
65
- replyTo &&
66
- ! traverseComments ( comments , ( c ) => c . commentId === replyTo . commentId )
67
- ) {
64
+ if ( replyTo && ! traverseComments ( comments , ( c ) => c === replyTo ) ) {
68
65
setReplyTo ( undefined )
69
66
}
70
67
} , [ replyTo , comments ] )
@@ -82,7 +79,7 @@ export const CommentArea = withSuspensable(function ViewerComments({
82
79
return (
83
80
< CommentAreaContext . Provider value = { contextValue } >
84
81
< div >
85
- < CommentForm className = "mb-6" />
82
+ < CommentForm primary className = "mb-6" />
86
83
{ comments . map ( ( comment ) => (
87
84
< MainComment
88
85
key = { comment . commentId }
@@ -291,7 +288,6 @@ const CommentActions = ({
291
288
</ div >
292
289
{ replyTo === comment && (
293
290
< CommentForm
294
- embedded
295
291
inputAutoFocus
296
292
className = "mt-4"
297
293
placeholder = { `回复 @${ comment . uploader } :` }
Original file line number Diff line number Diff line change @@ -12,14 +12,14 @@ import { CommentAreaContext } from './CommentArea'
12
12
13
13
export interface CommentFormProps {
14
14
className ?: string
15
- embedded ?: boolean
15
+ primary ?: boolean
16
16
placeholder ?: string
17
17
inputAutoFocus ?: boolean
18
18
}
19
19
20
20
export const CommentForm = ( {
21
21
className,
22
- embedded ,
22
+ primary ,
23
23
placeholder = '发表一条评论吧' ,
24
24
inputAutoFocus,
25
25
} : CommentFormProps ) => {
@@ -46,7 +46,17 @@ export const CommentForm = ({
46
46
try {
47
47
await wrapErrorMessage (
48
48
( e ) => '发表评论失败:' + formatError ( e ) ,
49
- requestAddComment ( message , operationId , replyTo ?. commentId ) ,
49
+ ( async ( ) => {
50
+ if ( primary ) {
51
+ // this comment is a main comment and does not reply to others
52
+ await requestAddComment ( message , operationId )
53
+ } else {
54
+ if ( ! replyTo ) {
55
+ throw new Error ( '要回复的评论不存在' )
56
+ }
57
+ await requestAddComment ( message , operationId , replyTo ?. commentId )
58
+ }
59
+ } ) ( ) ,
50
60
)
51
61
52
62
setMessage ( '' )
@@ -78,7 +88,7 @@ export const CommentForm = ({
78
88
loading = { isSubmitting }
79
89
onClick = { handleSubmit }
80
90
>
81
- { embedded ? '回复 ' : '发表评论 ' }
91
+ { primary ? '发表评论 ' : '回复 ' }
82
92
</ Button >
83
93
84
94
< div className = "ml-auto text-slate-500 text-sm" >
You can’t perform that action at this time.
0 commit comments