Skip to content

Commit 9615646

Browse files
committed
Merge branch 'add_confirmation_when_we_remove_a_message' of https://github.com/arabakevin/vue-beautiful-chat into arabakevin-add_confirmation_when_we_remove_a_message
2 parents 1fafcef + bfa2152 commit 9615646

File tree

7 files changed

+72
-31
lines changed

7 files changed

+72
-31
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Vue.use(Chat)
5757
:showFile="true"
5858
:showEdition="true"
5959
:showDeletion="true"
60+
:deletionConfirmation="true"
6061
:showTypingIndicator="showTypingIndicator"
6162
:showLauncher="true"
6263
:showCloseButton="true"
@@ -178,6 +179,7 @@ For more detailed examples see the demo folder.
178179
| showEmoji | Boolean | A bool indicating whether or not to show the emoji button
179180
| showFile | Boolean | A bool indicating whether or not to show the file chooser button
180181
| showDeletion | Boolean | A bool indicating whether or not to show the edit button for a message
182+
| showConfirmationDeletion | Boolean | A bool indicating whether or not to show the confirmation text when we remove a message
181183
| showEdition | Boolean | A bool indicating whether or not to show the delete button for a message
182184
| showTypingIndicator | String | A string that can be set to a user's participant.id to show `typing` indicator for them
183185
| showHeader | Boolean | A bool indicating whether or not to show the header of chatwindow

demo/src/App.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
:showTypingIndicator="showTypingIndicator"
2323
:showEdition="true"
2424
:showDeletion="true"
25+
:showConfirmationDeletion="true"
2526
:titleImageUrl="titleImageUrl"
2627
@onType="handleOnType"
2728
@edit="editMessage"
@@ -197,11 +198,9 @@ export default {
197198
m.data.text = message.data.text;
198199
},
199200
removeMessage(message){
200-
if (confirm('Delete?')){
201-
const m = this.messageList.find(m => m.id === message.id);
202-
m.type = 'system';
203-
m.data.text = 'This message has been removed';
204-
}
201+
const m = this.messageList.find(m => m.id === message.id);
202+
m.type = 'system';
203+
m.data.text = 'This message has been removed';
205204
},
206205
like(id){
207206
const m = this.messageList.findIndex(m => m.id === id);

src/ChatWindow.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
:always-scroll-to-bottom="alwaysScrollToBottom"
2525
:show-edition="showEdition"
2626
:show-deletion="showDeletion"
27+
:show-confirmation-deletion="showConfirmationDeletion"
2728
:message-styling="messageStyling"
2829
@scrollToTop="$emit('scrollToTop')"
2930
@remove="$emit('remove', $event)"
@@ -152,6 +153,10 @@ export default {
152153
showDeletion: {
153154
type: Boolean,
154155
required: true
156+
},
157+
showConfirmationDeletion: {
158+
type: Boolean,
159+
required: true
155160
}
156161
},
157162
data() {

src/Launcher.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
:show-file="showFile"
2828
:show-edition="showEdition"
2929
:show-deletion="showDeletion"
30+
:show-confirmation-deletion="showConfirmationDeletion"
3031
:show-header="showHeader"
3132
:placeholder="placeholder"
3233
:show-typing-indicator="showTypingIndicator"
@@ -104,6 +105,10 @@ export default {
104105
type: Boolean,
105106
default: false
106107
},
108+
showConfirmationDeletion: {
109+
type: Boolean,
110+
default: false
111+
},
107112
isOpen: {
108113
type: Boolean,
109114
required: true

src/Message.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
:message-styling="messageStyling"
2828
:show-edition="showEdition"
2929
:show-deletion="showDeletion"
30+
:show-confirmation-deletion="showConfirmationDeletion"
3031
@remove="$emit('remove')"
3132
>
3233
<template v-slot:default="scopedProps">
@@ -103,6 +104,10 @@ export default {
103104
showDeletion: {
104105
type: Boolean,
105106
required: true
107+
},
108+
showConfirmationDeletion: {
109+
type: Boolean,
110+
required: true
106111
}
107112
},
108113
computed: {
@@ -203,7 +208,13 @@ export default {
203208
left: -20px;
204209
opacity: 1;
205210
}
206-
.sc-message--toolbox {
211+
&.confirm-delete:hover .sc-message--toolbox {
212+
left: -90px;
213+
}
214+
&.confirm-delete .sc-message--toolbox {
215+
width: auto;
216+
}
217+
.sc-message--toolbox{
207218
transition: left 0.2s ease-out 0s;
208219
white-space: normal;
209220
opacity: 0;

src/MessageList.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
:message-styling="messageStyling"
1515
:show-edition="showEdition"
1616
:show-deletion="showDeletion"
17+
:show-confirmation-deletion="showConfirmationDeletion"
1718
@remove="$emit('remove', message)"
1819
>
1920
<template v-slot:user-avatar="scopedProps">
@@ -45,6 +46,7 @@
4546
:message-styling="messageStyling"
4647
:show-edition="showEdition"
4748
:show-deletion="showDeletion"
49+
:show-confirmation-deletion="showConfirmationDeletion"
4850
/>
4951
</div>
5052
</template>
@@ -89,6 +91,10 @@ export default {
8991
showDeletion: {
9092
type: Boolean,
9193
required: true
94+
},
95+
showConfirmationDeletion: {
96+
type: Boolean,
97+
required: true
9298
}
9399
},
94100
computed: {

src/messages/TextMessage.vue

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,18 @@
22
<div class="sc-message--text" :style="messageColors">
33
<template>
44
<div class="sc-message--toolbox" :style="{background: messageColors.backgroundColor}">
5-
<button
6-
v-if="showEdition && me && message.id != null && message.id != undefined"
7-
:disabled="isEditing"
8-
@click="edit"
9-
>
10-
<IconBase :color="isEditing ? 'black' : messageColors.color" width="10" icon-name="edit">
5+
<button v-if="showEdition && me && message.id" @click="edit" :disabled="isEditing">
6+
<IconBase :color="isEditing? 'black': messageColors.color" width="10" icon-name="edit">
117
<IconEdit />
128
</IconBase>
139
</button>
14-
<button
15-
v-if="showDeletion && me && message.id != null && message.id != undefined"
16-
@click="$emit('remove')"
17-
>
18-
<IconBase :color="messageColors.color" width="10" icon-name="remove">
19-
<IconCross />
20-
</IconBase>
21-
</button>
10+
<div v-if="showDeletion">
11+
<button v-if="me && message.id != null && message.id != undefined" @click="ifelse(showConfirmationDeletion, withConfirm('Do you really want to delete the message?', () => $emit('remove')), () => $emit('remove'))()">
12+
<IconBase :color="messageColors.color" width="10" icon-name="remove">
13+
<IconCross />
14+
</IconBase>
15+
</button>
16+
</div>
2217
<slot name="text-message-toolbox" :message="message" :me="me"> </slot>
2318
</div>
2419
</template>
@@ -47,10 +42,10 @@ import store from './../store/'
4742
const fmt = require('msgdown')
4843
4944
export default {
50-
components: {
51-
IconBase,
52-
IconCross,
53-
IconEdit
45+
data() {
46+
return {
47+
store
48+
}
5449
},
5550
props: {
5651
message: {
@@ -72,12 +67,11 @@ export default {
7267
showDeletion: {
7368
type: Boolean,
7469
required: true
75-
}
76-
},
77-
data() {
78-
return {
79-
store
80-
}
70+
},
71+
showConfirmationDeletion: {
72+
type: Boolean,
73+
required: true
74+
},
8175
},
8276
computed: {
8377
messageText() {
@@ -98,7 +92,26 @@ export default {
9892
methods: {
9993
edit() {
10094
this.store.editMessage = this.message
101-
}
95+
},
96+
ifelse(cond, funcIf, funcElse) {
97+
return () => {
98+
if (funcIf && cond) funcIf()
99+
else if (funcElse) funcElse()
100+
}
101+
},
102+
withConfirm(msg, func) {
103+
return () => {
104+
if (confirm(msg)) {
105+
console.log(func)
106+
func()
107+
}
108+
}
109+
},
110+
},
111+
components:{
112+
IconBase,
113+
IconCross,
114+
IconEdit,
102115
}
103116
}
104117
</script>

0 commit comments

Comments
 (0)