summaryrefslogtreecommitdiff
path: root/iridescence/src/store/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'iridescence/src/store/index.js')
-rw-r--r--iridescence/src/store/index.js33
1 files changed, 26 insertions, 7 deletions
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: {}