@riosst100/pwa-marketplace 1.7.9 → 1.8.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.
@@ -9,7 +9,7 @@ import { getFilterInput, getFiltersFromSearch } from '@magento/peregrine/lib/tal
9
9
 
10
10
  export const useShopBy = props => {
11
11
 
12
- const { searchQuery, setActive, currentSort, categoryId, shopby } = props
12
+ const { searchQuery, active, setActive, currentSort, categoryId, shopby } = props
13
13
 
14
14
  const { value: sortby } = currentSort
15
15
 
@@ -59,7 +59,7 @@ export const useShopBy = props => {
59
59
 
60
60
  const filters = getFiltersFromSearch(search);
61
61
 
62
- console.log(search)
62
+ // console.log(search)
63
63
 
64
64
  // Construct the filter arg object.
65
65
  const newFilters = {};
@@ -151,7 +151,7 @@ export const useShopBy = props => {
151
151
  return sortby != "all" ? sortbyData && sortbyData.length ? sortbyData.sort((a, b) => b.release_type.toLowerCase().localeCompare(a.release_type.toLowerCase())) : sortbyData : mappingData;
152
152
  }, [queryResponse, sortby]);
153
153
 
154
- const dataResult = useMemo(() => {
154
+ const filteredOptions = useMemo(() => {
155
155
  if (!queryResponse) {
156
156
  return null;
157
157
  }
@@ -163,25 +163,21 @@ export const useShopBy = props => {
163
163
 
164
164
  let options = rawData[0].options;
165
165
 
166
- const filteredSets = [];
166
+ // const filteredSets = [];
167
167
 
168
- let filteredOptions = [];
168
+ // let filteredOptions = [];
169
169
 
170
170
  // let mappingData = [];
171
171
 
172
- // if (searchQuery) {
173
- // setActive('all')
174
- // mappingData = options.filter(function(option) {
175
- // return option.label.search(new RegExp(searchQuery, "i")) != -1;
176
- // }).reduce((acc, item) => {
177
- // let firstLetter = item.label.charAt(0).toUpperCase();
178
- // if (!alpha.includes(firstLetter)) {
179
- // firstLetter = '#';
180
- // }
181
- // acc[firstLetter] = acc[firstLetter] || [];
182
- // acc[firstLetter].push(item);
183
- // return acc;
184
- // }, {});
172
+ if (searchQuery) {
173
+ if (active != "all") {
174
+ setActive('all');
175
+ }
176
+
177
+ return options.filter(function(option) {
178
+ return option.label.search(new RegExp(searchQuery, "i")) != -1;
179
+ });
180
+ }
185
181
  // } else {
186
182
 
187
183
  // console.log(filteredOptions)
@@ -189,20 +185,30 @@ export const useShopBy = props => {
189
185
 
190
186
  // }
191
187
 
192
- const mappingData = options.reduce((acc, item) => {
193
- let firstLetter = item.label.charAt(0).toUpperCase();
194
- if (!alpha.includes(firstLetter)) {
195
- firstLetter = '#';
196
- }
197
- acc[firstLetter] = acc[firstLetter] || [];
198
- acc[firstLetter].push(item);
199
- return acc;
200
- }, {});
188
+
201
189
 
202
- const sortbyData = [];
190
+ // const sortbyData = [];
203
191
 
204
- return sortby != "all" ? sortbyData && sortbyData.length ? sortbyData.sort((a, b) => b.release_type.toLowerCase().localeCompare(a.release_type.toLowerCase())) : sortbyData : mappingData;
205
- }, [queryResponse, sortby, searchQuery]);
192
+ return options;
193
+ }, [queryResponse, searchQuery]);
194
+
195
+ const dataResult = useMemo(() => {
196
+ if (filteredOptions) {
197
+ return filteredOptions.reduce((acc, item) => {
198
+ let firstLetter = item.label.charAt(0).toUpperCase();
199
+ if (!alpha.includes(firstLetter)) {
200
+ firstLetter = '#';
201
+ }
202
+ acc[firstLetter] = acc[firstLetter] || [];
203
+ acc[firstLetter].push(item);
204
+ return acc;
205
+ }, {});
206
+ }
207
+
208
+ return filteredOptions;
209
+ }, [filteredOptions])
210
+
211
+ // console.log(dataResult)
206
212
 
207
213
  const availableGroups = originalDataResult ? Object.keys(originalDataResult).sort() : [];
208
214
 
@@ -12,14 +12,15 @@ export const GET_STORE_CONFIG_DATA = gql`
12
12
  `;
13
13
 
14
14
  export const GET_SPORT_CARDS_SETS_QUERY = gql`
15
- query getSportCardsSets($categoryUrlKey: String!, $setType: String) {
16
- sportCardsSets(categoryUrlKey: $categoryUrlKey, setType: $setType) {
15
+ query getSportCardsSets($categoryUrlKey: String!, $setType: String, $filters: ProductAttributeFilterInput!) {
16
+ sportCardsSets(categoryUrlKey: $categoryUrlKey, setType: $setType, filters: $filters) {
17
17
  group
18
18
  sets {
19
19
  set_name
20
20
  option_id
21
21
  release_year
22
22
  sc_league
23
+ sc_brands
23
24
  }
24
25
  }
25
26
  }
@@ -39,8 +40,22 @@ export const GET_CATEGORY_CONTENT = gql`
39
40
  }
40
41
  `;
41
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
+
42
56
  export default {
43
57
  getStoreConfigData: GET_STORE_CONFIG_DATA,
44
58
  getSportCardsSetsQuery: GET_SPORT_CARDS_SETS_QUERY,
45
- getCategoryContentQuery: GET_CATEGORY_CONTENT
59
+ getCategoryContentQuery: GET_CATEGORY_CONTENT,
60
+ getFilterInputsQuery: GET_FILTER_INPUTS,
46
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 './sportCardsSets.gql';
8
+ import { getFilterInput, getFiltersFromSearch } from '@magento/peregrine/lib/talons/FilterModal/helpers';
8
9
 
9
10
  export const useSportCardsSets = props => {
10
11
 
@@ -13,16 +14,9 @@ export const useSportCardsSets = props => {
13
14
  const { value: sortby } = currentSort
14
15
 
15
16
  const operations = mergeOperations(DEFAULT_OPERATIONS, null);
16
- const { getStoreConfigData, getSportCardsSetsQuery, getCategoryContentQuery } = operations;
17
- const { pathname } = useLocation();
18
- const [
19
- ,
20
- {
21
- actions: { setPageLoading }
22
- }
23
- ] = useAppContext();
24
-
25
- const { data: storeConfigData } = useQuery(getStoreConfigData, {
17
+ const { getStoreConfigData, getSportCardsSetsQuery, getCategoryContentQuery, getFilterInputsQuery } = operations;
18
+ const { pathname, search } = useLocation();
19
+ const [runQuery, queryResponse] = useLazyQuery(getSportCardsSetsQuery, {
26
20
  fetchPolicy: 'cache-and-network',
27
21
  nextFetchPolicy: 'cache-first'
28
22
  });
@@ -33,30 +27,112 @@ export const useSportCardsSets = props => {
33
27
  const parentCategoryUrlKey = pathnameArr[pathnameArr.length - 2].replace('.html','');
34
28
  const productType = shopby;
35
29
 
36
- const categoryUrlSuffix = storeConfigData?.storeConfig?.category_url_suffix;
30
+
37
31
 
38
- const { error, loading, data } = useQuery(getSportCardsSetsQuery, {
39
- fetchPolicy: 'cache-and-network',
40
- nextFetchPolicy: 'cache-first',
41
- skip: !storeConfigData,
42
- variables: {
43
- categoryUrlKey: categoryUrlKey,
44
- setType: setType
32
+ // const { error, loading, data } = useQuery(getSportCardsSetsQuery, {
33
+ // fetchPolicy: 'cache-and-network',
34
+ // nextFetchPolicy: 'cache-first',
35
+ // skip: !storeConfigData,
36
+ // variables: {
37
+ // categoryUrlKey: categoryUrlKey,
38
+ // setType: setType
39
+ // }
40
+ // });
41
+ const { data: introspectionData } = useQuery(getFilterInputsQuery);
42
+
43
+ const filterTypeMap = useMemo(() => {
44
+ const typeMap = new Map();
45
+ if (introspectionData) {
46
+ introspectionData.__type.inputFields.forEach(({ name, type }) => {
47
+ typeMap.set(name, type.name);
48
+ });
49
+ }
50
+ return typeMap;
51
+ }, [introspectionData]);
52
+ const filters = getFiltersFromSearch(search);
53
+
54
+ // console.log(search)
55
+
56
+ // Construct the filter arg object.
57
+ const newFilters = {};
58
+ filters.forEach((values, key) => {
59
+ newFilters[key] = getFilterInput(values, filterTypeMap.get(key));
60
+ // console.log(key)
61
+ // console.log(values)
62
+
63
+ if (key == "sc_baseball_release") {
64
+ for(let item of values) {
65
+ if(item) {
66
+ // console.log(item.split(',')[0])
67
+ const data = search.split('&');
68
+ data.pop();
69
+ activeFilters.push(
70
+ {
71
+ 'label': item.split(',')[0],
72
+ 'path': data
73
+ }
74
+ )
75
+ }
76
+ }
45
77
  }
46
78
  });
47
79
 
80
+ useEffect(() => {
81
+ // console.log("MASUK")
82
+
83
+ // if (queryResponse.data) {
84
+
85
+
86
+
87
+ // Use the category uid for the current category page regardless of the
88
+ // applied filters. Follow-up in PWA-404.
89
+ // newFilters['category_uid'] = { eq: id };
90
+
91
+ runQuery({
92
+ variables: {
93
+ filters: newFilters,
94
+ categoryUrlKey: categoryUrlKey,
95
+ setType: setType
96
+ }
97
+ });
98
+ // }
99
+ }, [
100
+ runQuery,
101
+ // queryResponse
102
+ // filterTypeMap,
103
+ // search,
104
+ // newFilters,
105
+ // shopby,
106
+ // categoryUrlKey
107
+ ]);
108
+
109
+ const { data: storeConfigData } = useQuery(getStoreConfigData, {
110
+ fetchPolicy: 'cache-and-network',
111
+ nextFetchPolicy: 'cache-first'
112
+ });
113
+
114
+ const categoryUrlSuffix = storeConfigData?.storeConfig?.category_url_suffix;
115
+
116
+ // { data: queryResponse, error, loading }
117
+
118
+
119
+
48
120
  // console.log(data)
49
121
 
50
- const isBackgroundLoading = !!data && loading;
122
+ // const isBackgroundLoading = !!data && loading;
51
123
 
52
124
  const availableLeagues = [];
53
125
 
126
+ // console.log(queryResponse.data)
127
+
54
128
  const sportCardsSets = useMemo(() => {
55
- if (!data) {
129
+ if (!queryResponse) {
56
130
  return null;
57
131
  }
132
+
133
+ // console.log(data)
58
134
 
59
- const sportCardsSets = data.sportCardsSets;
135
+ const sportCardsSets = queryResponse?.data?.sportCardsSets;
60
136
  if (!sportCardsSets) {
61
137
  return null;
62
138
  }
@@ -64,7 +140,8 @@ export const useSportCardsSets = props => {
64
140
  const sortbyData = [];
65
141
  // if (activeTab == 'year') {
66
142
 
67
- // console.log(activeTab)
143
+ // console.log(sportCardsSets)
144
+ if (sportCardsSets) {
68
145
  sportCardsSets.map((setRelease, index) => {
69
146
  const { group, sets } = setRelease;
70
147
  if (sets.length) {
@@ -94,10 +171,10 @@ export const useSportCardsSets = props => {
94
171
  })
95
172
  }
96
173
  })
97
- // }
174
+ }
98
175
 
99
176
  return sportCardsSets.slice().sort((a, b) => b.group.toLowerCase().localeCompare(a.group.toLowerCase()));
100
- }, [data, activeTab]);
177
+ }, [queryResponse, activeTab]);
101
178
 
102
179
  const availableGroups = sportCardsSets && sportCardsSets.length ? sportCardsSets.map(({ group }) => group) : [];
103
180
 
@@ -145,16 +222,14 @@ export const useSportCardsSets = props => {
145
222
  })
146
223
  }
147
224
  })
148
- console.log(activeFilter)
149
- console.log(filteredSets)
150
225
  }
151
226
 
152
227
  return searchQuery || activeFilter ? filteredSets : sportCardsSets;
153
228
  }, [sportCardsSets, searchQuery, sortby, activeFilter]);
154
229
 
155
- useEffect(() => {
156
- setPageLoading(isBackgroundLoading);
157
- }, [isBackgroundLoading, setPageLoading]);
230
+ // useEffect(() => {
231
+ // setPageLoading(isBackgroundLoading);
232
+ // }, [isBackgroundLoading, setPageLoading]);
158
233
 
159
234
  const { data: categoryData, loading: categoryLoading } = useQuery(
160
235
  getCategoryContentQuery,
@@ -173,6 +248,9 @@ export const useSportCardsSets = props => {
173
248
  ? categoryData.categories.items[0]
174
249
  : null;
175
250
 
251
+ const error = queryResponse?.error;
252
+ const loading = queryResponse?.loading;
253
+
176
254
  return {
177
255
  error,
178
256
  loading,