summaryrefslogtreecommitdiff
path: root/iridescence/src/store
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2022-10-26 21:02:31 -0400
committerAdam T. Carpenter <atc@53hor.net>2022-10-26 21:02:31 -0400
commit9f3098e80c6b6c87e9bfbfe36239a39e5cafb29f (patch)
treedb9ca419266117facecdff6d30460669f3148efb /iridescence/src/store
parentf243a3b7341012227d6e8342a65f9c5d7784256f (diff)
downloadtheglassyladies-9f3098e80c6b6c87e9bfbfe36239a39e5cafb29f.tar.xz
theglassyladies-9f3098e80c6b6c87e9bfbfe36239a39e5cafb29f.zip
init: add some stories and personas and begin layout out domain
Diffstat (limited to 'iridescence/src/store')
-rw-r--r--iridescence/src/store/index.js118
1 files changed, 0 insertions, 118 deletions
diff --git a/iridescence/src/store/index.js b/iridescence/src/store/index.js
deleted file mode 100644
index 709dc79..0000000
--- a/iridescence/src/store/index.js
+++ /dev/null
@@ -1,118 +0,0 @@
-import Vue from "vue";
-import Vuex from "vuex";
-import Dichroism from "@/api/dichroism.js";
-
-Vue.use(Vuex);
-
-let dichroism = new Dichroism();
-
-export default new Vuex.Store({
- state: {
- searchTerm: "",
- products: [],
- cart: {},
- busy: false,
- compare: a => (a.featured ? -1 : 1),
- productDetailId: 0
- },
- getters: {
- products(state) {
- let term = state.searchTerm.toLowerCase();
- return state.products
- .filter(item => {
- return [item.id, item.name, item.description, item.category]
- .join("")
- .toLowerCase()
- .includes(term);
- })
- .sort(state.compare);
- },
- cartTotal(state) {
- let cents = state.products
- .filter(p => state.cart[p.id])
- .map(p => p.cents * state.cart[p.id])
- .reduce((acc, cur) => acc + cur, 0);
- return "$ " + (cents / 100).toFixed(2);
- }
- },
- mutations: {
- toggleBusy(state) {
- state.busy = !state.busy;
- },
- productDetailId(state, id) {
- state.productDetailId = id;
- },
- cartItem(state, { id, by }) {
- let newCount = 1;
- if (state.cart[id]) {
- newCount = state.cart[id] += by;
- //if (newCount <= 0) {
- // // remove from cart entirely
- // delete state.cart[id];
- // return;
- //}
- //state.cart = {
- // ...state.cart,
- // [id]: newCount
- }
-
- let cart = {
- ...state.cart
- };
-
- if (newCount) {
- cart[id] = newCount;
- } else {
- // remove entirely
- delete cart[id];
- }
- state.cart = cart;
- },
- removeItemFromCart(state, id) {
- if (state.cart[id]) {
- let cart = {
- ...state.cart
- };
- delete cart[id];
- state.cart = cart;
- }
- },
- compare(state, compare) {
- state.compare = compare;
- },
- searchTerm(state, term) {
- state.searchTerm = term;
- },
- setProducts(state, products) {
- if (products) {
- state.products = products;
- }
- }
- },
- actions: {
- async refreshProducts({ commit }) {
- commit("toggleBusy");
- const products = await dichroism.getProducts();
- commit("setProducts", products);
- commit("toggleBusy");
- },
- async updateProduct({ commit, dispatch }, product) {
- commit("toggleBusy");
- await dichroism.updateProduct(product);
- dispatch("refreshProducts");
- commit("toggleBusy");
- },
- async createProduct({ commit, dispatch }, product) {
- commit("toggleBusy");
- await dichroism.createProduct(product);
- dispatch("refreshProducts");
- commit("toggleBusy");
- },
- async createPhotoSet({ commit }, file) {
- commit("toggleBusy");
- const photoSet = await dichroism.createPhoto(file);
- commit("toggleBusy");
- return photoSet;
- }
- }
-});