From 433e57ba93b3f854639ece08d3928184bfa59694 Mon Sep 17 00:00:00 2001 From: Justin Georgi Date: Wed, 29 Nov 2023 21:39:15 -0700 Subject: [PATCH] Change image loading to promise (#25) This PR makes the detection page image loading a promise for better loading success and error handling. Signed-off-by: Justin Georgi Reviewed-on: https://gitea.azgeorgis.net/Georgi_Lab/ALVINN_f7/pulls/25 --- src/pages/detect.vue | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/pages/detect.vue b/src/pages/detect.vue index 149f75e..b0f9f27 100644 --- a/src/pages/detect.vue +++ b/src/pages/detect.vue @@ -314,15 +314,23 @@ }); }, getImage () { + var self = this const searchImage = this.$refs.image_chooser.files[0] - //Promise goes here? - this.imageView = URL.createObjectURL(searchImage) - this.reader.readAsDataURL(searchImage) - this.imageLoaded = true - this.resultData = {} - this.selectedChip = -1 - const box = this.$refs.structure_box - box.style.display = 'none' + let loadImage =new Promise((resolve, reject) => { + this.imageView = URL.createObjectURL(searchImage) + this.reader.readAsDataURL(searchImage) + resolve() + }) + loadImage.then(() => { + this.imageLoaded = true + this.resultData = {} + this.selectedChip = -1 + const box = this.$refs.structure_box + box.style.display = 'none' + }).catch((e) => { + console.log(e.message) + f7.dialog.alert('Error loading image') + }) } } }