From c5280144de096c274f185fade287ccd63b954ceb Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Sun, 8 Nov 2020 21:26:34 -0500 Subject: fixed up product models and api calls, working on new product form --- iridescence/src/api/dichroism.js | 40 +++++++++--- iridescence/src/components/BusyBar.vue | 10 +++ iridescence/src/components/ProductList.vue | 10 +-- iridescence/src/components/admin/NewProduct.vue | 20 +++--- .../src/components/admin/ProductEditCard.vue | 73 +++++++--------------- .../src/components/admin/ProductEditList.vue | 4 -- iridescence/src/models/product.js | 42 ++++++++++++- iridescence/src/store/index.js | 41 +++++++++--- 8 files changed, 146 insertions(+), 94 deletions(-) (limited to 'iridescence/src') diff --git a/iridescence/src/api/dichroism.js b/iridescence/src/api/dichroism.js index e3b08a8..610941c 100644 --- a/iridescence/src/api/dichroism.js +++ b/iridescence/src/api/dichroism.js @@ -14,13 +14,23 @@ export default class Dichroism { body: fd }; - const photos = await self._sendRequest("photos", options); - return photos.map(p => new PhotoSet(p)); + try { + const photos = await this._sendRequest("photos", options); + return photos.map(p => new PhotoSet(p)); + } catch (err) { + console.error(err.message); + return null; + } } async getProducts() { - const products = await self._sendRequest("products", null); - return products.map(p => new Product(p)); + try { + const products = await this._sendRequest("products", null); + return products.map(p => new Product(p)); + } catch (err) { + console.error(err.message); + return []; + } } async updateProduct(fieldDiff) { @@ -29,8 +39,13 @@ export default class Dichroism { body: fieldDiff }; - const product = await self._sendRequest("products", options); - return new Product(product); + try { + const product = await this._sendRequest("products", options); + return new Product(product); + } catch (err) { + console.error(err.message); + return null; + } } async createProduct(newProduct) { @@ -39,17 +54,22 @@ export default class Dichroism { body: newProduct }; - const product = await self._sendRequest("products", options); - return new Product(product); + try { + const product = await this._sendRequest("products", options); + return new Product(product); + } catch (err) { + console.error(err.message); + return null; + } } async _sendRequest(endpoint, options) { - const response = await fetch(self.base_addr + endpoint, options); + const response = await fetch(this._base_addr + endpoint, options); if (response.ok) { return await response.json(); } else { - return new ApiError(await response.text()); + throw new ApiError(await response.text()); } } } diff --git a/iridescence/src/components/BusyBar.vue b/iridescence/src/components/BusyBar.vue index fff2c4c..721a5fd 100644 --- a/iridescence/src/components/BusyBar.vue +++ b/iridescence/src/components/BusyBar.vue @@ -5,6 +5,13 @@ max="100" v-if="isBusy" > + {{ progress }}% @@ -14,6 +21,9 @@ export default { computed: { isBusy() { return this.$store.getters.busy; + }, + progress() { + return this.$store.getters.progress; } } }; diff --git a/iridescence/src/components/ProductList.vue b/iridescence/src/components/ProductList.vue index 537e802..bed37b3 100644 --- a/iridescence/src/components/ProductList.vue +++ b/iridescence/src/components/ProductList.vue @@ -3,10 +3,10 @@
- +
@@ -20,15 +20,11 @@ export default { components: { ProductCard }, - data() { - return {}; - }, computed: { products() { return this.$store.getters.products; } }, - methods: {}, created() { this.$store.dispatch("refreshProducts"); } diff --git a/iridescence/src/components/admin/NewProduct.vue b/iridescence/src/components/admin/NewProduct.vue index 8c45f0b..511ae9c 100644 --- a/iridescence/src/components/admin/NewProduct.vue +++ b/iridescence/src/components/admin/NewProduct.vue @@ -17,7 +17,9 @@ @@ -27,26 +29,18 @@