@riosst100/pwa-marketplace 1.6.2 → 1.6.3
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/AlphaFilter/alphaFilter.js +23 -6
- package/src/components/ArraySearchInput/arraySearchInput.js +100 -0
- package/src/components/ArraySearchInput/arraySearchInput.module.css +48 -0
- package/src/components/ArraySearchInput/index.js +1 -0
- package/src/components/CollectibleGameSets/collectibleGameSets.js +53 -25
- package/src/components/CollectibleGameSets/collectibleGameSets.module.css +8 -0
- package/src/components/CustomSortBy/customSortBy.js +9 -11
- package/src/components/CustomSubCategory/subCategory.js +2 -1
- package/src/components/FilterTop/FilterBlockList/filterTopItemGroup.module.css +1 -1
- package/src/components/FilterTop/filterTop.js +1 -1
- package/src/components/ShopBy/index.js +2 -0
- package/src/components/ShopBy/shopBy.js +237 -0
- package/src/components/ShopBy/shopBy.module.css +46 -0
- package/src/components/ShopBy/shopBy.shimmer.js +50 -0
- package/src/components/ShopByPage/index.js +1 -0
- package/src/components/ShopByPage/shopByPage.js +12 -0
- package/src/hooks/useCustomSort.js +21 -0
- package/src/intercept.js +1 -8
- package/src/overwrites/peregrine/lib/talons/FilterSidebar/useFilterSidebar.js +2 -2
- package/src/overwrites/peregrine/lib/talons/RootComponents/Category/categoryContent.gql.js +1 -0
- package/src/overwrites/peregrine/lib/talons/RootComponents/Category/categoryFragments.gql.js +31 -0
- package/src/overwrites/venia-ui/lib/RootComponents/Category/category.js +13 -2
- package/src/overwrites/venia-ui/lib/RootComponents/Category/categoryContent.js +30 -5
- package/src/overwrites/venia-ui/lib/components/FilterSidebar/filterSidebar.js +5 -5
- package/src/overwrites/venia-ui/lib/components/Gallery/gallery.js +3 -3
- package/src/talons/ArraySearchInput/useArraySearchInput.js +58 -0
- package/src/talons/CollectibleGameSets/useCollectibleGameSets.js +75 -2
- package/src/talons/ShopBy/shopBy.gql.js +47 -0
- package/src/talons/ShopBy/useShopBy.js +171 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
import { useHistory } from 'react-router-dom';
|
|
3
|
+
|
|
4
|
+
import { useDropdown } from '@magento/peregrine/lib/hooks/useDropdown';
|
|
5
|
+
|
|
6
|
+
const initialValues = { search_query: '' };
|
|
7
|
+
|
|
8
|
+
export const useArraySearchInput = props => {
|
|
9
|
+
const { active } = props
|
|
10
|
+
const [valid, setValid] = useState(false);
|
|
11
|
+
const {
|
|
12
|
+
elementRef,
|
|
13
|
+
expanded: isAutoCompleteOpen,
|
|
14
|
+
setExpanded: setIsAutoCompleteOpen
|
|
15
|
+
} = useDropdown();
|
|
16
|
+
const history = useHistory();
|
|
17
|
+
const { push } = history;
|
|
18
|
+
|
|
19
|
+
// expand or collapse on input change
|
|
20
|
+
const handleChange = useCallback(
|
|
21
|
+
value => {
|
|
22
|
+
const hasValue = !!value;
|
|
23
|
+
const isValid = hasValue && value.length > 2;
|
|
24
|
+
|
|
25
|
+
setValid(isValid);
|
|
26
|
+
setIsAutoCompleteOpen(hasValue);
|
|
27
|
+
},
|
|
28
|
+
[setIsAutoCompleteOpen, setValid]
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// expand on focus
|
|
32
|
+
const handleFocus = useCallback(() => {
|
|
33
|
+
setIsAutoCompleteOpen(true);
|
|
34
|
+
}, [setIsAutoCompleteOpen]);
|
|
35
|
+
|
|
36
|
+
// navigate on submit
|
|
37
|
+
const handleSubmit = useCallback(
|
|
38
|
+
({ search_query }) => {
|
|
39
|
+
if (search_query != null && search_query.trim().length > 0) {
|
|
40
|
+
push(`/search.html?query=${search_query}`);
|
|
41
|
+
setIsAutoCompleteOpen(false);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
[push, setIsAutoCompleteOpen]
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
containerRef: elementRef,
|
|
49
|
+
handleChange,
|
|
50
|
+
handleFocus,
|
|
51
|
+
handleSubmit,
|
|
52
|
+
initialValues,
|
|
53
|
+
isAutoCompleteOpen,
|
|
54
|
+
setIsAutoCompleteOpen,
|
|
55
|
+
setValid,
|
|
56
|
+
valid
|
|
57
|
+
};
|
|
58
|
+
};
|
|
@@ -8,6 +8,10 @@ import DEFAULT_OPERATIONS from './collectibleGameSets.gql';
|
|
|
8
8
|
|
|
9
9
|
export const useCollectibleGameSets = props => {
|
|
10
10
|
|
|
11
|
+
const { searchQuery, setActive, currentSort } = props
|
|
12
|
+
|
|
13
|
+
const { value: sortby } = currentSort
|
|
14
|
+
|
|
11
15
|
const operations = mergeOperations(DEFAULT_OPERATIONS, null);
|
|
12
16
|
const { getStoreConfigData, getCollectibleGameQuery } = operations;
|
|
13
17
|
const { pathname } = useLocation();
|
|
@@ -23,6 +27,8 @@ export const useCollectibleGameSets = props => {
|
|
|
23
27
|
nextFetchPolicy: 'cache-first'
|
|
24
28
|
});
|
|
25
29
|
|
|
30
|
+
// console.log(sortby)
|
|
31
|
+
|
|
26
32
|
const pathnameArr = pathname.split('/');
|
|
27
33
|
|
|
28
34
|
const categoryUrlKey = pathnameArr[pathnameArr.length - 2].replace('.html','');
|
|
@@ -52,8 +58,74 @@ export const useCollectibleGameSets = props => {
|
|
|
52
58
|
return null;
|
|
53
59
|
}
|
|
54
60
|
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
// console.log(sortby)
|
|
62
|
+
|
|
63
|
+
const sortbyData = [];
|
|
64
|
+
if (sortby != 'all') {
|
|
65
|
+
collectibleGameSets.map((setRelease, index) => {
|
|
66
|
+
const { release_type, sets } = setRelease;
|
|
67
|
+
if (sets.length) {
|
|
68
|
+
sets.map((set, index) => {
|
|
69
|
+
const { release_year } = set;
|
|
70
|
+
if (release_year) {
|
|
71
|
+
// groupingSetsByYear.splice(release_year, 0, set);
|
|
72
|
+
const result = sortbyData.find(item => item.release_type === release_year);
|
|
73
|
+
|
|
74
|
+
// console.log(result)
|
|
75
|
+
// groupingSetsByYear[release_year] = set;
|
|
76
|
+
if (result) {
|
|
77
|
+
result.sets.push(set)
|
|
78
|
+
} else {
|
|
79
|
+
if (sortby == "date" || sortby == "newest" && sortbyData.length <= 5) {
|
|
80
|
+
sortbyData.push({
|
|
81
|
+
'release_type': release_year,
|
|
82
|
+
'sets': [set]
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return sortby != "all" ? sortbyData && sortbyData.length ? sortbyData.sort((a, b) => b.release_type.toLowerCase().localeCompare(a.release_type.toLowerCase())) : sortbyData : collectibleGameSets.slice().sort((a, b) => a.release_type.toLowerCase().localeCompare(b.release_type.toLowerCase()));
|
|
93
|
+
}, [data, sortby]);
|
|
94
|
+
|
|
95
|
+
// console.log(collectibleGameSets)
|
|
96
|
+
|
|
97
|
+
const filteredCollectibleGameSets = useMemo(() => {
|
|
98
|
+
if (!collectibleGameSets) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const filteredSets = [];
|
|
103
|
+
|
|
104
|
+
if (searchQuery) {
|
|
105
|
+
|
|
106
|
+
setActive('all')
|
|
107
|
+
|
|
108
|
+
collectibleGameSets.map(({ release_type, sets }, index) => {
|
|
109
|
+
|
|
110
|
+
// console.log(sets)
|
|
111
|
+
const newSets = sets.filter(function(set) {
|
|
112
|
+
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;
|
|
113
|
+
// return set.set_name.includes(searchQuery);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
if (newSets && newSets.length) {
|
|
117
|
+
filteredSets.push({
|
|
118
|
+
'release_type': sortby == "date" ? set.release_year : release_type,
|
|
119
|
+
'sets': newSets
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
// console.log(filteredSets)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return searchQuery ? filteredSets : collectibleGameSets;
|
|
128
|
+
}, [collectibleGameSets, searchQuery, sortby]);
|
|
57
129
|
|
|
58
130
|
useEffect(() => {
|
|
59
131
|
setPageLoading(isBackgroundLoading);
|
|
@@ -63,6 +135,7 @@ export const useCollectibleGameSets = props => {
|
|
|
63
135
|
error,
|
|
64
136
|
loading,
|
|
65
137
|
collectibleGameSets,
|
|
138
|
+
filteredCollectibleGameSets,
|
|
66
139
|
categoryUrlSuffix,
|
|
67
140
|
categoryUrlKey,
|
|
68
141
|
productType
|
|
@@ -0,0 +1,47 @@
|
|
|
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 getShopByData($categoryUrlKey: String!, $attributeCode: String) {
|
|
16
|
+
shopByData(categoryUrlKey: $categoryUrlKey, attributeCode: $attributeCode) {
|
|
17
|
+
label
|
|
18
|
+
count
|
|
19
|
+
attribute_code
|
|
20
|
+
options {
|
|
21
|
+
label
|
|
22
|
+
value
|
|
23
|
+
}
|
|
24
|
+
position
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
export const GET_CATEGORY_CONTENT = gql`
|
|
30
|
+
query getCategoryData($id: String!) {
|
|
31
|
+
categories(filters: { category_uid: { in: [$id] } }) {
|
|
32
|
+
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
33
|
+
items {
|
|
34
|
+
uid
|
|
35
|
+
name
|
|
36
|
+
url_key
|
|
37
|
+
url_path
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
export default {
|
|
44
|
+
getStoreConfigData: GET_STORE_CONFIG_DATA,
|
|
45
|
+
getShopByDataQuery: GET_SHOP_BY_DATA_QUERY,
|
|
46
|
+
getCategoryContentQuery: GET_CATEGORY_CONTENT
|
|
47
|
+
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { useQuery } 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 './shopBy.gql';
|
|
8
|
+
|
|
9
|
+
export const useShopBy = props => {
|
|
10
|
+
|
|
11
|
+
const { searchQuery, setActive, currentSort, categoryId, shopby } = props
|
|
12
|
+
|
|
13
|
+
const { value: sortby } = currentSort
|
|
14
|
+
|
|
15
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, null);
|
|
16
|
+
const { getStoreConfigData, getShopByDataQuery, getCategoryContentQuery } = operations;
|
|
17
|
+
const { pathname } = useLocation();
|
|
18
|
+
// const [
|
|
19
|
+
// ,
|
|
20
|
+
// {
|
|
21
|
+
// actions: { setPageLoading }
|
|
22
|
+
// }
|
|
23
|
+
// ] = useAppContext();
|
|
24
|
+
|
|
25
|
+
const { data: storeConfigData } = useQuery(getStoreConfigData, {
|
|
26
|
+
fetchPolicy: 'cache-and-network',
|
|
27
|
+
nextFetchPolicy: 'cache-first'
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
// // console.log(sortby)
|
|
33
|
+
|
|
34
|
+
const pathnameArr = pathname.split('/');
|
|
35
|
+
|
|
36
|
+
const categoryUrlKey = pathnameArr[pathnameArr.length - 1].replace('.html','');
|
|
37
|
+
|
|
38
|
+
const categoryUrlSuffix = storeConfigData?.storeConfig?.category_url_suffix;
|
|
39
|
+
|
|
40
|
+
const { error, loading, data } = useQuery(getShopByDataQuery, {
|
|
41
|
+
fetchPolicy: 'cache-and-network',
|
|
42
|
+
nextFetchPolicy: 'cache-first',
|
|
43
|
+
skip: !storeConfigData,
|
|
44
|
+
variables: {
|
|
45
|
+
categoryUrlKey: categoryUrlKey,
|
|
46
|
+
attributeCode: shopby
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
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'];
|
|
51
|
+
|
|
52
|
+
// const isBackgroundLoading = !!data && loading;
|
|
53
|
+
|
|
54
|
+
const originalDataResult = useMemo(() => {
|
|
55
|
+
if (!data) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// console.log(data)
|
|
60
|
+
|
|
61
|
+
const rawData = data.shopByData;
|
|
62
|
+
if (!rawData) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// console.log(rawData)
|
|
67
|
+
|
|
68
|
+
let options = rawData[0].options;
|
|
69
|
+
|
|
70
|
+
const mappingData = options.reduce((acc, item) => {
|
|
71
|
+
// console.log(item)
|
|
72
|
+
let firstLetter = item.label.charAt(0).toUpperCase();
|
|
73
|
+
if (!alpha.includes(firstLetter)) {
|
|
74
|
+
firstLetter = '#';
|
|
75
|
+
}
|
|
76
|
+
acc[firstLetter] = acc[firstLetter] || [];
|
|
77
|
+
acc[firstLetter].push(item);
|
|
78
|
+
return acc;
|
|
79
|
+
}, {});
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
// console.log(mappingData)
|
|
84
|
+
|
|
85
|
+
const sortbyData = [];
|
|
86
|
+
|
|
87
|
+
return sortby != "all" ? sortbyData && sortbyData.length ? sortbyData.sort((a, b) => b.release_type.toLowerCase().localeCompare(a.release_type.toLowerCase())) : sortbyData : mappingData;
|
|
88
|
+
}, [data, sortby, searchQuery]);
|
|
89
|
+
|
|
90
|
+
const dataResult = useMemo(() => {
|
|
91
|
+
if (!data) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// console.log(data)
|
|
96
|
+
|
|
97
|
+
const rawData = data.shopByData;
|
|
98
|
+
if (!rawData) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// console.log(rawData)
|
|
103
|
+
|
|
104
|
+
let options = rawData[0].options;
|
|
105
|
+
|
|
106
|
+
if (searchQuery) {
|
|
107
|
+
setActive('all')
|
|
108
|
+
options = options.filter(function(option) {
|
|
109
|
+
return option.label.search(new RegExp(searchQuery, "i")) != -1;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const mappingData = options.reduce((acc, item) => {
|
|
114
|
+
// console.log(item)
|
|
115
|
+
let firstLetter = item.label.charAt(0).toUpperCase();
|
|
116
|
+
if (!alpha.includes(firstLetter)) {
|
|
117
|
+
firstLetter = '#';
|
|
118
|
+
}
|
|
119
|
+
acc[firstLetter] = acc[firstLetter] || [];
|
|
120
|
+
acc[firstLetter].push(item);
|
|
121
|
+
return acc;
|
|
122
|
+
}, {});
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
// console.log(mappingData)
|
|
127
|
+
|
|
128
|
+
const sortbyData = [];
|
|
129
|
+
|
|
130
|
+
return sortby != "all" ? sortbyData && sortbyData.length ? sortbyData.sort((a, b) => b.release_type.toLowerCase().localeCompare(a.release_type.toLowerCase())) : sortbyData : mappingData;
|
|
131
|
+
}, [data, sortby, searchQuery]);
|
|
132
|
+
|
|
133
|
+
const availableGroups = originalDataResult ? Object.keys(originalDataResult).sort() : [];
|
|
134
|
+
|
|
135
|
+
const filteredAvailableGroups = dataResult ? Object.keys(dataResult).sort() : [];
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
const attributeData = data ? data.shopByData[0] : null
|
|
139
|
+
|
|
140
|
+
const { data: categoryData, loading: categoryLoading } = useQuery(
|
|
141
|
+
getCategoryContentQuery,
|
|
142
|
+
{
|
|
143
|
+
fetchPolicy: 'cache-and-network',
|
|
144
|
+
nextFetchPolicy: 'cache-first',
|
|
145
|
+
skip: !categoryId,
|
|
146
|
+
variables: {
|
|
147
|
+
id: categoryId
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const category =
|
|
153
|
+
categoryData && categoryData.categories.items.length
|
|
154
|
+
? categoryData.categories.items[0]
|
|
155
|
+
: null;
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
error,
|
|
159
|
+
loading,
|
|
160
|
+
dataResult,
|
|
161
|
+
// collectibleGameSets,
|
|
162
|
+
filteredAvailableGroups,
|
|
163
|
+
categoryUrlSuffix,
|
|
164
|
+
categoryUrlKey,
|
|
165
|
+
availableGroups,
|
|
166
|
+
attributeData,
|
|
167
|
+
alpha,
|
|
168
|
+
category
|
|
169
|
+
// productType
|
|
170
|
+
};
|
|
171
|
+
};
|