@riosst100/pwa-marketplace 2.9.0 → 2.9.1

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@riosst100/pwa-marketplace",
3
3
  "author": "riosst100@gmail.com",
4
- "version": "2.9.0",
4
+ "version": "2.9.1",
5
5
  "main": "src/index.js",
6
6
  "pwa-studio": {
7
7
  "targets": {
@@ -22,14 +22,20 @@ const SubCategory = props => {
22
22
 
23
23
  normalizedData && normalizedData.length && normalizedData.map(({ text, path }, index) => {
24
24
  if (index < maxSubCategory) {
25
- subCategory.push(
25
+ const isActive = index == 0 ? true : false;
26
+
27
+ const item = isActive ? (
28
+ <span className={classes.item}><b>{text}</b></span>
29
+ ) : (
26
30
  <Link
27
31
  key={index}
28
32
  to={resourceUrl(path)}
29
33
  >
30
34
  <li className={classes.item}>{text}</li>
31
35
  </Link>
32
- )
36
+ );
37
+
38
+ subCategory.push(item)
33
39
  }
34
40
  });
35
41
 
@@ -29,6 +29,11 @@ export const GET_CATEGORY_CONTENT = gql`
29
29
  name
30
30
  description
31
31
  url_key
32
+ default_top_filter {
33
+ attribute_code
34
+ label
35
+ value
36
+ }
32
37
  url_path
33
38
  hide_filters
34
39
  allowed_filters {
@@ -1,9 +1,9 @@
1
- import { useEffect, useMemo } from 'react';
1
+ import { useCallback, useMemo, useRef, useState, useEffect } from 'react';
2
2
  import { useLazyQuery, useQuery } from '@apollo/client';
3
3
 
4
4
  import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
5
5
  import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
6
- import { useLocation } from 'react-router-dom';
6
+ import { useLocation, useHistory } from 'react-router-dom';
7
7
  import DEFAULT_OPERATIONS from './categoryContent.gql';
8
8
  import {
9
9
  getFiltersFromSearch,
@@ -177,6 +177,57 @@ export const useCategoryContent = props => {
177
177
 
178
178
  const filters = [];
179
179
 
180
+ const history = useHistory();
181
+ const location = useLocation();
182
+
183
+ const setQueryParam = ({ history, location, parameter, replace, value }) => {
184
+ const { search } = location;
185
+ const queryParams = new URLSearchParams(search);
186
+
187
+ queryParams.set(parameter, value);
188
+ const destination = { search: queryParams.toString() };
189
+
190
+ if (replace) {
191
+ history.replace(destination);
192
+ } else {
193
+ history.push(destination);
194
+ }
195
+ };
196
+
197
+ const setDefaultSubcategoryAndTopFilter = useCallback(
198
+ (value, searchParam, replace = false) => {
199
+ // Update the query parameter.
200
+ setQueryParam({
201
+ history,
202
+ location,
203
+ parameter: searchParam,
204
+ replace,
205
+ value: value
206
+ });
207
+ },
208
+ [history, location]
209
+ );
210
+
211
+ useEffect(() => {
212
+ const { search } = location;
213
+
214
+ if (category && category.default_top_filter) {
215
+ const defaultTopFilter = category.default_top_filter;
216
+
217
+ const attrCode = defaultTopFilter.attribute_code;
218
+ const label = defaultTopFilter.label;
219
+ const value = defaultTopFilter.value;
220
+
221
+ if (!search.includes(attrCode)) {
222
+ setDefaultSubcategoryAndTopFilter(
223
+ label + ',' + value,
224
+ attrCode + '[filter]',
225
+ true
226
+ );
227
+ }
228
+ }
229
+ }, [category, location, setDefaultSubcategoryAndTopFilter]);
230
+
180
231
  // console.log('rawFilters')
181
232
  // console.log(rawFilters)
182
233
 
@@ -163,12 +163,6 @@ const CategoryContent = props => {
163
163
  <FilterModal filters={filters} />
164
164
  ) : null;
165
165
 
166
- // console.log('filters')
167
- // console.log(filters)
168
-
169
- // console.log('shouldShowFilterButtons')
170
- // console.log(shouldShowFilterButtons)
171
-
172
166
  const sidebar = shouldShowFilterButtons ? (
173
167
  <FilterSidebar hideFilters={category && category.hide_filters ? true : false} children={children} filters={filters} allowedFilters={category ? category.allowed_filters : []} />
174
168
  ) : shouldShowFilterShimmer ? (
@@ -289,7 +283,7 @@ const CategoryContent = props => {
289
283
 
290
284
  const currentFilter = activeFilters && activeFilters.length ? activeFilters[activeFilters.length - 1].label : '';
291
285
 
292
- let title = activeFilters && activeFilters.length ? (
286
+ let title = category && !category.children.length && activeFilters && activeFilters.length ? (
293
287
  activeFilters.length > 1 ?
294
288
  activeFilters[activeFilters.length - 1].label
295
289
  : currentFilter