@riosst100/pwa-marketplace 1.8.7 → 1.8.9
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/CustomSubCategoryPage/subCategoryPage.js +5 -3
- package/src/components/FilterTopBackup/CustomFilters/customFilters.js +2 -0
- package/src/components/LegoSets/legoSets.js +50 -19
- package/src/components/NonSportCardsSets/index.js +2 -0
- package/src/components/NonSportCardsSets/nonSportCardsSets.js +270 -0
- package/src/components/NonSportCardsSets/nonSportCardsSets.module.css +76 -0
- package/src/components/NonSportCardsSets/nonSportCardsSets.shimmer.js +50 -0
- package/src/components/ShopBy/shopBy.js +8 -1
- package/src/components/ShopByVehicles/index.js +2 -0
- package/src/components/ShopByVehicles/shopByVehicles.js +328 -0
- package/src/components/ShopByVehicles/shopByVehicles.shimmer.js +50 -0
- package/src/components/SportCardsSets/sportCardsSets.js +71 -154
- package/src/components/SubCategory/customSubCategory.js +19 -9
- package/src/overwrites/venia-ui/lib/RootComponents/Category/category.js +5 -1
- package/src/overwrites/venia-ui/lib/RootComponents/Category/categoryContent.js +31 -5
- package/src/overwrites/venia-ui/lib/components/Breadcrumbs/breadcrumbs.js +12 -3
- package/src/overwrites/venia-ui/lib/components/FilterModal/CurrentFilters/currentFilters.js +2 -2
- package/src/overwrites/venia-ui/lib/components/ProductFullDetail/productFullDetail.js +1 -1
- package/src/talons/LegoSets/legoSets.gql.js +2 -2
- package/src/talons/LegoSets/useLegoSets.js +4 -2
- package/src/talons/NonSportCardsSets/nonSportCardsSets.gql.js +59 -0
- package/src/talons/NonSportCardsSets/useNonSportCardsSets.js +238 -0
- package/src/talons/ShopBy/useShopBy.js +13 -3
- package/src/talons/ShopByVehicles/shopByVehicles.gql.js +59 -0
- package/src/talons/ShopByVehicles/useShopByVehicles.js +222 -0
- package/src/talons/SportCardsSets/sportCardsSets.gql.js +2 -2
- package/src/talons/SportCardsSets/useSportCardsSets.js +10 -10
|
@@ -0,0 +1,238 @@
|
|
|
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 './nonSportCardsSets.gql';
|
|
8
|
+
import { getFilterInput, getFiltersFromSearch } from '@magento/peregrine/lib/talons/FilterModal/helpers';
|
|
9
|
+
|
|
10
|
+
export const useNonSportCardsSets = 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, getNonSportCardsSetsQuery, getCategoryContentQuery, getFilterInputsQuery } = operations;
|
|
18
|
+
const { pathname, search } = useLocation();
|
|
19
|
+
const [runQuery, queryResponse] = useLazyQuery(getNonSportCardsSetsQuery, {
|
|
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(getNonSportCardsSetsQuery, {
|
|
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
|
+
setType: setType,
|
|
96
|
+
shopby: shopby
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
// }
|
|
100
|
+
}, [
|
|
101
|
+
runQuery,
|
|
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
|
+
const nonSportCardsSets = useMemo(() => {
|
|
118
|
+
if (!queryResponse) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const nonSportCardsSets = queryResponse?.data?.nonSportCardsSets;
|
|
123
|
+
if (!nonSportCardsSets) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// const sortbyData = [];
|
|
128
|
+
// if (nonSportCardsSets) {
|
|
129
|
+
// nonSportCardsSets.map((setRelease, index) => {
|
|
130
|
+
// const { group, sets } = setRelease;
|
|
131
|
+
// if (sets.length) {
|
|
132
|
+
// sets.map((set, index) => {
|
|
133
|
+
// const { release_year } = set;
|
|
134
|
+
// // if (release_year) {
|
|
135
|
+
// // // groupingSetsByYear.splice(release_year, 0, set);
|
|
136
|
+
// // const result = sortbyData.find(item => item.group === release_year);
|
|
137
|
+
|
|
138
|
+
// // // groupingSetsByYear[release_year] = set;
|
|
139
|
+
// // if (result) {
|
|
140
|
+
// // result.sets.push(set)
|
|
141
|
+
// // } else {
|
|
142
|
+
// // // if (sortby == "date" || sortby == "newest" && sortbyData.length < 2) {
|
|
143
|
+
// // sortbyData.push({
|
|
144
|
+
// // 'group': release_year,
|
|
145
|
+
// // 'sets': [set]
|
|
146
|
+
// // })
|
|
147
|
+
// // // }
|
|
148
|
+
// // }
|
|
149
|
+
// // }
|
|
150
|
+
// })
|
|
151
|
+
// }
|
|
152
|
+
// })
|
|
153
|
+
|
|
154
|
+
return nonSportCardsSets.slice().sort((a, b) => b.group.toLowerCase().localeCompare(a.group.toLowerCase()));
|
|
155
|
+
}, [queryResponse]);
|
|
156
|
+
|
|
157
|
+
const availableGroups = nonSportCardsSets && nonSportCardsSets.length ? nonSportCardsSets.map(({ group }) => group) : [];
|
|
158
|
+
|
|
159
|
+
const filteredNonSportCardsSets = useMemo(() => {
|
|
160
|
+
if (!nonSportCardsSets) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const filteredSets = [];
|
|
165
|
+
|
|
166
|
+
if (searchQuery) {
|
|
167
|
+
|
|
168
|
+
// setActive('all')
|
|
169
|
+
|
|
170
|
+
nonSportCardsSets.map(({ group, sets }, index) => {
|
|
171
|
+
const newSets = sets.filter(function(set) {
|
|
172
|
+
return set.set_name.search(new RegExp(searchQuery, "i")) != -1 || group.search(new RegExp(searchQuery, "i")) != -1;
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
if (newSets && newSets.length) {
|
|
176
|
+
filteredSets.push({
|
|
177
|
+
'group': group,
|
|
178
|
+
'sets': newSets
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// if (activeFilter && activeFilter != "all") {
|
|
185
|
+
// nonSportCardsSets.map(({ group, sets }, index) => {
|
|
186
|
+
// const newSets = sets.filter(function(set) {
|
|
187
|
+
// return set.sc_league == activeFilter;
|
|
188
|
+
// // return set.set_name.includes(searchQuery);
|
|
189
|
+
// });
|
|
190
|
+
|
|
191
|
+
// if (newSets && newSets.length) {
|
|
192
|
+
// filteredSets.push({
|
|
193
|
+
// 'group': group,
|
|
194
|
+
// 'sets': newSets
|
|
195
|
+
// })
|
|
196
|
+
// }
|
|
197
|
+
// })
|
|
198
|
+
// }
|
|
199
|
+
|
|
200
|
+
return searchQuery ? filteredSets : nonSportCardsSets;
|
|
201
|
+
}, [nonSportCardsSets, searchQuery]);
|
|
202
|
+
|
|
203
|
+
// useEffect(() => {
|
|
204
|
+
// setPageLoading(isBackgroundLoading);
|
|
205
|
+
// }, [isBackgroundLoading, setPageLoading]);
|
|
206
|
+
|
|
207
|
+
const { data: categoryData, loading: categoryLoading } = useQuery(
|
|
208
|
+
getCategoryContentQuery,
|
|
209
|
+
{
|
|
210
|
+
fetchPolicy: 'cache-and-network',
|
|
211
|
+
nextFetchPolicy: 'cache-first',
|
|
212
|
+
skip: !categoryId,
|
|
213
|
+
variables: {
|
|
214
|
+
id: categoryId
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
const category =
|
|
220
|
+
categoryData && categoryData.categories.items.length
|
|
221
|
+
? categoryData.categories.items[0]
|
|
222
|
+
: null;
|
|
223
|
+
|
|
224
|
+
const error = queryResponse?.error;
|
|
225
|
+
const loading = queryResponse?.loading;
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
error,
|
|
229
|
+
loading,
|
|
230
|
+
nonSportCardsSets,
|
|
231
|
+
filteredNonSportCardsSets,
|
|
232
|
+
categoryUrlSuffix,
|
|
233
|
+
categoryUrlKey,
|
|
234
|
+
productType,
|
|
235
|
+
availableGroups,
|
|
236
|
+
category
|
|
237
|
+
};
|
|
238
|
+
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useQuery, useLazyQuery } from '@apollo/client';
|
|
2
2
|
import { useEffect, useMemo } from 'react';
|
|
3
3
|
import { useLocation } from 'react-router-dom';
|
|
4
|
-
import { useAppContext } from '@magento/peregrine/lib/context/app';
|
|
5
4
|
|
|
6
5
|
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
7
6
|
import DEFAULT_OPERATIONS from './shopBy.gql';
|
|
@@ -141,6 +140,9 @@ export const useShopBy = props => {
|
|
|
141
140
|
if (!alpha.includes(firstLetter)) {
|
|
142
141
|
firstLetter = '#';
|
|
143
142
|
}
|
|
143
|
+
if (shopby == "trains_gauge" || shopby == "vehicles_scale" || shopby == "lego_theme" || shopby == "lego_subtheme" || shopby == "lego_interest") {
|
|
144
|
+
firstLetter = '#';
|
|
145
|
+
}
|
|
144
146
|
acc[firstLetter] = acc[firstLetter] || [];
|
|
145
147
|
acc[firstLetter].push(item);
|
|
146
148
|
return acc;
|
|
@@ -199,6 +201,9 @@ export const useShopBy = props => {
|
|
|
199
201
|
if (!alpha.includes(firstLetter)) {
|
|
200
202
|
firstLetter = '#';
|
|
201
203
|
}
|
|
204
|
+
if (shopby == "trains_gauge" || shopby == "vehicles_scale" || shopby == "lego_theme" || shopby == "lego_subtheme" || shopby == "lego_interest") {
|
|
205
|
+
firstLetter = '#';
|
|
206
|
+
}
|
|
202
207
|
acc[firstLetter] = acc[firstLetter] || [];
|
|
203
208
|
acc[firstLetter].push(item);
|
|
204
209
|
return acc;
|
|
@@ -210,9 +215,14 @@ export const useShopBy = props => {
|
|
|
210
215
|
|
|
211
216
|
// console.log(dataResult)
|
|
212
217
|
|
|
213
|
-
|
|
218
|
+
let availableGroups = originalDataResult ? Object.keys(originalDataResult).sort() : [];
|
|
214
219
|
|
|
215
|
-
|
|
220
|
+
let filteredAvailableGroups = dataResult ? Object.keys(dataResult).sort() : [];
|
|
221
|
+
|
|
222
|
+
if (shopby == "trains_gauge" || shopby == "vehicles_scale" || shopby == "lego_theme" || shopby == "lego_subtheme" || shopby == "lego_interest") {
|
|
223
|
+
availableGroups = ['#'];
|
|
224
|
+
filteredAvailableGroups = ['#'];
|
|
225
|
+
}
|
|
216
226
|
|
|
217
227
|
|
|
218
228
|
const attributeData = queryResponse?.data?.shopByData && queryResponse?.data?.shopByData.length ? queryResponse.data.shopByData[0] : null
|
|
@@ -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_SHOP_BY_DATA_QUERY = gql`
|
|
15
|
+
query getShopByVehicles($categoryUrlKey: String!, $activeTab: String, $filters: ProductAttributeFilterInput!, $shopby: String, $activeFilter: String) {
|
|
16
|
+
shopByVehicles(categoryUrlKey: $categoryUrlKey, activeTab: $activeTab, filters: $filters, shopby: $shopby, activeFilter: $activeFilter) {
|
|
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
|
+
getShopByVehiclesQuery: GET_SHOP_BY_DATA_QUERY,
|
|
57
|
+
getCategoryContentQuery: GET_CATEGORY_CONTENT,
|
|
58
|
+
getFilterInputsQuery: GET_FILTER_INPUTS,
|
|
59
|
+
};
|
|
@@ -0,0 +1,222 @@
|
|
|
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 './shopByVehicles.gql';
|
|
8
|
+
import { getFilterInput, getFiltersFromSearch } from '@magento/peregrine/lib/talons/FilterModal/helpers';
|
|
9
|
+
|
|
10
|
+
export const useShopByVehicles = 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, getShopByVehiclesQuery, getCategoryContentQuery, getFilterInputsQuery } = operations;
|
|
18
|
+
const { pathname, search } = useLocation();
|
|
19
|
+
const [runQuery, queryResponse] = useLazyQuery(getShopByVehiclesQuery, {
|
|
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(getShopByVehiclesQuery, {
|
|
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
|
+
shopby: shopby,
|
|
97
|
+
activeFilter: activeFilter
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
// }
|
|
101
|
+
}, [
|
|
102
|
+
runQuery,
|
|
103
|
+
activeTab,
|
|
104
|
+
activeFilter
|
|
105
|
+
// queryResponse
|
|
106
|
+
// filterTypeMap,
|
|
107
|
+
// search,
|
|
108
|
+
// newFilters,
|
|
109
|
+
// shopby,
|
|
110
|
+
// categoryUrlKey
|
|
111
|
+
]);
|
|
112
|
+
|
|
113
|
+
const { data: storeConfigData } = useQuery(getStoreConfigData, {
|
|
114
|
+
fetchPolicy: 'cache-and-network',
|
|
115
|
+
nextFetchPolicy: 'cache-first'
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const categoryUrlSuffix = storeConfigData?.storeConfig?.category_url_suffix;
|
|
119
|
+
|
|
120
|
+
// { data: queryResponse, error, loading }
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
// console.log(data)
|
|
125
|
+
|
|
126
|
+
// const isBackgroundLoading = !!data && loading;
|
|
127
|
+
|
|
128
|
+
const availableLeagues = [];
|
|
129
|
+
|
|
130
|
+
// console.log(queryResponse.data)
|
|
131
|
+
|
|
132
|
+
const shopByVehicles = useMemo(() => {
|
|
133
|
+
if (!queryResponse) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// console.log(data)
|
|
138
|
+
|
|
139
|
+
const shopByVehicles = queryResponse?.data?.shopByVehicles;
|
|
140
|
+
if (!shopByVehicles) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return shopByVehicles.slice().sort((a, b) =>a.group.toLowerCase().localeCompare(b.group.toLowerCase()));
|
|
145
|
+
}, [queryResponse]);
|
|
146
|
+
|
|
147
|
+
const availableGroups = shopByVehicles && shopByVehicles.length ? shopByVehicles.map(({ group }) => group) : [];
|
|
148
|
+
|
|
149
|
+
// const availableLeagues = shopByVehicles && shopByVehicles.length ? shopByVehicles.map(({ sets }) => shopByVehicles.map(({ sc_league }) => sc_league)) : [];
|
|
150
|
+
// console.log(availableLeagues)
|
|
151
|
+
// sc_league
|
|
152
|
+
|
|
153
|
+
const filteredShopByVehicles = useMemo(() => {
|
|
154
|
+
if (!shopByVehicles) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const filteredSets = [];
|
|
159
|
+
|
|
160
|
+
if (searchQuery) {
|
|
161
|
+
|
|
162
|
+
// useEffect(() => {
|
|
163
|
+
// setActive('all')
|
|
164
|
+
// }, [active]);
|
|
165
|
+
|
|
166
|
+
shopByVehicles.map(({ group, sets }, index) => {
|
|
167
|
+
const newSets = sets.filter(function(set) {
|
|
168
|
+
return set.set_name.search(new RegExp(searchQuery, "i")) != -1 || group.search(new RegExp(searchQuery, "i")) != -1;
|
|
169
|
+
// return set.set_name.includes(searchQuery);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
if (newSets && newSets.length) {
|
|
173
|
+
filteredSets.push({
|
|
174
|
+
'group': group,
|
|
175
|
+
'sets': newSets
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return searchQuery ? filteredSets : shopByVehicles;
|
|
182
|
+
}, [shopByVehicles, searchQuery]);
|
|
183
|
+
|
|
184
|
+
// useEffect(() => {
|
|
185
|
+
// setPageLoading(isBackgroundLoading);
|
|
186
|
+
// }, [isBackgroundLoading, setPageLoading]);
|
|
187
|
+
|
|
188
|
+
const { data: categoryData, loading: categoryLoading } = useQuery(
|
|
189
|
+
getCategoryContentQuery,
|
|
190
|
+
{
|
|
191
|
+
fetchPolicy: 'cache-and-network',
|
|
192
|
+
nextFetchPolicy: 'cache-first',
|
|
193
|
+
skip: !categoryId,
|
|
194
|
+
variables: {
|
|
195
|
+
id: categoryId
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
const category =
|
|
201
|
+
categoryData && categoryData.categories.items.length
|
|
202
|
+
? categoryData.categories.items[0]
|
|
203
|
+
: null;
|
|
204
|
+
|
|
205
|
+
const error = queryResponse?.error;
|
|
206
|
+
const loading = queryResponse?.loading;
|
|
207
|
+
|
|
208
|
+
// console.log(shopByVehicles)
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
error,
|
|
212
|
+
loading,
|
|
213
|
+
shopByVehicles,
|
|
214
|
+
filteredShopByVehicles,
|
|
215
|
+
categoryUrlSuffix,
|
|
216
|
+
categoryUrlKey,
|
|
217
|
+
productType,
|
|
218
|
+
availableGroups,
|
|
219
|
+
category,
|
|
220
|
+
// availableLeagues
|
|
221
|
+
};
|
|
222
|
+
};
|
|
@@ -12,8 +12,8 @@ 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, $filters: ProductAttributeFilterInput!) {
|
|
16
|
-
sportCardsSets(categoryUrlKey: $categoryUrlKey, setType: $setType, filters: $filters) {
|
|
15
|
+
query getSportCardsSets($categoryUrlKey: String!, $shopby: String, $setType: String, $filters: ProductAttributeFilterInput!) {
|
|
16
|
+
sportCardsSets(categoryUrlKey: $categoryUrlKey, shopby: $shopby, setType: $setType, filters: $filters) {
|
|
17
17
|
group
|
|
18
18
|
sets {
|
|
19
19
|
set_name
|
|
@@ -66,12 +66,12 @@ export const useSportCardsSets = props => {
|
|
|
66
66
|
// console.log(item.split(',')[0])
|
|
67
67
|
const data = search.split('&');
|
|
68
68
|
data.pop();
|
|
69
|
-
activeFilters.push(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
)
|
|
69
|
+
// activeFilters.push(
|
|
70
|
+
// {
|
|
71
|
+
// 'label': item.split(',')[0],
|
|
72
|
+
// 'path': data
|
|
73
|
+
// }
|
|
74
|
+
// )
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -92,7 +92,8 @@ export const useSportCardsSets = props => {
|
|
|
92
92
|
variables: {
|
|
93
93
|
filters: newFilters,
|
|
94
94
|
categoryUrlKey: categoryUrlKey,
|
|
95
|
-
setType: setType
|
|
95
|
+
setType: setType,
|
|
96
|
+
shopby: shopby
|
|
96
97
|
}
|
|
97
98
|
});
|
|
98
99
|
// }
|
|
@@ -173,7 +174,7 @@ export const useSportCardsSets = props => {
|
|
|
173
174
|
})
|
|
174
175
|
}
|
|
175
176
|
|
|
176
|
-
return sportCardsSets.slice().sort((a, b) => b.group.toLowerCase().localeCompare(a.group.toLowerCase()));
|
|
177
|
+
return sortby == "release" ? sportCardsSets.slice().sort((a, b) => b.group.toLowerCase().localeCompare(a.group.toLowerCase())) : sportCardsSets.slice().sort((a, b) => a.group.toLowerCase().localeCompare(b.group.toLowerCase()));
|
|
177
178
|
}, [queryResponse, activeTab]);
|
|
178
179
|
|
|
179
180
|
const availableGroups = sportCardsSets && sportCardsSets.length ? sportCardsSets.map(({ group }) => group) : [];
|
|
@@ -191,12 +192,11 @@ export const useSportCardsSets = props => {
|
|
|
191
192
|
|
|
192
193
|
if (searchQuery) {
|
|
193
194
|
|
|
194
|
-
setActive('all')
|
|
195
|
+
// setActive('all')
|
|
195
196
|
|
|
196
197
|
sportCardsSets.map(({ group, sets }, index) => {
|
|
197
198
|
const newSets = sets.filter(function(set) {
|
|
198
199
|
return set.set_name.search(new RegExp(searchQuery, "i")) != -1 || group.search(new RegExp(searchQuery, "i")) != -1;
|
|
199
|
-
// return set.set_name.includes(searchQuery);
|
|
200
200
|
});
|
|
201
201
|
|
|
202
202
|
if (newSets && newSets.length) {
|