All files / components/products Products.vue

0% Statements 0/3
0% Branches 0/2
0% Functions 0/1
0% Lines 0/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128                                                                                                                                                                                                                                                               
<template>
  <div>
    <main v-if="error">
      {{ error }}
    </main>
    <main
      v-else-if="!products.length"
      class="main d-flex justify-content-center h-100vh"
    >
      <h6 class="no-items text-center my-auto">There aren't any products</h6>
    </main>
    <main
      v-else
      class="content row justify-content-center px-md-1 px-0 py-5 mx-md-5 m-0"
    >
      <div
        v-for="product in products"
        :key="product.id"
        class="
          product
          d-flex
          flex-column
          justify-content-between
          col-10 col-sm-6 col-lg-3
          mb-3
          mx-md-2
          p-4
          mx-2
        "
      >
        <ProductCard :product="product" />
        <button
          v-if="product.status === 'published'"
          class="
            py-2
            px-4
            rounded
            btn
            d-flex
            justify-content-center
            align-items-center
            text-uppercase text-nowrap
            w-100
          "
          v-on:click="addToCart(product)"
        >
          <span class="icon icon-bag mr-2 d-none d-lg-flex"></span>
          Add to cart
        </button>
      </div>
    </main>
  </div>
</template>

<script>
import ProductCard from "~/components/products/ProductCard";
 
export default {
  props: {
    products: Array,
    error: Object,
    storeUrl: String,
  },
  components: { ProductCard },
  methods: {
    addToCart(product) {
      const selected = {
        productId: product.id,
        quantity: 1
      };
      this.$store.dispatch("order/addProduct", selected);
    },
  },
};
</script>
 
<style scoped>
@media (min-width: 350px) {
  .product.col-sm-6 {
    flex: 0 0 45%;
    max-width: 45%;
  }
}
 
@media (min-width: 992px) {
  .product.col-lg-3 {
    flex: 0 0 23%;
    max-width: 23%;
  }
}
 
.main {
  height: 70vh;
}
 
button {
  background-color: #1f2020;
  color: #fff;
}
 
.btn:hover {
  color: none;
}
 
.content {
  margin-left: 35px;
  margin-right: 35px;
}
 
.price {
  font-size: 1.5rem;
}
 
.product {
  box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.17);
  border-radius: 10px;
}
 
.product:hover {
  transform: scale(1.01);
}
 
.icon-bag {
  filter: invert(98%) sepia(98%) saturate(0%) hue-rotate(326deg)
    brightness(103%) contrast(102%);
}
</style>