@wikala/spmkt 2.22.1 → 2.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,30 +2,35 @@
2
2
  <div class="category-filters category-filter-component">
3
3
  <template v-for="(filter, index) in filters">
4
4
  <div class="filter-container">
5
- <h2>{{ filter.display_name }}</h2>
6
- <div v-if="rangeTypes.includes(filter.type)" class="range-filter-container">
7
- <RangeInput
8
- :value="filters[index].selected"
9
- :min="filters[index].min"
10
- :max="filters[index].max"
11
- :step="filters[index].step"
12
- :show-apply-button="$mq !== 'mobile'"
13
- :filter-name="filter.display_name"
14
- @applyRange="applyRange($event, index)"
15
- @input="rangeInput($event, index)"
16
- />
5
+ <div class="filter-title">
6
+ <h2>{{ filter.display_name }}</h2>
7
+ <span class="filter-expand" @click="expandFilter($event)"><i :class="{ 'fa': true, 'fa-plus': !isExpanded(filter.id), 'fa-minus': isExpanded(filter.id) }"></i></span>
17
8
  </div>
18
- <div v-else :class="[filter.values.length > 7 && !expanded[index] ? 'fixed-height-filter' : '']">
19
- <div v-if="filter.values.length > 7" class="filter-query">
20
- <input class="input" :placeholder="$t('category.searchBy') + filter.display_name" @input="filterQuery($event, filter.id)" />
9
+ <div :class="{ 'filter-content': true, 'is-hidden': !isExpanded(filter.id) }">
10
+ <div v-if="rangeTypes.includes(filter.type)" class="range-filter-container" >
11
+ <RangeInput
12
+ :value="filters[index].selected"
13
+ :min="filters[index].min"
14
+ :max="filters[index].max"
15
+ :step="filters[index].step"
16
+ :show-apply-button="$mq !== 'mobile'"
17
+ :filter-name="filter.display_name"
18
+ @applyRange="applyRange($event, index)"
19
+ @input="rangeInput($event, index)"
20
+ />
21
21
  </div>
22
- <div v-for="fval in filterfilter(filter.values, filter.id)">
23
- <b-checkbox @input="filterChange" v-model="fval.selected">{{ fval.value }}</b-checkbox>
22
+ <div v-else :class="[filter.values.length > 7 && !expanded[index] ? 'fixed-height-filter' : '']">
23
+ <div v-if="filter.values.length > 7" class="filter-query">
24
+ <input class="input" :placeholder="$t('category.searchBy') + ' ' + filter.display_name.toLowerCase()" @input="filterQuery($event, filter.id)" />
25
+ </div>
26
+ <div v-for="fval in filterfilter(filter.values, filter.id)">
27
+ <b-checkbox @input="filterChange" v-model="fval.selected">{{ fval.value }}</b-checkbox>
28
+ </div>
29
+ <div v-if="filterq[filter.id] && filterq[filter.id][1] === 0"> No results </div>
30
+ </div>
31
+ <div v-if="$mq==='mobile' && !rangeTypes.includes(filter.type) && filter.values.length > 7">
32
+ <div @click="expand(index)" class="ml-3 mt-1 is-link">{{ expanded[index] ? 'Show less' : 'Show more' }}</div>
24
33
  </div>
25
- <div v-if="filterq[filter.id] && filterq[filter.id][1] === 0"> No results </div>
26
- </div>
27
- <div v-if="$mq==='mobile' && !rangeTypes.includes(filter.type) && filter.values.length > 7">
28
- <div @click="expand(index)" class="ml-3 mt-1 is-link">{{ expanded[index] ? 'Show less' : 'Show more' }}</div>
29
34
  </div>
30
35
  </div>
31
36
  </template>
@@ -90,7 +95,19 @@ export default {
90
95
 
91
96
  expand(idx) {
92
97
  this.$set(this.expanded, idx, !this.expanded[idx])
93
- //this.expanded[idx] = true
98
+ },
99
+
100
+ expandFilter(e) {
101
+ let filterContent = e.target.parentNode.parentNode.nextElementSibling
102
+ let expandIcon = e.target
103
+
104
+ filterContent.classList.toggle('is-hidden')
105
+ expandIcon.classList.toggle('fa-plus')
106
+ expandIcon.classList.toggle('fa-minus')
107
+ },
108
+
109
+ isExpanded(index) {
110
+ return this.filtersFromURL[index] !== undefined;
94
111
  },
95
112
 
96
113
  filterQuery(e, id) {
@@ -0,0 +1,74 @@
1
+ <template>
2
+ <div class="load-more" v-if="hasMoreContent">
3
+ <button
4
+ @click="loadMore"
5
+ :disabled="isLoading"
6
+ class="button"
7
+ >
8
+ <span v-if="!isLoading">{{ buttonLabel }}</span>
9
+ <span v-else>{{ loadingLabel }}</span>
10
+ </button>
11
+ </div>
12
+ </template>
13
+
14
+ <script>
15
+ export default {
16
+ name: 'LoadMore',
17
+ props: {
18
+ totalPages: {
19
+ type: Number,
20
+ required: true,
21
+ },
22
+ buttonLabel: {
23
+ type: String,
24
+ default: 'Load More',
25
+ },
26
+ loadingLabel: {
27
+ type: String,
28
+ default: 'Loading...',
29
+ },
30
+ },
31
+ data() {
32
+ return {
33
+ isLoading: false,
34
+ currentPage: 1,
35
+ hasMoreContent: true,
36
+ }
37
+ },
38
+ methods: {
39
+ async loadMore() {
40
+ this.isLoading = true;
41
+
42
+ try {
43
+ this.currentPage++;
44
+
45
+ const url = new URL(window.location.href);
46
+ url.searchParams.set('page', this.currentPage);
47
+ url.searchParams.set('partial', '1');
48
+
49
+ const response = await fetch(url);
50
+ console.log("response.status =", response.status);
51
+
52
+ const html = await response.text();
53
+
54
+ const temp = document.createElement('div');
55
+ temp.innerHTML = html;
56
+
57
+ const categoryProducts = this.$el.closest('.category-products').firstChild
58
+ const newProducts = temp.querySelectorAll('.prod-box-container');
59
+ newProducts.forEach(element => {
60
+ categoryProducts.appendChild(element);
61
+ });
62
+ } catch (error) {
63
+ console.error('Error loading more content:', error);
64
+ } finally {
65
+ this.isLoading = false;
66
+ if(this.currentPage === this.totalPages) {
67
+ this.hasMoreContent = false;
68
+ return;
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
74
+ </script>
@@ -236,6 +236,44 @@ export default {
236
236
  GoogleAnalyticsEEC.productView(this.eecProduct())
237
237
  //console.log('addtocart ', this.selectedVariant, this.product_id)
238
238
  }
239
+ },
240
+
241
+ handleScroll() {
242
+ if (this.$mq !== 'mobile') {
243
+ return;
244
+ }
245
+ const element = this.$el
246
+ const pagetop = document.querySelector('#pagetop')
247
+ const elementPosition = element.getBoundingClientRect().top
248
+
249
+ function checkPosition() {
250
+ const scrollPosition = window.scrollY
251
+
252
+ if (scrollPosition > elementPosition) {
253
+ element.classList.add('add-to-cart-fixed-footer')
254
+ pagetop.classList.add('pos2');
255
+ } else {
256
+ element.classList.remove('add-to-cart-fixed-footer');
257
+ pagetop.classList.remove('pos2');
258
+ }
259
+ }
260
+
261
+ window.addEventListener('scroll', checkPosition);
262
+ checkPosition();
263
+ },
264
+
265
+ handleBusEvents() {
266
+ this.$bus.$on('selectVariant', this.onSelectVariant)
267
+
268
+ if (!this.headless) {
269
+ this.$bus.$on('updateQty', (qty) => {
270
+ console.log('received updateQty', qty)
271
+ this.qty = qty
272
+ })
273
+ }
274
+ if (this.headless) {
275
+ this.initHeadless()
276
+ }
239
277
  }
240
278
  },
241
279
 
@@ -254,17 +292,9 @@ export default {
254
292
  }
255
293
  })
256
294
 
257
- this.$bus.$on('selectVariant', this.onSelectVariant)
258
-
259
- if (!this.headless) {
260
- this.$bus.$on('updateQty', (qty) => {
261
- console.log('received updateQty', qty)
262
- this.qty = qty
263
- })
264
- }
265
- if (this.headless) {
266
- this.initHeadless()
267
- }
295
+ this.handleBusEvents()
296
+ this.handleScroll()
297
+
268
298
  }
269
299
  }
270
300
  </script>
package/index.js CHANGED
@@ -49,6 +49,7 @@ import ShoppingCart from './components/Cart/ShoppingCart' //t
49
49
 
50
50
  import CategoryFilter from './components/Category/CategoryFilter' //t
51
51
  import CategorySort from './components/Category/CategorySort' //t
52
+ import LoadMore from './components/Category/LoadMore'
52
53
 
53
54
  import AddToCart from './components/Product/AddToCart' //t
54
55
  import Quantity from './components/Product/Quantity'
@@ -123,6 +124,7 @@ export {
123
124
 
124
125
  CategoryFilter,
125
126
  CategorySort,
127
+ LoadMore,
126
128
 
127
129
  AddToCart,
128
130
  Quantity,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wikala/spmkt",
3
- "version": "2.22.1",
3
+ "version": "2.24.0",
4
4
  "private": false,
5
5
  "description": "supermarket",
6
6
  "scripts": {