From 7381a7033231e6454a37fd64b1f3de4e8d59355f Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Wed, 11 Nov 2020 20:07:12 -0500 Subject: Kind of flailing with the UI; lots of API bugfixes though. --- iridescence/src/store/index.js | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'iridescence/src/store') diff --git a/iridescence/src/store/index.js b/iridescence/src/store/index.js index fc77f79..f98fd87 100644 --- a/iridescence/src/store/index.js +++ b/iridescence/src/store/index.js @@ -29,6 +29,9 @@ export default new Vuex.Store({ } }, mutations: { + toggleBusy(state) { + state.busy = !state.busy; + }, searchTerm(state, term) { if (term) { state.searchTerm = term; @@ -40,9 +43,13 @@ export default new Vuex.Store({ } }, replaceProduct(state, product) { + if (!product || !product.id) { + return; + } + let index = state.products.findIndex(p => p.id == product.id); - if (product && index >= 0) { + if (index) { state.products[index] = product; } }, @@ -53,17 +60,29 @@ export default new Vuex.Store({ } }, actions: { - async refreshProducts(context) { + async refreshProducts({ commit }) { + commit("toggleBusy"); const products = await dichroism.getProducts(); - context.commit("setProducts", products); + commit("setProducts", products); + commit("toggleBusy"); }, - async updateProduct(context, product) { + async updateProduct({ commit }, product) { + commit("toggleBusy"); const updatedProduct = await dichroism.updateProduct(product); - context.dispatch("replaceProduct", updatedProduct); + commit("replaceProduct", updatedProduct); + commit("toggleBusy"); }, - async createProduct(context, product) { + async createProduct({ commit }, product) { + commit("toggleBusy"); const newProduct = await dichroism.createProduct(product); - context.dispatch("addProduct", newProduct); + commit("addProduct", newProduct); + commit("toggleBusy"); + }, + async createPhotoSet({ commit }, file) { + commit("toggleBusy"); + const photoSet = await dichroism.createPhoto(file); + commit("toggleBusy"); + return photoSet; } }, modules: {} -- cgit v1.2.3