@riosst100/pwa-marketplace 1.7.5 → 1.7.6

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": "1.7.5",
4
+ "version": "1.7.6",
5
5
  "main": "src/index.js",
6
6
  "pwa-studio": {
7
7
  "targets": {
@@ -107,7 +107,7 @@ const ShopBy = props => {
107
107
 
108
108
  const talonProps = useShopBy({ searchQuery, setActive, currentSort, categoryId, shopby });
109
109
 
110
- const { error, loading, dataResult, categoryUrlSuffix, categoryUrlKey, productType, filteredAvailableGroups, availableGroups, attributeData, alpha, category } = talonProps;
110
+ const { error, loading, dataResult, categoryUrlSuffix, categoryUrlKey, productType, filteredAvailableGroups, availableGroups, attributeData, alpha, category, activeFilters } = talonProps;
111
111
 
112
112
  if (loading && !dataResult)
113
113
  return <ShopByShimmer />;
@@ -190,10 +190,12 @@ const ShopBy = props => {
190
190
  }
191
191
  ];
192
192
 
193
+ console.log(activeFilters)
194
+
193
195
  return (
194
196
  <Fragment>
195
197
  <StoreTitle>{attributeData ? 'By ' + attributeData.label : 'Shop By'}</StoreTitle>
196
- <Breadcrumbs categoryId={categoryId} customPage={'By ' + attributeData.label} />
198
+ <Breadcrumbs categoryId={categoryId} customPage={'By ' + attributeData.label} currentFilter={activeFilters} />
197
199
  <h1 className='mx-auto relative block text-xl font-bold text-center pt-10 pb-4'>
198
200
  {attributeData ? 'By ' + attributeData.label : 'Shop By'}
199
201
  </h1>
@@ -70,23 +70,30 @@ const Breadcrumbs = props => {
70
70
  );
71
71
  }
72
72
 
73
+ // console.log(currentFilter)
74
+
73
75
  const filterBreadcrumbsElement = [];
74
76
 
75
77
  currentFilter && currentFilter.length && currentFilter.map((filter, index) => {
76
78
  currentProduct ? (
77
79
  filterBreadcrumbsElement.push(
80
+ <>
81
+ <span className={classes.divider}>{DELIMITER}</span>
78
82
  <Link
79
83
  key={index}
80
84
  className={classes.link}
81
- to={resourceUrl(currentCategoryPath)}
85
+ to={filter.path}
82
86
  onClick={handleClick}
83
87
  >
84
88
  {filter.label}
85
89
  </Link>
90
+ </>
86
91
  )
87
92
  ) : (
88
93
  customPage ? (
89
94
  filterBreadcrumbsElement.push(
95
+ <>
96
+ <span className={classes.divider}>{DELIMITER}</span>
90
97
  <Link
91
98
  key={index}
92
99
  className={classes.link}
@@ -95,6 +102,7 @@ const Breadcrumbs = props => {
95
102
  >
96
103
  {filter.label}
97
104
  </Link>
105
+ </>
98
106
  )
99
107
  ) : filterBreadcrumbsElement.push(
100
108
  <span key={index}>
@@ -12,8 +12,8 @@ export const GET_STORE_CONFIG_DATA = gql`
12
12
  `;
13
13
 
14
14
  export const GET_SHOP_BY_DATA_QUERY = gql`
15
- query getShopByData($categoryUrlKey: String!, $attributeCode: String) {
16
- shopByData(categoryUrlKey: $categoryUrlKey, attributeCode: $attributeCode) {
15
+ query getShopByData($categoryUrlKey: String!, $attributeCode: String, $filters: ProductAttributeFilterInput!) {
16
+ shopByData(categoryUrlKey: $categoryUrlKey, attributeCode: $attributeCode, filters: $filters) {
17
17
  label
18
18
  count
19
19
  attribute_code
@@ -40,8 +40,22 @@ export const GET_CATEGORY_CONTENT = gql`
40
40
  }
41
41
  `;
42
42
 
43
+ export const GET_FILTER_INPUTS = gql`
44
+ query GetFilterInputsForCategory {
45
+ __type(name: "ProductAttributeFilterInput") {
46
+ inputFields {
47
+ name
48
+ type {
49
+ name
50
+ }
51
+ }
52
+ }
53
+ }
54
+ `;
55
+
43
56
  export default {
44
57
  getStoreConfigData: GET_STORE_CONFIG_DATA,
45
58
  getShopByDataQuery: GET_SHOP_BY_DATA_QUERY,
46
- getCategoryContentQuery: GET_CATEGORY_CONTENT
59
+ getCategoryContentQuery: GET_CATEGORY_CONTENT,
60
+ getFilterInputsQuery: GET_FILTER_INPUTS,
47
61
  };
@@ -1,10 +1,11 @@
1
- import { useQuery } from '@apollo/client';
1
+ import { useQuery, useLazyQuery } from '@apollo/client';
2
2
  import { useEffect, useMemo } from 'react';
3
3
  import { useLocation } from 'react-router-dom';
4
4
  import { useAppContext } from '@magento/peregrine/lib/context/app';
5
5
 
6
6
  import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
7
7
  import DEFAULT_OPERATIONS from './shopBy.gql';
8
+ import { getFilterInput, getFiltersFromSearch } from '@magento/peregrine/lib/talons/FilterModal/helpers';
8
9
 
9
10
  export const useShopBy = props => {
10
11
 
@@ -13,8 +14,8 @@ export const useShopBy = props => {
13
14
  const { value: sortby } = currentSort
14
15
 
15
16
  const operations = mergeOperations(DEFAULT_OPERATIONS, null);
16
- const { getStoreConfigData, getShopByDataQuery, getCategoryContentQuery } = operations;
17
- const { pathname } = useLocation();
17
+ const { getStoreConfigData, getShopByDataQuery, getCategoryContentQuery, getFilterInputsQuery } = operations;
18
+ const { pathname, search } = useLocation();
18
19
  // const [
19
20
  // ,
20
21
  // {
@@ -22,6 +23,11 @@ export const useShopBy = props => {
22
23
  // }
23
24
  // ] = useAppContext();
24
25
 
26
+ const [runQuery, queryResponse] = useLazyQuery(getShopByDataQuery, {
27
+ fetchPolicy: 'cache-and-network',
28
+ nextFetchPolicy: 'cache-first'
29
+ });
30
+
25
31
  const { data: storeConfigData } = useQuery(getStoreConfigData, {
26
32
  fetchPolicy: 'cache-and-network',
27
33
  nextFetchPolicy: 'cache-first'
@@ -33,26 +39,97 @@ export const useShopBy = props => {
33
39
 
34
40
  const categoryUrlSuffix = storeConfigData?.storeConfig?.category_url_suffix;
35
41
 
36
- const { error, loading, data } = useQuery(getShopByDataQuery, {
37
- fetchPolicy: 'cache-and-network',
38
- nextFetchPolicy: 'cache-first',
39
- skip: !storeConfigData,
40
- variables: {
41
- categoryUrlKey: categoryUrlKey,
42
- attributeCode: shopby
42
+ const { data: introspectionData } = useQuery(getFilterInputsQuery);
43
+
44
+ const filterTypeMap = useMemo(() => {
45
+ const typeMap = new Map();
46
+ if (introspectionData) {
47
+ introspectionData.__type.inputFields.forEach(({ name, type }) => {
48
+ typeMap.set(name, type.name);
49
+ });
50
+ }
51
+ return typeMap;
52
+ }, [introspectionData]);
53
+
54
+ const activeFilters = [];
55
+
56
+ // if (!filterTypeMap.size) {
57
+ // return;
58
+ // }
59
+
60
+ const filters = getFiltersFromSearch(search);
61
+
62
+ console.log(search)
63
+
64
+ // Construct the filter arg object.
65
+ const newFilters = {};
66
+ filters.forEach((values, key) => {
67
+ newFilters[key] = getFilterInput(values, filterTypeMap.get(key));
68
+ // console.log(key)
69
+ // console.log(values)
70
+
71
+ if (key == "sc_baseball_release") {
72
+ for(let item of values) {
73
+ if(item) {
74
+ // console.log(item.split(',')[0])
75
+ const data = search.split('&');
76
+ data.pop();
77
+ activeFilters.push(
78
+ {
79
+ 'label': item.split(',')[0],
80
+ 'path': data
81
+ }
82
+ )
83
+ }
84
+ }
43
85
  }
44
86
  });
45
87
 
88
+ useEffect(() => {
89
+
90
+
91
+
92
+ // Use the category uid for the current category page regardless of the
93
+ // applied filters. Follow-up in PWA-404.
94
+ // newFilters['category_uid'] = { eq: id };
95
+
96
+ runQuery({
97
+ variables: {
98
+ filters: newFilters,
99
+ categoryUrlKey: categoryUrlKey,
100
+ attributeCode: shopby
101
+ }
102
+ });
103
+ }, [
104
+ runQuery,
105
+ // filterTypeMap,
106
+ // search
107
+ ]);
108
+
109
+ // console.log(activeFilters)
110
+
111
+
112
+
113
+ // const { error, loading, data } = useQuery(getShopByDataQuery, {
114
+ // fetchPolicy: 'cache-and-network',
115
+ // nextFetchPolicy: 'cache-first',
116
+ // skip: !storeConfigData,
117
+ // variables: {
118
+ // categoryUrlKey: categoryUrlKey,
119
+ // attributeCode: shopby
120
+ // }
121
+ // });
122
+
46
123
  const alpha = ['#', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
47
124
 
48
- // const isBackgroundLoading = !!data && loading;
125
+ // const isBackgroundLoading = !!queryResponse && loading;
49
126
 
50
127
  const originalDataResult = useMemo(() => {
51
- if (!data) {
128
+ if (!queryResponse) {
52
129
  return null;
53
130
  }
54
131
 
55
- const rawData = data.shopByData;
132
+ const rawData = queryResponse?.data?.shopByData;
56
133
  if (!rawData) {
57
134
  return null;
58
135
  }
@@ -72,14 +149,14 @@ export const useShopBy = props => {
72
149
  const sortbyData = [];
73
150
 
74
151
  return sortby != "all" ? sortbyData && sortbyData.length ? sortbyData.sort((a, b) => b.release_type.toLowerCase().localeCompare(a.release_type.toLowerCase())) : sortbyData : mappingData;
75
- }, [data, sortby, searchQuery]);
152
+ }, [queryResponse, sortby, searchQuery]);
76
153
 
77
154
  const dataResult = useMemo(() => {
78
- if (!data) {
155
+ if (!queryResponse) {
79
156
  return null;
80
157
  }
81
158
 
82
- const rawData = data.shopByData;
159
+ const rawData = queryResponse?.data?.shopByData;
83
160
  if (!rawData) {
84
161
  return null;
85
162
  }
@@ -106,14 +183,14 @@ export const useShopBy = props => {
106
183
  const sortbyData = [];
107
184
 
108
185
  return sortby != "all" ? sortbyData && sortbyData.length ? sortbyData.sort((a, b) => b.release_type.toLowerCase().localeCompare(a.release_type.toLowerCase())) : sortbyData : mappingData;
109
- }, [data, sortby, searchQuery]);
186
+ }, [queryResponse, sortby, searchQuery]);
110
187
 
111
188
  const availableGroups = originalDataResult ? Object.keys(originalDataResult).sort() : [];
112
189
 
113
190
  const filteredAvailableGroups = dataResult ? Object.keys(dataResult).sort() : [];
114
191
 
115
192
 
116
- const attributeData = data ? data.shopByData[0] : null
193
+ const attributeData = queryResponse?.data?.shopByData && queryResponse?.data?.shopByData.length ? queryResponse.data.shopByData[0] : null
117
194
 
118
195
  const { data: categoryData, loading: categoryLoading } = useQuery(
119
196
  getCategoryContentQuery,
@@ -133,8 +210,8 @@ export const useShopBy = props => {
133
210
  : null;
134
211
 
135
212
  return {
136
- error,
137
- loading,
213
+ // error,
214
+ // loading,
138
215
  dataResult,
139
216
  // collectibleGameSets,
140
217
  filteredAvailableGroups,
@@ -143,7 +220,8 @@ export const useShopBy = props => {
143
220
  availableGroups,
144
221
  attributeData,
145
222
  alpha,
146
- category
223
+ category,
224
+ activeFilters
147
225
  // productType
148
226
  };
149
227
  };