summaryrefslogtreecommitdiff
path: root/iridescence/src/store
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2020-11-08 21:26:34 -0500
committerAdam T. Carpenter <atc@53hor.net>2020-11-08 21:26:34 -0500
commitc5280144de096c274f185fade287ccd63b954ceb (patch)
tree169f1c2ad86c68e5ccb37494398c5e2db33dca3d /iridescence/src/store
parent7dd36c0e699a1154c7163f25bf488fbd63edeafe (diff)
downloadtheglassyladies-c5280144de096c274f185fade287ccd63b954ceb.tar.xz
theglassyladies-c5280144de096c274f185fade287ccd63b954ceb.zip
fixed up product models and api calls, working on new product form
Diffstat (limited to 'iridescence/src/store')
-rw-r--r--iridescence/src/store/index.js41
1 files changed, 33 insertions, 8 deletions
diff --git a/iridescence/src/store/index.js b/iridescence/src/store/index.js
index 2b24816..fc77f79 100644
--- a/iridescence/src/store/index.js
+++ b/iridescence/src/store/index.js
@@ -10,12 +10,16 @@ export default new Vuex.Store({
state: {
searchTerm: "",
products: [],
- busy: false
+ busy: false,
+ progress: 100
},
getters: {
busy(state) {
return state.busy;
},
+ progress(state) {
+ return state.progress;
+ },
products(state) {
return state.products.filter(item => {
return JSON.stringify(item)
@@ -26,19 +30,40 @@ export default new Vuex.Store({
},
mutations: {
searchTerm(state, term) {
- state.searchTerm = term;
+ if (term) {
+ state.searchTerm = term;
+ }
},
setProducts(state, products) {
- state.products = products;
+ if (products) {
+ state.products = products;
+ }
+ },
+ replaceProduct(state, product) {
+ let index = state.products.findIndex(p => p.id == product.id);
+
+ if (product && index >= 0) {
+ state.products[index] = product;
+ }
+ },
+ addProduct(state, product) {
+ if (product) {
+ state.products.push(product);
+ }
}
},
actions: {
- refreshProducts(context) {
- context.commit("setProducts", dichroism.getProducts());
+ async refreshProducts(context) {
+ const products = await dichroism.getProducts();
+ context.commit("setProducts", products);
+ },
+ async updateProduct(context, product) {
+ const updatedProduct = await dichroism.updateProduct(product);
+ context.dispatch("replaceProduct", updatedProduct);
},
- updateProduct(context, product) {
- dichroism.updateProduct(product);
- context.dispatch("refreshProducts");
+ async createProduct(context, product) {
+ const newProduct = await dichroism.createProduct(product);
+ context.dispatch("addProduct", newProduct);
}
},
modules: {}