forked from DarkGeekMS/ApeX-Web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Comment.vue
155 lines (146 loc) · 4.08 KB
/
Comment.vue
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<script>
/**
* @vue-data {string} [Content] content of the comment
* @vue-data {integer} [idx] idx of the comment in the array of comments
* @vue-data {integer} [level] level of indentation of the comment in the view
* @vue-data {integer} [parentIdx] idx of the parent of the comment in the array of comments
* @vue-data {string} [parentID] ID of the parent component
* @vue-data {string} [ID] ID of the the current comment
* @vue-data {string} [user] user name of the current logged-in user
* @vue-data {boolean} [upVoted=false] check if the Post is upVoted by the user
* @vue-data {boolean} [downVoted=false] check if the Post is downVoted by the user
* @vue-data {integer} [Points=0] # of points the the comment got
* @vue-data {object} [time=0] the time that the post created in
* @vue-data {boolean} [showReplyBox=0] to show the reply box
* @vue-data {boolean} [showEditBox=0] to show the edit box
* @vue-data {boolean} [deleted=1] check if the comment is Deleted
* @vue-data {string} [unSaved='Save'] check if the comment is Saved
*/
export default {
name: 'CommentItem',
props:{
content:String,
idx:Number,
level:Number,
parentIdx:Number,
parentID:String,
ID:String
},
data(){
return{
user:globalStore.Username,
upVoted:false,
downVoted:false,
points:0,
time:0,
showReplyBox:0,
showEditBox:0,
deleted:1,
unSaved:'Save'
}
},
methods:{
/**
* edits the comment's content
* @param {string} updatedContent the updated content of the comment to be rendered
*/
edit:function(updatedContent){
this.content=updatedContent;
this.showEditBox =0;
//EMIT EVENT TO COMMENT PARENT TO EDIT THE CONTENT OF THE IDX = idx by updatedContent
this.$emit('Edit',updatedContent,this.idx );
},
/**
* hides the edit box and do nothing if it's empty
*/
retrieveWithNoEdit:function(){
this.showEditBox =0;
},
/**
* deletes the the comment and sends to the CommentParent to delete it and its children from the array
*/
Delete:function(){
this.$emit('Delete',this.idx );
axios.delete('http://127.0.0.1:8000/api/delete', {
data : {
name: this.ID,
token: globalStore.token
}
})
.then(function (response) {
})
.catch(function (error) {
alert("Something went wrong");
});
},
/**
* saves the the comment
*/
Save:function(){
if(this.unSaved=='Save')
this.unSaved='Unsave';
else
this.unSaved='Save';
axios.post('http://127.0.0.1:8000/api/save', {
ID: this.ID,
token: globalStore.token
})
.then(function (response) {
})
.catch(function (error) {
alert("Something went wrong");
});
},
/**
* upvotes the comment
*/
Upvote:function(){
this.upVoted = !this.upVoted;
this.downVoted = false;
axios.post('http://127.0.0.1:8000/api/vote', {
name: this.ID,
dir: 1,
token: globalStore.token
})
.then(function (response) {
})
.catch(function (error)
{
alert("Something went wrong");
});
},
/**
* downvotes the comment
*/
Downvote:function(){
this.downVoted = !this.downVoted;
this.upVoted = false;
axios.post('http://127.0.0.1:8000/api/vote', {
name: this.ID,
dir: -1,
token: globalStore.token
})
.then(function (response) {
})
.catch(function (error) {
alert("Something went wrong");
});
},
/**
* function due to the response of the reply box to send the data to the CommentParent to be set in the array
* @param {string} cont content of the added comment
* @param {integer} parent parent index in the array
* @param {integer} parentLevel level of the parent comment
* @param {string} parentID parent ID
* @param {string} currentID current ID
*/
addReply:function(cont,use,parent,parentLevel,parentID,currentID){
// send to comment parent to push in the array!!!!!
this.$emit('Reply2',cont,parent,parentLevel+1,parentID,currentID );
}
},
components: {
WriteComment
}
}
</script>