-
Notifications
You must be signed in to change notification settings - Fork 8
/
CommentReply.vue
140 lines (137 loc) · 3.34 KB
/
CommentReply.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
<template>
<div class="comment-reply">
<KtAvatar
class="comment-reply__avatar"
:size="Kotti.Avatar.Size.SMALL"
:src="userAvatar"
/>
<div class="comment-reply__wrapper">
<div class="comment-reply__info">
<div class="comment-reply__name" v-text="userName" />
<div class="comment-reply__time" v-text="createdTime" />
</div>
<div class="comment-reply__body">
<div
v-if="!isInlineEdit"
class="comment-reply__message"
@click="$emit('_inlineReplyClick', { userName, userId })"
>
<!-- eslint-disable vue/no-v-html -->
<span
v-html="postEscapeParser(dangerouslyOverrideParser(inlineMessage))"
/>
<!-- eslint-enable vue/no-v-html -->
<i class="yoco" v-text="'comment'" />
</div>
<div v-else class="comment-inline-edit form-group">
<textarea
v-model="inlineMessageValue"
class="comment-inline-edit-input form-input"
></textarea>
<KtButtonGroup class="comment-inline-edit-buttons">
<KtButton icon="close" @click="cancelInlineEdit" />
<KtButton icon="check" @click="handleConfirm" />
</KtButtonGroup>
</div>
<div
v-if="!isInlineEdit & (actionOptions.length > 0)"
class="comment-reply__action action__more"
>
<i class="yoco">dots</i>
<div class="action__options">
<a
v-for="option in actionOptions"
:key="option.type"
@click="option.onClick"
>
<li>{{ option.label }}</li>
</a>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import escape from 'lodash/escape'
import { KtAvatar } from '../../kotti-avatar'
import { KtButton } from '../../kotti-button'
import { KtButtonGroup } from '../../kotti-button-group'
import { Kotti } from '../../types'
export default {
name: 'CommentReply',
components: {
KtAvatar,
KtButton,
KtButtonGroup,
},
props: {
createdTime: String,
dangerouslyOverrideParser: { default: escape, type: Function },
isDeletable: { default: false, type: Boolean },
isEditable: { default: false, type: Boolean },
id: [Number, String],
message: String,
parser: { default: escape, type: Function },
postEscapeParser: { default: (_) => _, type: Function },
userAvatar: String,
userId: [Number, String],
userName: String,
},
data() {
return {
inlineMessageValue: '',
isInlineEdit: false,
Kotti,
}
},
computed: {
inlineMessage() {
return this.inlineMessageValue || this.message
},
actionOptions() {
const options = []
if (this.isEditable)
options.push({
label: 'Edit',
onClick: () => {
this.inlineMessageValue = this.inlineMessage
this.isInlineEdit = true
},
type: 'EDIT',
})
if (this.isDeletable)
options.push({
label: 'Delete',
onClick: () => this.$emit('_inlineDeleteClick', this.id),
type: 'DELETE',
})
return options
},
},
methods: {
cancelInlineEdit() {
this.inlineMessageValue = ''
this.isInlineEdit = false
},
handleInlineInput(event) {
this.inlineMessageValue = event.target.value
},
handleConfirm() {
this.isInlineEdit = false
if (!this.inlineMessageValue) return
const _payload = {
message: this.inlineMessageValue,
id: this.id,
}
this.$emit('_inlineEditSumbit', _payload)
},
},
}
</script>
<style lang="scss" scoped>
.comment-reply__message {
display: flex;
align-items: center;
}
</style>