@@ -2,7 +2,7 @@ import { colorList, getCommentParentId } from "@utils/app";
2
2
import { futureDaysToUnixTime , numToSI } from "@utils/helpers" ;
3
3
import classNames from "classnames" ;
4
4
import { isBefore , parseISO , subMinutes } from "date-fns" ;
5
- import { Component , InfernoNode , linkEvent } from "inferno" ;
5
+ import { Component , linkEvent } from "inferno" ;
6
6
import { Link } from "inferno-router" ;
7
7
import {
8
8
AddAdmin ,
@@ -33,7 +33,6 @@ import {
33
33
SaveComment ,
34
34
TransferCommunity ,
35
35
} from "lemmy-js-client" ;
36
- import deepEqual from "lodash.isequal" ;
37
36
import { commentTreeMaxDepth } from "../../config" ;
38
37
import {
39
38
CommentNodeI ,
@@ -87,7 +86,6 @@ interface CommentNodeProps {
87
86
allLanguages : Language [ ] ;
88
87
siteLanguages : number [ ] ;
89
88
hideImages ?: boolean ;
90
- finished : Map < CommentId , boolean | undefined > ;
91
89
onSaveComment ( form : SaveComment ) : Promise < void > ;
92
90
onCommentReplyRead ( form : MarkCommentReplyAsRead ) : void ;
93
91
onPersonMentionRead ( form : MarkPersonMentionAsRead ) : void ;
@@ -139,6 +137,8 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
139
137
super ( props , context ) ;
140
138
141
139
this . handleReplyCancel = this . handleReplyCancel . bind ( this ) ;
140
+ this . handleCreateComment = this . handleCreateComment . bind ( this ) ;
141
+ this . handleEditComment = this . handleEditComment . bind ( this ) ;
142
142
this . handleReportComment = this . handleReportComment . bind ( this ) ;
143
143
this . handleRemoveComment = this . handleRemoveComment . bind ( this ) ;
144
144
this . handleReplyClick = this . handleReplyClick . bind ( this ) ;
@@ -164,22 +164,6 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
164
164
return this . commentView . comment . id ;
165
165
}
166
166
167
- componentWillReceiveProps (
168
- nextProps : Readonly < { children ?: InfernoNode } & CommentNodeProps > ,
169
- ) : void {
170
- if ( ! deepEqual ( this . props , nextProps ) ) {
171
- this . setState ( {
172
- showEdit : false ,
173
- showAdvanced : false ,
174
- createOrEditCommentLoading : false ,
175
- upvoteLoading : false ,
176
- downvoteLoading : false ,
177
- readLoading : false ,
178
- fetchChildrenLoading : false ,
179
- } ) ;
180
- }
181
- }
182
-
183
167
render ( ) {
184
168
const node = this . props . node ;
185
169
const cv = this . commentView ;
@@ -283,12 +267,11 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
283
267
edit
284
268
onReplyCancel = { this . handleReplyCancel }
285
269
disabled = { this . props . locked }
286
- finished = { this . props . finished . get ( id ) }
287
270
focus
288
271
allLanguages = { this . props . allLanguages }
289
272
siteLanguages = { this . props . siteLanguages }
290
273
containerClass = "comment-comment-container"
291
- onUpsertComment = { this . props . onEditComment }
274
+ onUpsertComment = { this . handleEditComment }
292
275
/>
293
276
) }
294
277
{ ! this . state . showEdit && ! this . state . collapsed && (
@@ -425,12 +408,11 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
425
408
node = { node }
426
409
onReplyCancel = { this . handleReplyCancel }
427
410
disabled = { this . props . locked }
428
- finished = { this . props . finished . get ( id ) }
429
411
focus
430
412
allLanguages = { this . props . allLanguages }
431
413
siteLanguages = { this . props . siteLanguages }
432
414
containerClass = "comment-comment-container"
433
- onUpsertComment = { this . props . onCreateComment }
415
+ onUpsertComment = { this . handleCreateComment }
434
416
/>
435
417
) }
436
418
{ ! this . state . collapsed && node . children . length > 0 && (
@@ -447,7 +429,6 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
447
429
hideImages = { this . props . hideImages }
448
430
isChild = { ! this . props . isTopLevel }
449
431
depth = { this . props . node . depth + 1 }
450
- finished = { this . props . finished }
451
432
onCommentReplyRead = { this . props . onCommentReplyRead }
452
433
onPersonMentionRead = { this . props . onPersonMentionRead }
453
434
onCreateComment = { this . props . onCreateComment }
@@ -559,6 +540,26 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
559
540
this . setState ( { showReply : false , showEdit : false } ) ;
560
541
}
561
542
543
+ async handleCreateComment (
544
+ form : CreateComment ,
545
+ ) : Promise < RequestState < CommentResponse > > {
546
+ const res = await this . props . onCreateComment ( form ) ;
547
+ if ( res . state !== "failed" ) {
548
+ this . setState ( { showReply : false , showEdit : false } ) ;
549
+ }
550
+ return res ;
551
+ }
552
+
553
+ async handleEditComment (
554
+ form : EditComment ,
555
+ ) : Promise < RequestState < CommentResponse > > {
556
+ const res = await this . props . onEditComment ( form ) ;
557
+ if ( res . state !== "failed" ) {
558
+ this . setState ( { showReply : false , showEdit : false } ) ;
559
+ }
560
+ return res ;
561
+ }
562
+
562
563
isPersonMentionType ( item : CommentNodeView ) : item is PersonMentionView {
563
564
return item . person_mention ?. id !== undefined ;
564
565
}
0 commit comments