summaryrefslogtreecommitdiffstats
path: root/ui/src/components/comment-form.tsx
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-06-23 12:52:07 -0400
committerDessalines <tyhou13@gmx.com>2020-06-23 12:52:07 -0400
commit4c582cf1b6d9d9a348dd6efc6c337a0b1754bb8e (patch)
tree32e6159a2c96767d104f026399ca1043ee1b76a5 /ui/src/components/comment-form.tsx
parent43905a041b348d3f7ae5256b84ae07447b61579b (diff)
Making sure new comments don't clear out your current textarea.
- Making a better random string generator. - Doing better incoming comment checking. - Fixes #769
Diffstat (limited to 'ui/src/components/comment-form.tsx')
-rw-r--r--ui/src/components/comment-form.tsx44
1 files changed, 27 insertions, 17 deletions
diff --git a/ui/src/components/comment-form.tsx b/ui/src/components/comment-form.tsx
index 24bfb7cb..0fb7824e 100644
--- a/ui/src/components/comment-form.tsx
+++ b/ui/src/components/comment-form.tsx
@@ -245,18 +245,32 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
});
}
- handleFinished() {
- this.state.previewMode = false;
- this.state.loading = false;
- this.state.commentForm.content = '';
- this.setState(this.state);
- let form: any = document.getElementById(this.formId);
- form.reset();
- if (this.props.node) {
- this.props.onReplyCancel();
+ handleFinished(data: CommentResponse) {
+ let isReply =
+ this.props.node !== undefined && data.comment.parent_id !== null;
+ let xor =
+ +!(data.comment.parent_id !== null) ^ +(this.props.node !== undefined);
+
+ if (
+ (data.comment.creator_id == UserService.Instance.user.id &&
+ // If its a reply, make sure parent child match
+ isReply &&
+ data.comment.parent_id == this.props.node.comment.id) ||
+ // Otherwise, check the XOR of the two
+ (!isReply && xor)
+ ) {
+ this.state.previewMode = false;
+ this.state.loading = false;
+ this.state.commentForm.content = '';
+ this.setState(this.state);
+ let form: any = document.getElementById(this.formId);
+ form.reset();
+ if (this.props.node) {
+ this.props.onReplyCancel();
+ }
+ autosize.update(form);
+ this.setState(this.state);
}
- autosize.update(document.querySelector('textarea'));
- this.setState(this.state);
}
handleCommentSubmit(i: CommentForm, event: any) {
@@ -359,14 +373,10 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
if (UserService.Instance.user) {
if (res.op == UserOperation.CreateComment) {
let data = res.data as CommentResponse;
- if (data.comment.creator_id == UserService.Instance.user.id) {
- this.handleFinished();
- }
+ this.handleFinished(data);
} else if (res.op == UserOperation.EditComment) {
let data = res.data as CommentResponse;
- if (data.comment.creator_id == UserService.Instance.user.id) {
- this.handleFinished();
- }
+ this.handleFinished(data);
}
}
}