@riosst100/pwa-marketplace 1.7.9 → 1.8.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 +1 -1
- package/src/components/LegoSets/index.js +2 -0
- package/src/components/LegoSets/legoSets.js +279 -0
- package/src/components/LegoSets/legoSets.module.css +76 -0
- package/src/components/LegoSets/legoSets.shimmer.js +50 -0
- package/src/components/ShopBy/shopBy.js +41 -14
- package/src/components/SportCardsSets/sportCardsSets.js +110 -48
- package/src/overwrites/venia-ui/lib/RootComponents/Category/category.js +5 -1
- package/src/talons/FilterTop/filterTop.gql.js +2 -2
- package/src/talons/FilterTop/useFilterTop.js +6 -1
- package/src/talons/LegoSets/legoSets.gql.js +59 -0
- package/src/talons/LegoSets/useLegoSets.js +219 -0
- package/src/talons/ShopBy/useShopBy.js +36 -30
- package/src/talons/SportCardsSets/sportCardsSets.gql.js +18 -3
- package/src/talons/SportCardsSets/useSportCardsSets.js +108 -30
|
@@ -17,19 +17,24 @@ import Breadcrumbs from '@magento/venia-ui/lib/components/Breadcrumbs';
|
|
|
17
17
|
const SportCardsSets = props => {
|
|
18
18
|
const { categoryId } = props
|
|
19
19
|
|
|
20
|
+
const { location } = globalThis;
|
|
21
|
+
|
|
22
|
+
const query = new URLSearchParams(location.search);
|
|
23
|
+
const activeParam = query.get('active_tab') || null;
|
|
24
|
+
|
|
20
25
|
const [active, setActive] = useState('all');
|
|
21
|
-
const [activeTab, setActiveTab] = useState('leagues');
|
|
26
|
+
const [activeTab, setActiveTab] = useState(activeParam ? activeParam : 'leagues');
|
|
22
27
|
const [activeFilter, setActiveFilter] = useState('Major Baseball League');
|
|
28
|
+
const [activeBrand, setActiveBrand] = useState('all');
|
|
23
29
|
|
|
24
30
|
const [searchQuery, setSearchQuery] = useState('');
|
|
25
31
|
|
|
26
32
|
let availableLeagues = [];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const query = new URLSearchParams(location.search);
|
|
33
|
+
let availableBrands = [];
|
|
34
|
+
|
|
31
35
|
const shopby = query.get('shopby') || null;
|
|
32
36
|
const setType = query.get('set_type') || null;
|
|
37
|
+
const brandsFilter = query.get('sc_brands[filter]') || null;
|
|
33
38
|
|
|
34
39
|
let defaultSort = {
|
|
35
40
|
sortText: 'All (A-Z)',
|
|
@@ -54,10 +59,10 @@ const SportCardsSets = props => {
|
|
|
54
59
|
|
|
55
60
|
const [currentSort] = sortProps;
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
const [sortBy, setSortBy] = useState({
|
|
63
|
+
sortText: 'All (A-Z)',
|
|
64
|
+
value: 'all'
|
|
65
|
+
});
|
|
61
66
|
|
|
62
67
|
|
|
63
68
|
const classes = useStyle(defaultClasses);
|
|
@@ -111,6 +116,14 @@ const SportCardsSets = props => {
|
|
|
111
116
|
availableLeagues.push(set.sc_league)
|
|
112
117
|
}
|
|
113
118
|
}
|
|
119
|
+
|
|
120
|
+
if (set.sc_brands) {
|
|
121
|
+
if (!availableBrands.includes(set.sc_brands)) {
|
|
122
|
+
availableBrands.push(set.sc_brands)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// availableBrands
|
|
114
127
|
})
|
|
115
128
|
}
|
|
116
129
|
}
|
|
@@ -125,8 +138,6 @@ const SportCardsSets = props => {
|
|
|
125
138
|
return result;
|
|
126
139
|
}
|
|
127
140
|
|
|
128
|
-
// console.log(category)
|
|
129
|
-
|
|
130
141
|
const setRelases = newSportCardsSets && newSportCardsSets.length && newSportCardsSets.map((setRelease, index) => {
|
|
131
142
|
const { group, sets } = setRelease;
|
|
132
143
|
|
|
@@ -191,6 +202,33 @@ const SportCardsSets = props => {
|
|
|
191
202
|
setSearchQuery('')
|
|
192
203
|
}
|
|
193
204
|
|
|
205
|
+
const activeTabParam = query.get('active_tab') || null;
|
|
206
|
+
|
|
207
|
+
// useEffect(() => {
|
|
208
|
+
// if (query) {
|
|
209
|
+
//
|
|
210
|
+
// if (activeTabParam) {
|
|
211
|
+
// if (activeTabParam && activeTab == "leagues") {
|
|
212
|
+
|
|
213
|
+
// handleActiveTab(activeTabParam)
|
|
214
|
+
// }
|
|
215
|
+
// }
|
|
216
|
+
|
|
217
|
+
// const activeParam = query.get('active') || null;
|
|
218
|
+
// if (activeParam) {
|
|
219
|
+
// return handleActive(activeTabParam)
|
|
220
|
+
// }
|
|
221
|
+
// // const activeParam = query.get('active') || null;
|
|
222
|
+
// // if (activeParam && activeParam != activeFilter) {
|
|
223
|
+
// // if (activeParam && active == "all") {
|
|
224
|
+
// // return handleActive(activeParam)
|
|
225
|
+
// // }
|
|
226
|
+
// // }
|
|
227
|
+
|
|
228
|
+
// }
|
|
229
|
+
// return true;
|
|
230
|
+
// }, [activeTabParam]);
|
|
231
|
+
|
|
194
232
|
const handleActiveFilter = (val) => {
|
|
195
233
|
setActiveFilter(val);
|
|
196
234
|
|
|
@@ -210,35 +248,37 @@ const SportCardsSets = props => {
|
|
|
210
248
|
}
|
|
211
249
|
];
|
|
212
250
|
|
|
213
|
-
if (shopby == "release_year") {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
251
|
+
// if (shopby == "release_year") {
|
|
252
|
+
// availableSortBy = [
|
|
253
|
+
// {
|
|
254
|
+
// 'label': 'All (By Year)',
|
|
255
|
+
// 'value': 'date'
|
|
256
|
+
// },
|
|
257
|
+
// {
|
|
258
|
+
// 'label': 'Latest Sets',
|
|
259
|
+
// 'value': 'newest'
|
|
260
|
+
// }
|
|
261
|
+
// ];
|
|
262
|
+
|
|
263
|
+
// // alpha = availableGroups;
|
|
264
|
+
// }
|
|
224
265
|
|
|
225
|
-
|
|
226
|
-
|
|
266
|
+
// if (productType == "expansion_sets") {
|
|
267
|
+
// // availableSortBy = [
|
|
268
|
+
// // {
|
|
269
|
+
// // 'label': 'All (Expansion Sets)',
|
|
270
|
+
// // 'value': 'all'
|
|
271
|
+
// // },
|
|
272
|
+
// // {
|
|
273
|
+
// // 'label': 'Latest Sets',
|
|
274
|
+
// // 'value': 'newest'
|
|
275
|
+
// // }
|
|
276
|
+
// // ];
|
|
277
|
+
|
|
278
|
+
// // alpha = availableGroups
|
|
279
|
+
// }
|
|
227
280
|
|
|
228
|
-
|
|
229
|
-
// availableSortBy = [
|
|
230
|
-
// {
|
|
231
|
-
// 'label': 'All (Expansion Sets)',
|
|
232
|
-
// 'value': 'all'
|
|
233
|
-
// },
|
|
234
|
-
// {
|
|
235
|
-
// 'label': 'Latest Sets',
|
|
236
|
-
// 'value': 'newest'
|
|
237
|
-
// }
|
|
238
|
-
// ];
|
|
239
|
-
|
|
240
|
-
// alpha = availableGroups
|
|
241
|
-
}
|
|
281
|
+
let brandName = brandsFilter ? brandsFilter.split(',')[0] : '';
|
|
242
282
|
|
|
243
283
|
let title = "By Release/Set";
|
|
244
284
|
if (activeTab == "year") {
|
|
@@ -246,18 +286,15 @@ const SportCardsSets = props => {
|
|
|
246
286
|
} else if (activeTab == "leagues") {
|
|
247
287
|
title = "By Leagues";
|
|
248
288
|
} else if (activeTab == "brand") {
|
|
249
|
-
title =
|
|
289
|
+
title = brandName;
|
|
250
290
|
}
|
|
251
291
|
|
|
252
|
-
//
|
|
253
|
-
|
|
254
|
-
availableLeagues.sort();
|
|
255
|
-
|
|
292
|
+
// availableLeagues.sort();
|
|
256
293
|
|
|
257
294
|
return (
|
|
258
295
|
<Fragment>
|
|
259
296
|
<StoreTitle>{title}</StoreTitle>
|
|
260
|
-
<Breadcrumbs categoryId={categoryId} customPage={shopby == "
|
|
297
|
+
<Breadcrumbs categoryId={categoryId} customPage={shopby == "release_year" ? "By Year" : "By Release/Set"} />
|
|
261
298
|
{shopby == "release" ? <ul className={classes.nav}>
|
|
262
299
|
<li className={classes.nav_item}>
|
|
263
300
|
<button
|
|
@@ -268,7 +305,7 @@ const SportCardsSets = props => {
|
|
|
268
305
|
{activeTab == 'year' ? <b>By Year</b> : 'By Year'}
|
|
269
306
|
</button>
|
|
270
307
|
</li>
|
|
271
|
-
<li className={classes.nav_item}>
|
|
308
|
+
{/* <li className={classes.nav_item}>
|
|
272
309
|
<button
|
|
273
310
|
onClick={() => {
|
|
274
311
|
handleActiveTab('brand')
|
|
@@ -276,7 +313,7 @@ const SportCardsSets = props => {
|
|
|
276
313
|
>
|
|
277
314
|
{activeTab == 'brand' ? <b>By Brand</b> : 'By Brand'}
|
|
278
315
|
</button>
|
|
279
|
-
</li>
|
|
316
|
+
</li> */}
|
|
280
317
|
<li className={classes.nav_item}>
|
|
281
318
|
<button
|
|
282
319
|
onClick={() => {
|
|
@@ -323,8 +360,32 @@ const SportCardsSets = props => {
|
|
|
323
360
|
{activeFilter == group ? <b>{group}</b> : group}
|
|
324
361
|
</button>
|
|
325
362
|
</li>
|
|
326
|
-
))}
|
|
327
|
-
|
|
363
|
+
))}</ul> : ''}
|
|
364
|
+
{/* {activeTab == "brand" && availableBrands && availableBrands.length ? <ul className={classes.nav}>
|
|
365
|
+
{availableBrands.map((group, index) => (
|
|
366
|
+
<li key={index} className={classes.nav_item}>
|
|
367
|
+
<button
|
|
368
|
+
onClick={() => {
|
|
369
|
+
handleActiveFilter(group)
|
|
370
|
+
}}
|
|
371
|
+
>
|
|
372
|
+
{activeFilter == group ? <b>{group}</b> : group}
|
|
373
|
+
</button>
|
|
374
|
+
</li>
|
|
375
|
+
))} */}
|
|
376
|
+
{/* <li>
|
|
377
|
+
<button
|
|
378
|
+
className={cn(
|
|
379
|
+
'rounded-md border border-solid border-gray-100 p-2 min-w-[28px]',
|
|
380
|
+
'leading-4 font-medium text-base hover_bg-gray-50'
|
|
381
|
+
)}
|
|
382
|
+
onClick={() => {
|
|
383
|
+
setActiveBrand('all')
|
|
384
|
+
}}
|
|
385
|
+
>
|
|
386
|
+
{active == 'all' ? <b>All</b> : 'All'}
|
|
387
|
+
</button>
|
|
388
|
+
</li></ul> : ''} */}
|
|
328
389
|
<div className='border border-gray-100 px-6'>
|
|
329
390
|
{sportCardsSets ? (
|
|
330
391
|
<div
|
|
@@ -379,6 +440,7 @@ const SportCardsSets = props => {
|
|
|
379
440
|
</div>
|
|
380
441
|
</Fragment>
|
|
381
442
|
);
|
|
443
|
+
return '';
|
|
382
444
|
}
|
|
383
445
|
|
|
384
446
|
export default SportCardsSets;
|
|
@@ -14,6 +14,7 @@ import SubCategoryPage from '@riosst100/pwa-marketplace/src/components/CustomSub
|
|
|
14
14
|
import ShopBySets from '@riosst100/pwa-marketplace/src/components/ShopBySets/shopBySets';
|
|
15
15
|
import { useLocation } from 'react-router-dom';
|
|
16
16
|
import SportCardsSets from '@riosst100/pwa-marketplace/src/components/SportCardsSets/sportCardsSets';
|
|
17
|
+
import LegoSets from '@riosst100/pwa-marketplace/src/components/LegoSets/legoSets';
|
|
17
18
|
|
|
18
19
|
const MESSAGES = new Map().set(
|
|
19
20
|
'NOT_FOUND',
|
|
@@ -84,7 +85,10 @@ const Category = props => {
|
|
|
84
85
|
categoryId={uid}
|
|
85
86
|
isLoading={loading} />
|
|
86
87
|
) : (
|
|
87
|
-
shopby == "
|
|
88
|
+
shopby == "lego_set_name" && parentCategoryUrlKey == "lego" ? <LegoSets
|
|
89
|
+
categoryId={uid}
|
|
90
|
+
shopby={shopby}
|
|
91
|
+
isLoading={loading} /> : shopby == "release" && parentCategoryUrlKey == "sport-cards" ? <SportCardsSets
|
|
88
92
|
categoryId={uid}
|
|
89
93
|
shopby={shopby}
|
|
90
94
|
isLoading={loading} /> : shopby == "sets" || shopby == "expansion_sets" || shopby == "release_year" ? <ShopBySets
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { gql } from '@apollo/client';
|
|
2
2
|
|
|
3
3
|
export const GET_CUSTOM_FILTERS = gql`
|
|
4
|
-
query GetCustomFilters($filters: ProductAttributeFilterInput!) {
|
|
5
|
-
customSubFilters(filters: $filters) {
|
|
4
|
+
query GetCustomFilters($categoryUrlKey: String!, $filters: ProductAttributeFilterInput!) {
|
|
5
|
+
customSubFilters(categoryUrlKey: $categoryUrlKey, filters: $filters) {
|
|
6
6
|
label
|
|
7
7
|
count
|
|
8
8
|
attribute_code
|
|
@@ -40,6 +40,10 @@ export const useFilterTop = props => {
|
|
|
40
40
|
const history = useHistory();
|
|
41
41
|
const { pathname, search } = useLocation();
|
|
42
42
|
|
|
43
|
+
const pathnameArr = pathname.split('/');
|
|
44
|
+
|
|
45
|
+
const categoryUrlKey = pathnameArr[pathnameArr.length - 1].replace('.html','');
|
|
46
|
+
|
|
43
47
|
const { data: introspectionData } = useQuery(getFilterInputsQuery);
|
|
44
48
|
|
|
45
49
|
const filterTypeMap = useMemo(() => {
|
|
@@ -72,7 +76,8 @@ export const useFilterTop = props => {
|
|
|
72
76
|
|
|
73
77
|
runQuery({
|
|
74
78
|
variables: {
|
|
75
|
-
filters: newFilters
|
|
79
|
+
filters: newFilters,
|
|
80
|
+
categoryUrlKey: categoryUrlKey
|
|
76
81
|
}
|
|
77
82
|
});
|
|
78
83
|
}, [
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const GET_STORE_CONFIG_DATA = gql`
|
|
4
|
+
query getStoreConfigData {
|
|
5
|
+
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
6
|
+
storeConfig {
|
|
7
|
+
store_code
|
|
8
|
+
product_url_suffix
|
|
9
|
+
category_url_suffix
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
export const GET_LEGO_SETS_QUERY = gql`
|
|
15
|
+
query getLegoSets($categoryUrlKey: String!, $activeTab: String, $filters: ProductAttributeFilterInput!) {
|
|
16
|
+
legoSets(categoryUrlKey: $categoryUrlKey, activeTab: $activeTab, filters: $filters) {
|
|
17
|
+
group
|
|
18
|
+
sets {
|
|
19
|
+
set_name
|
|
20
|
+
option_id
|
|
21
|
+
release_year
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
export const GET_CATEGORY_CONTENT = gql`
|
|
28
|
+
query getCategoryData($id: String!) {
|
|
29
|
+
categories(filters: { category_uid: { in: [$id] } }) {
|
|
30
|
+
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
31
|
+
items {
|
|
32
|
+
uid
|
|
33
|
+
name
|
|
34
|
+
url_key
|
|
35
|
+
url_path
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
export const GET_FILTER_INPUTS = gql`
|
|
42
|
+
query GetFilterInputsForCategory {
|
|
43
|
+
__type(name: "ProductAttributeFilterInput") {
|
|
44
|
+
inputFields {
|
|
45
|
+
name
|
|
46
|
+
type {
|
|
47
|
+
name
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
export default {
|
|
55
|
+
getStoreConfigData: GET_STORE_CONFIG_DATA,
|
|
56
|
+
getLegoSetsQuery: GET_LEGO_SETS_QUERY,
|
|
57
|
+
getCategoryContentQuery: GET_CATEGORY_CONTENT,
|
|
58
|
+
getFilterInputsQuery: GET_FILTER_INPUTS,
|
|
59
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { useQuery, useLazyQuery } from '@apollo/client';
|
|
2
|
+
import { useEffect, useMemo } from 'react';
|
|
3
|
+
import { useLocation } from 'react-router-dom';
|
|
4
|
+
import { useAppContext } from '@magento/peregrine/lib/context/app';
|
|
5
|
+
|
|
6
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
7
|
+
import DEFAULT_OPERATIONS from './legoSets.gql';
|
|
8
|
+
import { getFilterInput, getFiltersFromSearch } from '@magento/peregrine/lib/talons/FilterModal/helpers';
|
|
9
|
+
|
|
10
|
+
export const useLegoSets = props => {
|
|
11
|
+
|
|
12
|
+
const { searchQuery, setActive, currentSort, shopby, setType, categoryId, activeTab, activeFilter } = props
|
|
13
|
+
|
|
14
|
+
const { value: sortby } = currentSort
|
|
15
|
+
|
|
16
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, null);
|
|
17
|
+
const { getStoreConfigData, getLegoSetsQuery, getCategoryContentQuery, getFilterInputsQuery } = operations;
|
|
18
|
+
const { pathname, search } = useLocation();
|
|
19
|
+
const [runQuery, queryResponse] = useLazyQuery(getLegoSetsQuery, {
|
|
20
|
+
fetchPolicy: 'cache-and-network',
|
|
21
|
+
nextFetchPolicy: 'cache-first'
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const pathnameArr = pathname.split('/');
|
|
25
|
+
|
|
26
|
+
const categoryUrlKey = pathnameArr[pathnameArr.length - 1].replace('.html','');
|
|
27
|
+
const parentCategoryUrlKey = pathnameArr[pathnameArr.length - 2].replace('.html','');
|
|
28
|
+
const productType = shopby;
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
// const { error, loading, data } = useQuery(getLegoSetsQuery, {
|
|
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
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
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
|
+
activeTab: activeTab
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
// }
|
|
99
|
+
}, [
|
|
100
|
+
runQuery,
|
|
101
|
+
activeTab
|
|
102
|
+
// queryResponse
|
|
103
|
+
// filterTypeMap,
|
|
104
|
+
// search,
|
|
105
|
+
// newFilters,
|
|
106
|
+
// shopby,
|
|
107
|
+
// categoryUrlKey
|
|
108
|
+
]);
|
|
109
|
+
|
|
110
|
+
const { data: storeConfigData } = useQuery(getStoreConfigData, {
|
|
111
|
+
fetchPolicy: 'cache-and-network',
|
|
112
|
+
nextFetchPolicy: 'cache-first'
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const categoryUrlSuffix = storeConfigData?.storeConfig?.category_url_suffix;
|
|
116
|
+
|
|
117
|
+
// { data: queryResponse, error, loading }
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
// console.log(data)
|
|
122
|
+
|
|
123
|
+
// const isBackgroundLoading = !!data && loading;
|
|
124
|
+
|
|
125
|
+
const availableLeagues = [];
|
|
126
|
+
|
|
127
|
+
// console.log(queryResponse.data)
|
|
128
|
+
|
|
129
|
+
const legoSets = useMemo(() => {
|
|
130
|
+
if (!queryResponse) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// console.log(data)
|
|
135
|
+
|
|
136
|
+
const legoSets = queryResponse?.data?.legoSets;
|
|
137
|
+
if (!legoSets) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return legoSets.slice().sort((a, b) =>a.group.toLowerCase().localeCompare(b.group.toLowerCase()));
|
|
142
|
+
}, [queryResponse]);
|
|
143
|
+
|
|
144
|
+
const availableGroups = legoSets && legoSets.length ? legoSets.map(({ group }) => group) : [];
|
|
145
|
+
|
|
146
|
+
// const availableLeagues = legoSets && legoSets.length ? legoSets.map(({ sets }) => legoSets.map(({ sc_league }) => sc_league)) : [];
|
|
147
|
+
// console.log(availableLeagues)
|
|
148
|
+
// sc_league
|
|
149
|
+
|
|
150
|
+
const filteredLegoSets = useMemo(() => {
|
|
151
|
+
if (!legoSets) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const filteredSets = [];
|
|
156
|
+
|
|
157
|
+
if (searchQuery) {
|
|
158
|
+
|
|
159
|
+
// useEffect(() => {
|
|
160
|
+
// setActive('all')
|
|
161
|
+
// }, [active]);
|
|
162
|
+
|
|
163
|
+
legoSets.map(({ group, sets }, index) => {
|
|
164
|
+
const newSets = sets.filter(function(set) {
|
|
165
|
+
return set.set_name.search(new RegExp(searchQuery, "i")) != -1 || group.search(new RegExp(searchQuery, "i")) != -1;
|
|
166
|
+
// return set.set_name.includes(searchQuery);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
if (newSets && newSets.length) {
|
|
170
|
+
filteredSets.push({
|
|
171
|
+
'group': group,
|
|
172
|
+
'sets': newSets
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return searchQuery ? filteredSets : legoSets;
|
|
179
|
+
}, [legoSets, searchQuery]);
|
|
180
|
+
|
|
181
|
+
// useEffect(() => {
|
|
182
|
+
// setPageLoading(isBackgroundLoading);
|
|
183
|
+
// }, [isBackgroundLoading, setPageLoading]);
|
|
184
|
+
|
|
185
|
+
const { data: categoryData, loading: categoryLoading } = useQuery(
|
|
186
|
+
getCategoryContentQuery,
|
|
187
|
+
{
|
|
188
|
+
fetchPolicy: 'cache-and-network',
|
|
189
|
+
nextFetchPolicy: 'cache-first',
|
|
190
|
+
skip: !categoryId,
|
|
191
|
+
variables: {
|
|
192
|
+
id: categoryId
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
const category =
|
|
198
|
+
categoryData && categoryData.categories.items.length
|
|
199
|
+
? categoryData.categories.items[0]
|
|
200
|
+
: null;
|
|
201
|
+
|
|
202
|
+
const error = queryResponse?.error;
|
|
203
|
+
const loading = queryResponse?.loading;
|
|
204
|
+
|
|
205
|
+
// console.log(legoSets)
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
error,
|
|
209
|
+
loading,
|
|
210
|
+
legoSets,
|
|
211
|
+
filteredLegoSets,
|
|
212
|
+
categoryUrlSuffix,
|
|
213
|
+
categoryUrlKey,
|
|
214
|
+
productType,
|
|
215
|
+
availableGroups,
|
|
216
|
+
category,
|
|
217
|
+
// availableLeagues
|
|
218
|
+
};
|
|
219
|
+
};
|
|
@@ -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
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
|
|
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
|
|
205
|
-
}, [queryResponse,
|
|
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
|
|