From f896de9041aad5b29f36e010dadaae516a96e86c Mon Sep 17 00:00:00 2001 From: Theophyl Hoguet Date: Tue, 14 Mar 2023 21:44:23 +0100 Subject: [PATCH] ergonomie upload --- frontend/src/components/Upload.vue | 96 +++++++++++++++++++++++------- frontend/src/style.css | 14 +++-- 2 files changed, 83 insertions(+), 27 deletions(-) diff --git a/frontend/src/components/Upload.vue b/frontend/src/components/Upload.vue index a1f4f1e..914576f 100644 --- a/frontend/src/components/Upload.vue +++ b/frontend/src/components/Upload.vue @@ -16,8 +16,9 @@ export default defineComponent({ emits: ['updateImageList', 'delete'], data() { return { - sent: false, - file: null as FileList | null + file: null as FileList | null, + titleSendButton: "Envoyer", + classSendButton: "" } }, props: { @@ -28,32 +29,48 @@ export default defineComponent({ }, methods: { async submitImage() { - if (this.sent === true || this.file === null) + if (this.classSendButton === "sent") { + this.titleSendButton = "Images déjà envoyées" + this.classSendButton = "error" return; + } + if (this.file === null || this.file.length === 0) { + this.titleSendButton = "Aucune image sélectionnée" + this.classSendButton = "error" + return; + } Array.from(this.file).forEach((file, id) => { let formData = new FormData(); formData.append('file', file); api.createImage(formData); }); - this.sent = true; this.$emit('updateImageList'); this.resetFile(); + this.titleSendButton = "Envoyé" + this.classSendButton = "sent" }, handleFilesUpload(event: InputFileEvent) { this.file = event.target.files; - this.sent = false; + this.resetSendButton(true) + }, resetFile() { this.file = null; (document.getElementById('fileUpload') as HTMLInputElement).value = ""; }, - titleSendButton() { - if (this.sent === true) - return "Envoyé"; - if (this.file === null) + nameLabelInput() { + if (this.file === null || this.file.length === 0) return "Aucune image sélectionnée"; - return "Envoyer (" + this.file.length + " image(s) sélectionnée(s))"; + if (this.file.length === 1) + return this.file[0].name; + return this.file.length + " images sélectionnées"; + }, + resetSendButton(force: boolean = false) { + if (force || this.classSendButton === "error") { + this.titleSendButton = "Envoyer" + this.classSendButton = "" + } } }, watch: { @@ -78,15 +95,18 @@ export default defineComponent({