Files
chatwoot/app/javascript/dashboard/mixins/attachmentHandlerMixin.js
T

36 lines
814 B
JavaScript

export default {
data() {
return {
attachedFiles: [],
};
},
computed: {
hasAttachments() {
return this.attachedFiles.length;
},
},
methods: {
attachFile({ blob, file }) {
const reader = new FileReader();
reader.readAsDataURL(file.file);
reader.onloadend = () => {
this.attachedFiles.push({
currentChatId: this.currentChat.id,
resource: blob || file,
isPrivate: this.isPrivate,
thumb: reader.result,
blobSignedId: blob ? blob.signed_id : undefined,
});
};
},
removeAttachment(itemIndex) {
this.attachedFiles = this.attachedFiles.filter(
(item, index) => itemIndex !== index
);
},
clearAttachments() {
this.attachedFiles = [];
},
},
};