@riosst100/pwa-marketplace 1.7.8 → 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.
- package/package.json +1 -1
- package/src/components/LegoSets/index.js +2 -0
- package/src/components/LegoSets/legoSets.js +330 -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 +46 -23
- package/src/components/SportCardsSets/sportCardsSets.js +110 -48
- package/src/overwrites/venia-ui/lib/RootComponents/Category/category.js +5 -1
- package/src/overwrites/venia-ui/lib/RootComponents/Category/categoryContent.js +3 -3
- package/src/overwrites/venia-ui/lib/components/Breadcrumbs/breadcrumbs.js +1 -1
- package/src/overwrites/venia-ui/lib/components/FilterModal/CurrentFilters/currentFilters.js +1 -1
- package/src/overwrites/venia-ui/lib/components/FilterSidebar/filterSidebar.js +1 -1
- package/src/talons/CollectibleGameSets/useCollectibleGameSets.js +0 -1
- package/src/talons/LegoSets/legoSets.gql.js +59 -0
- package/src/talons/LegoSets/useLegoSets.js +269 -0
- package/src/talons/ShopBy/useShopBy.js +43 -18
- 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
|
|
@@ -226,7 +226,7 @@ const CategoryContent = props => {
|
|
|
226
226
|
|
|
227
227
|
let isSingles = false;
|
|
228
228
|
|
|
229
|
-
console.log(allActiveFilters)
|
|
229
|
+
// console.log(allActiveFilters)
|
|
230
230
|
|
|
231
231
|
if (allActiveFilters && allActiveFilters.size > 0) {
|
|
232
232
|
allActiveFilters.forEach((value, key) => {
|
|
@@ -256,9 +256,9 @@ const CategoryContent = props => {
|
|
|
256
256
|
// console.log(activeFilters.length)
|
|
257
257
|
// console.log(activeFilters.map(u => u.label).join(' - '))
|
|
258
258
|
|
|
259
|
-
const title = activeFilters ? (
|
|
259
|
+
const title = activeFilters && activeFilters.length ? (
|
|
260
260
|
activeFilters.length > 1 ?
|
|
261
|
-
activeFilters.map(u => u.label).join('
|
|
261
|
+
activeFilters.map(u => u.label).join(': ')
|
|
262
262
|
: currentFilter
|
|
263
263
|
) : categoryName;
|
|
264
264
|
|
|
@@ -74,7 +74,7 @@ const Breadcrumbs = props => {
|
|
|
74
74
|
|
|
75
75
|
const filterBreadcrumbsElement = [];
|
|
76
76
|
|
|
77
|
-
const lastIndex = currentFilter.length - 1;
|
|
77
|
+
const lastIndex = currentFilter ? currentFilter.length - 1 : 0;
|
|
78
78
|
// const filterpath = ;
|
|
79
79
|
|
|
80
80
|
currentFilter && currentFilter.length && currentFilter.map((filter, index) => {
|
|
@@ -20,7 +20,7 @@ const CurrentFilters = props => {
|
|
|
20
20
|
const { title, value } = item || {};
|
|
21
21
|
const key = `${group}::${title}_${value}`;
|
|
22
22
|
|
|
23
|
-
const customAttributeLandingPage = ['card_set', 'sc_baseball_release','auction','special_price','lof_preorder','sc_baseball_inserts','sc_baseball_parallel'];
|
|
23
|
+
const customAttributeLandingPage = ['card_set', 'sc_baseball_release','auction','special_price','lof_preorder','sc_baseball_inserts','sc_baseball_parallel','sc_set_type'];
|
|
24
24
|
|
|
25
25
|
if (!customAttributeLandingPage.includes(group)) {
|
|
26
26
|
elements.push(
|
|
@@ -91,7 +91,7 @@ const FilterSidebar = props => {
|
|
|
91
91
|
const groupName = filterNames.get(group);
|
|
92
92
|
const frontendInput = filterFrontendInput.get(group);
|
|
93
93
|
|
|
94
|
-
const hideFilters = ['lof_preorder','auction','special_price'];
|
|
94
|
+
const hideFilters = ['lof_preorder','auction','special_price','sc_baseball_inserts','sc_baseball_parallel','sale','sc_set_type','sc_brands'];
|
|
95
95
|
if (!hideFilters.includes(group)) {
|
|
96
96
|
// if (!allowedFilters && !allowedFiltersArr.length && group != "category_uid" || allowedFilters && allowedFiltersArr.length && allowedFiltersArr.includes(group)) {
|
|
97
97
|
|
|
@@ -103,7 +103,6 @@ export const useCollectibleGameSets = props => {
|
|
|
103
103
|
collectibleGameSets.map(({ release_type, sets }, index) => {
|
|
104
104
|
const newSets = sets.filter(function(set) {
|
|
105
105
|
return set.set_name.search(new RegExp(searchQuery, "i")) != -1 || set.set_abbreviation.search(new RegExp(searchQuery, "i")) != -1 || release_type.search(new RegExp(searchQuery, "i")) != -1;
|
|
106
|
-
// return set.set_name.includes(searchQuery);
|
|
107
106
|
});
|
|
108
107
|
|
|
109
108
|
if (newSets && newSets.length) {
|
|
@@ -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!, $setType: String, $filters: ProductAttributeFilterInput!) {
|
|
16
|
+
legoSets(categoryUrlKey: $categoryUrlKey, setType: $setType, 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,269 @@
|
|
|
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
|
+
const sortbyData = [];
|
|
142
|
+
// if (activeTab == 'year') {
|
|
143
|
+
|
|
144
|
+
// console.log(legoSets)
|
|
145
|
+
if (legoSets) {
|
|
146
|
+
legoSets.map((setRelease, index) => {
|
|
147
|
+
const { group, sets } = setRelease;
|
|
148
|
+
if (sets.length) {
|
|
149
|
+
sets.map((set, index) => {
|
|
150
|
+
const { release_year, sc_league } = set;
|
|
151
|
+
if (sc_league) {
|
|
152
|
+
if (!availableLeagues.includes(sc_league)) {
|
|
153
|
+
availableLeagues.push(sc_league);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// if (release_year) {
|
|
157
|
+
// // groupingSetsByYear.splice(release_year, 0, set);
|
|
158
|
+
// const result = sortbyData.find(item => item.group === release_year);
|
|
159
|
+
|
|
160
|
+
// // groupingSetsByYear[release_year] = set;
|
|
161
|
+
// if (result) {
|
|
162
|
+
// result.sets.push(set)
|
|
163
|
+
// } else {
|
|
164
|
+
// // if (sortby == "date" || sortby == "newest" && sortbyData.length < 2) {
|
|
165
|
+
// sortbyData.push({
|
|
166
|
+
// 'group': release_year,
|
|
167
|
+
// 'sets': [set]
|
|
168
|
+
// })
|
|
169
|
+
// // }
|
|
170
|
+
// }
|
|
171
|
+
// }
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return legoSets.slice().sort((a, b) =>a.group.toLowerCase().localeCompare(b.group.toLowerCase()));
|
|
178
|
+
}, [queryResponse, activeTab]);
|
|
179
|
+
|
|
180
|
+
const availableGroups = legoSets && legoSets.length ? legoSets.map(({ group }) => group) : [];
|
|
181
|
+
|
|
182
|
+
// const availableLeagues = legoSets && legoSets.length ? legoSets.map(({ sets }) => legoSets.map(({ sc_league }) => sc_league)) : [];
|
|
183
|
+
// console.log(availableLeagues)
|
|
184
|
+
// sc_league
|
|
185
|
+
|
|
186
|
+
const filteredLegoSets = useMemo(() => {
|
|
187
|
+
if (!legoSets) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const filteredSets = [];
|
|
192
|
+
|
|
193
|
+
if (searchQuery) {
|
|
194
|
+
|
|
195
|
+
setActive('all')
|
|
196
|
+
|
|
197
|
+
legoSets.map(({ group, sets }, index) => {
|
|
198
|
+
const newSets = sets.filter(function(set) {
|
|
199
|
+
return set.set_name.search(new RegExp(searchQuery, "i")) != -1 || group.search(new RegExp(searchQuery, "i")) != -1;
|
|
200
|
+
// return set.set_name.includes(searchQuery);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
if (newSets && newSets.length) {
|
|
204
|
+
filteredSets.push({
|
|
205
|
+
'group': group,
|
|
206
|
+
'sets': newSets
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
})
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (activeFilter && activeFilter != "all") {
|
|
213
|
+
legoSets.map(({ group, sets }, index) => {
|
|
214
|
+
const newSets = sets.filter(function(set) {
|
|
215
|
+
return set.sc_league == activeFilter;
|
|
216
|
+
// return set.set_name.includes(searchQuery);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
if (newSets && newSets.length) {
|
|
220
|
+
filteredSets.push({
|
|
221
|
+
'group': group,
|
|
222
|
+
'sets': newSets
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return searchQuery || activeFilter ? filteredSets : legoSets;
|
|
229
|
+
}, [legoSets, searchQuery, sortby, activeFilter]);
|
|
230
|
+
|
|
231
|
+
// useEffect(() => {
|
|
232
|
+
// setPageLoading(isBackgroundLoading);
|
|
233
|
+
// }, [isBackgroundLoading, setPageLoading]);
|
|
234
|
+
|
|
235
|
+
const { data: categoryData, loading: categoryLoading } = useQuery(
|
|
236
|
+
getCategoryContentQuery,
|
|
237
|
+
{
|
|
238
|
+
fetchPolicy: 'cache-and-network',
|
|
239
|
+
nextFetchPolicy: 'cache-first',
|
|
240
|
+
skip: !categoryId,
|
|
241
|
+
variables: {
|
|
242
|
+
id: categoryId
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
const category =
|
|
248
|
+
categoryData && categoryData.categories.items.length
|
|
249
|
+
? categoryData.categories.items[0]
|
|
250
|
+
: null;
|
|
251
|
+
|
|
252
|
+
const error = queryResponse?.error;
|
|
253
|
+
const loading = queryResponse?.loading;
|
|
254
|
+
|
|
255
|
+
// console.log(legoSets)
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
error,
|
|
259
|
+
loading,
|
|
260
|
+
legoSets,
|
|
261
|
+
filteredLegoSets,
|
|
262
|
+
categoryUrlSuffix,
|
|
263
|
+
categoryUrlKey,
|
|
264
|
+
productType,
|
|
265
|
+
availableGroups,
|
|
266
|
+
category,
|
|
267
|
+
// availableLeagues
|
|
268
|
+
};
|
|
269
|
+
};
|