-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathcomment.js
More file actions
130 lines (112 loc) · 2.87 KB
/
comment.js
File metadata and controls
130 lines (112 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { task } from 'ember-concurrency';
/**
* Component to handle individual comments in a comment thread.
*/
export default class CommentThreadCommentComponent extends Component {
/**
* Service to handle data store operations.
* @service
*/
@service store;
/**
* The text input for replying or editing comments.
* @tracked
*/
@tracked input = '';
/**
* Flag to indicate if the reply interface is active.
* @tracked
*/
@tracked replying = false;
/**
* Flag to indicate if the edit interface is active.
* @tracked
*/
@tracked editing = false;
/**
* The constructor for the comment component.
* @param owner - The owner of the component.
* @param comment - The comment data for the component.
*/
constructor(owner, { comment, contextApi }) {
super(...arguments);
this.comment = comment;
this.contextApi = contextApi;
}
/**
* Activates the reply interface.
* @action
*/
@action reply() {
this.replying = true;
}
/**
* Deactivates the reply interface.
* @action
*/
@action cancelReply() {
this.replying = false;
}
/**
* Activates the edit interface.
* @action
*/
@action edit() {
this.editing = true;
}
/**
* Deactivates the edit interface.
* @action
*/
@action cancelEdit() {
this.editing = false;
}
/**
* Deletes the current comment.
* @action
*/
@action delete() {
this.comment.destroyRecord();
}
/**
* Asynchronous task to update the current comment.
* @task
*/
@task *updateComment() {
if (this.contextApi && this.contextApi.isCommentInvalid(this.comment.content)) {
return;
}
yield this.comment.save();
this.editing = false;
}
/**
* Asynchronous task to publish a reply to the current comment.
* @task
*/
@task *publishReply() {
if (this.contextApi && this.contextApi.isCommentInvalid(this.input)) {
return;
}
let comment = this.store.createRecord('comment', {
content: this.input,
parent_comment_uuid: this.comment.id,
subject_uuid: this.comment.subject_uuid,
subject_type: this.comment.subject_type,
});
yield comment.save();
yield this.reloadReplies.perform();
this.replying = false;
this.input = '';
}
/**
* Asynchronous task to reload replies to the current comment.
* @task
*/
@task *reloadReplies() {
this.comment = yield this.comment.reload();
}
}