@riosst100/pwa-marketplace 2.0.7 → 2.0.8
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/ShopByCard/index.js +2 -0
- package/src/components/ShopByCard/shopByCard.js +277 -0
- package/src/components/ShopByCard/shopByCard.module.css +76 -0
- package/src/components/ShopByCard/shopByCard.shimmer.js +50 -0
- package/src/overwrites/venia-ui/lib/RootComponents/Category/category.js +4 -0
- package/src/talons/ShopByCard/shopByCard.gql.js +47 -0
- package/src/talons/ShopByCard/useShopByCard.js +134 -0
- package/src/talons/SportCardsSets/useSportCardsSets.js +1 -1
package/package.json
CHANGED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import React, { Fragment, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import ErrorView from '@magento/venia-ui/lib/components/ErrorView';
|
|
3
|
+
import { StoreTitle, Meta } from '@magento/venia-ui/lib/components/Head';
|
|
4
|
+
import { useShopByCard } from '@riosst100/pwa-marketplace/src/talons/ShopByCard/useShopByCard';
|
|
5
|
+
import { Link } from 'react-router-dom';
|
|
6
|
+
import resourceUrl from '@magento/peregrine/lib/util/makeUrl';
|
|
7
|
+
import defaultClasses from './shopByCard.module.css';
|
|
8
|
+
import { useStyle } from '@magento/venia-ui/lib/classify';
|
|
9
|
+
import cn from 'classnames';
|
|
10
|
+
import Divider from '@riosst100/pwa-marketplace/src/components/Divider';
|
|
11
|
+
import { ShopByCardShimmer } from '@riosst100/pwa-marketplace/src/components/ShopByCard';
|
|
12
|
+
import CustomSortBy from '@riosst100/pwa-marketplace/src/components/CustomSortBy';
|
|
13
|
+
import ArraySearchInput from '@riosst100/pwa-marketplace/src/components/ArraySearchInput';
|
|
14
|
+
import { useCustomSort } from '@riosst100/pwa-marketplace/src/hooks/useCustomSort';
|
|
15
|
+
import Breadcrumbs from '@magento/venia-ui/lib/components/Breadcrumbs';
|
|
16
|
+
|
|
17
|
+
const ShopByCard = props => {
|
|
18
|
+
const { categoryId } = props
|
|
19
|
+
|
|
20
|
+
const [active, setActive] = useState('all');
|
|
21
|
+
|
|
22
|
+
const [searchQuery, setSearchQuery] = useState('');
|
|
23
|
+
|
|
24
|
+
const { location } = globalThis;
|
|
25
|
+
|
|
26
|
+
const query = new URLSearchParams(location.search);
|
|
27
|
+
const shopby = query.get('shopby') || null;
|
|
28
|
+
|
|
29
|
+
let defaultSort = {
|
|
30
|
+
sortText: 'All (A-Z)',
|
|
31
|
+
value: 'all'
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (shopby == "release_year") {
|
|
35
|
+
defaultSort = {
|
|
36
|
+
sortText: 'All (By Year)',
|
|
37
|
+
value: 'date'
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// if (productType == "expansion_sets") {
|
|
42
|
+
// defaultSort = {
|
|
43
|
+
// sortText: 'All (Expansion Sets)',
|
|
44
|
+
// value: 'all'
|
|
45
|
+
// };
|
|
46
|
+
// }
|
|
47
|
+
|
|
48
|
+
const sortProps = useCustomSort({ sortFromSearch: false, defaultSort: defaultSort});
|
|
49
|
+
|
|
50
|
+
const [currentSort] = sortProps;
|
|
51
|
+
|
|
52
|
+
// const [sortBy, setSortBy] = useState({
|
|
53
|
+
// sortText: 'All (A-Z)',
|
|
54
|
+
// value: 'all'
|
|
55
|
+
// });
|
|
56
|
+
|
|
57
|
+
const classes = useStyle(defaultClasses);
|
|
58
|
+
|
|
59
|
+
const talonProps = useShopByCard({ searchQuery, setActive, currentSort, shopby });
|
|
60
|
+
|
|
61
|
+
const { error, loading, shopByCard, categoryUrlSuffix, categoryUrlKey, productType, filteredShopByCard, availableGroups } = talonProps;
|
|
62
|
+
|
|
63
|
+
if (loading && !shopByCard)
|
|
64
|
+
return <ShopByCardShimmer />;
|
|
65
|
+
if (error && !shopByCard) return <ErrorView />;
|
|
66
|
+
|
|
67
|
+
if (!shopByCard && !loading && !error) {
|
|
68
|
+
return <ShopByCardShimmer />;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const setsLengthArr = [];
|
|
72
|
+
|
|
73
|
+
const newShopByCard = searchQuery ? filteredShopByCard : shopByCard;
|
|
74
|
+
|
|
75
|
+
// useEffect(() => {
|
|
76
|
+
if (shopByCard && shopByCard.length) {
|
|
77
|
+
shopByCard.map((setRelease, index) => {
|
|
78
|
+
const { release_type, sets } = setRelease;
|
|
79
|
+
|
|
80
|
+
setsLengthArr[release_type] = sets.length
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
// }, [shopByCard])
|
|
84
|
+
|
|
85
|
+
const splitToNChunks = (array, n) => {
|
|
86
|
+
let result = [];
|
|
87
|
+
for (let i = n; i > 0; i--) {
|
|
88
|
+
result.push(array.splice(0, Math.ceil(array.length / i)));
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const setRelases = newShopByCard.length && newShopByCard.map((setRelease, index) => {
|
|
94
|
+
const { release_type, sets } = setRelease;
|
|
95
|
+
|
|
96
|
+
const setsResult = [];
|
|
97
|
+
|
|
98
|
+
if (sets.length) {
|
|
99
|
+
sets.map((set, index) => {
|
|
100
|
+
const { set_name, option_id, set_abbreviation, release_year } = set;
|
|
101
|
+
|
|
102
|
+
const categoryUrl = resourceUrl(
|
|
103
|
+
`/games/collectible-game/${categoryUrlKey}${categoryUrlSuffix || ''}?card_name[filter]=${set_name},${option_id}`
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
setsResult.push(<li className='list-none'>
|
|
107
|
+
<Link to={categoryUrl} className="hover_bg-darkblue-900 hover_text-white w-full block text-[14px] py-[2px] px-2">
|
|
108
|
+
{set_name} <small style={{"color":"grey"}}>{set_abbreviation}</small>
|
|
109
|
+
</Link>
|
|
110
|
+
</li>)
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let setsResultSplitted = [];
|
|
115
|
+
if (active == release_type || newShopByCard.length == 1) {
|
|
116
|
+
setsResultSplitted = splitToNChunks(setsResult, 3);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<>
|
|
121
|
+
{active == "all" && newShopByCard.length > 1 ?
|
|
122
|
+
<div className={cn('singles_group-wrapper mb-4 px-2 inline-block', classes.singlesGroupWrapper)}>
|
|
123
|
+
<div className='singles_item_group_letter text-xl font-medium border-b border-gray-100 pb-1 mb-2' >
|
|
124
|
+
{release_type}
|
|
125
|
+
</div>
|
|
126
|
+
<div className={cn('singles_item-list flex flex-col')}>{setsResult}</div>
|
|
127
|
+
</div> : ''}
|
|
128
|
+
{active == release_type || newShopByCard.length == 1 ? setsResultSplitted && setsResultSplitted.length && setsResultSplitted.map((setsResult, index) =>
|
|
129
|
+
<div key={index} className={cn('singles_group-wrapper mb-4 px-2 inline-block', classes.singlesGroupWrapper)}>
|
|
130
|
+
{index == 0 ? <div className='singles_item_group_letter text-xl font-medium border-b border-gray-100 pb-1 mb-2'>{release_type}</div> :
|
|
131
|
+
<div className='singles_item_group_letter text-xl font-medium pb-1 mb-2' style={{"marginTop":"35px"}}></div>}
|
|
132
|
+
<div className={cn('singles_item-list flex flex-col')}>{setsResult}</div>
|
|
133
|
+
</div>
|
|
134
|
+
)
|
|
135
|
+
: ''}
|
|
136
|
+
</>
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const handleActive = (val) => {
|
|
141
|
+
setActive(val);
|
|
142
|
+
|
|
143
|
+
//
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
setSearchQuery('')
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let 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'];
|
|
150
|
+
|
|
151
|
+
let availableSortBy = [
|
|
152
|
+
{
|
|
153
|
+
'label': 'All (A-Z)',
|
|
154
|
+
'value': 'all'
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
'label': 'Latest Sets',
|
|
158
|
+
'value': 'newest'
|
|
159
|
+
}
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
if (shopby == "release_year") {
|
|
163
|
+
availableSortBy = [
|
|
164
|
+
{
|
|
165
|
+
'label': 'All (By Year)',
|
|
166
|
+
'value': 'date'
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
'label': 'Latest Sets',
|
|
170
|
+
'value': 'newest'
|
|
171
|
+
}
|
|
172
|
+
];
|
|
173
|
+
|
|
174
|
+
// alpha = availableGroups;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (productType == "expansion_sets") {
|
|
178
|
+
// availableSortBy = [
|
|
179
|
+
// {
|
|
180
|
+
// 'label': 'All (Expansion Sets)',
|
|
181
|
+
// 'value': 'all'
|
|
182
|
+
// },
|
|
183
|
+
// {
|
|
184
|
+
// 'label': 'Latest Sets',
|
|
185
|
+
// 'value': 'newest'
|
|
186
|
+
// }
|
|
187
|
+
// ];
|
|
188
|
+
|
|
189
|
+
// alpha = availableGroups
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
let title = "By Card Name";
|
|
193
|
+
|
|
194
|
+
return (
|
|
195
|
+
<Fragment>
|
|
196
|
+
<StoreTitle>{title}</StoreTitle>
|
|
197
|
+
<Breadcrumbs categoryId={categoryId} customPage={title} />
|
|
198
|
+
{shopby != "release_year" && productType != "expansion_sets" && <h1 className='mx-auto relative block text-xl font-bold text-center pt-10 pb-4'>
|
|
199
|
+
{title}
|
|
200
|
+
</h1>}
|
|
201
|
+
{shopby == "release_year" || productType == "expansion_sets" ? <ul className={classes.nav}>
|
|
202
|
+
{availableGroups.map((group, index) => (
|
|
203
|
+
<li key={index} className={classes.nav_item}>
|
|
204
|
+
<button
|
|
205
|
+
onClick={() => {
|
|
206
|
+
handleActive(group)
|
|
207
|
+
}}
|
|
208
|
+
>
|
|
209
|
+
{active == group ? <b>{group}</b> : group}
|
|
210
|
+
</button>
|
|
211
|
+
</li>
|
|
212
|
+
))}
|
|
213
|
+
<li className={classes.nav_item}>
|
|
214
|
+
<button
|
|
215
|
+
onClick={() => {
|
|
216
|
+
handleActive('all')
|
|
217
|
+
}}
|
|
218
|
+
>
|
|
219
|
+
{active == 'all' ? <b>All</b> : 'All'}
|
|
220
|
+
</button>
|
|
221
|
+
</li>
|
|
222
|
+
</ul> : ''}
|
|
223
|
+
<div className='border border-gray-100 px-6'>
|
|
224
|
+
{shopByCard ? (
|
|
225
|
+
<div
|
|
226
|
+
className={classes.toolbar}
|
|
227
|
+
>
|
|
228
|
+
<div style={{"width":"35%"}}><ArraySearchInput active={active} searchQuery={searchQuery} placeholder="Search sets..." isOpen={true} setSearchQuery={setSearchQuery} /></div>
|
|
229
|
+
<CustomSortBy sortProps={sortProps} availableSortMethods={availableSortBy} />
|
|
230
|
+
</div>
|
|
231
|
+
) : ''}
|
|
232
|
+
<section className='single_list-indexing-container relative m-auto pt-5'>
|
|
233
|
+
<ul className='flex gap-2 justify-center flex-wrap'>
|
|
234
|
+
<li>
|
|
235
|
+
<button
|
|
236
|
+
className={cn(
|
|
237
|
+
'rounded-md border border-solid border-gray-100 p-2 min-w-[28px]',
|
|
238
|
+
'leading-4 font-medium text-base hover_bg-gray-50'
|
|
239
|
+
)}
|
|
240
|
+
onClick={() => {
|
|
241
|
+
handleActive('all')
|
|
242
|
+
}}
|
|
243
|
+
>
|
|
244
|
+
{active == 'all' ? <b>All</b> : 'All'}
|
|
245
|
+
</button>
|
|
246
|
+
</li>
|
|
247
|
+
{alpha.map((letter, index) => (
|
|
248
|
+
<li key={index}>
|
|
249
|
+
<button
|
|
250
|
+
className={cn(
|
|
251
|
+
'rounded-md border border-solid border-gray-100 p-2 min-w-[28px]',
|
|
252
|
+
'leading-4 font-medium text-base ',
|
|
253
|
+
setsLengthArr[letter] > 0 ? 'hover_bg-gray-50' : 'bg-gray-100 text-gray-400',
|
|
254
|
+
)}
|
|
255
|
+
onClick={() => {
|
|
256
|
+
handleActive(letter)
|
|
257
|
+
}}
|
|
258
|
+
disabled={setsLengthArr[letter] > 0 ? false : true}
|
|
259
|
+
>
|
|
260
|
+
{active == letter ? <b>{letter}</b> : letter}
|
|
261
|
+
</button>
|
|
262
|
+
</li>
|
|
263
|
+
))}
|
|
264
|
+
</ul>
|
|
265
|
+
</section>
|
|
266
|
+
<Divider className="mb-5 px-4 mt-5" />
|
|
267
|
+
<section className='singles-container'>
|
|
268
|
+
<div className={cn('singles-wrapper block -mx-4', classes.singlesWrapper)}>
|
|
269
|
+
{newShopByCard && newShopByCard.length ? setRelases : (searchQuery ? <div className='singles_group-wrapper mb-4 px-2 inline-block w-full'>No card found for <b>{searchQuery}</b> search query.</div> : <div className='singles_group-wrapper mb-4 px-2 inline-block w-full'>No card found.</div>)}
|
|
270
|
+
</div>
|
|
271
|
+
</section>
|
|
272
|
+
</div>
|
|
273
|
+
</Fragment>
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export default ShopByCard;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
.nav {
|
|
2
|
+
composes: flex from global;
|
|
3
|
+
composes: flex-wrap from global;
|
|
4
|
+
margin: 50px 0 30px 0;
|
|
5
|
+
composes: gap-[10px] from global;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.nav_item {
|
|
9
|
+
composes: px-4 from global;
|
|
10
|
+
composes: py-2 from global;
|
|
11
|
+
composes: transition-colors from global;
|
|
12
|
+
composes: duration-150 from global;
|
|
13
|
+
composes: border from global;
|
|
14
|
+
composes: border-solid from global;
|
|
15
|
+
composes: leading-normal from global;
|
|
16
|
+
composes: text-base from global;
|
|
17
|
+
composes: text-colorDefault from global;
|
|
18
|
+
composes: bg-white from global;
|
|
19
|
+
composes: border-gray-100 from global;
|
|
20
|
+
border-radius: 5px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.toolbar {
|
|
24
|
+
composes: relative from global;
|
|
25
|
+
composes: ml-2xs from global;
|
|
26
|
+
display: flex;
|
|
27
|
+
justify-content: space-between;
|
|
28
|
+
margin-top: 20px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.tabs {
|
|
32
|
+
composes: flex from global;
|
|
33
|
+
composes: flex-wrap from global;
|
|
34
|
+
composes: mt-3 from global;
|
|
35
|
+
composes: gap-[15px] from global;
|
|
36
|
+
margin-bottom: 30px;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.tabs_item {
|
|
40
|
+
composes: px-4 from global;
|
|
41
|
+
composes: py-2 from global;
|
|
42
|
+
composes: transition-colors from global;
|
|
43
|
+
composes: duration-150 from global;
|
|
44
|
+
composes: border from global;
|
|
45
|
+
composes: border-solid from global;
|
|
46
|
+
composes: leading-normal from global;
|
|
47
|
+
composes: text-base from global;
|
|
48
|
+
composes: text-colorDefault from global;
|
|
49
|
+
composes: bg-white from global;
|
|
50
|
+
composes: border-gray-100 from global;
|
|
51
|
+
border-radius: 5px;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.singlesWrapper {
|
|
55
|
+
column-count: 1;
|
|
56
|
+
display: flex;
|
|
57
|
+
width: 100%;
|
|
58
|
+
flex-wrap: wrap;
|
|
59
|
+
flex-direction: row;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.singlesGroupWrapper {
|
|
63
|
+
width: 100%;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@media screen and (min-width: 768px) {
|
|
67
|
+
.singlesGroupWrapper {
|
|
68
|
+
width: 50%;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@media screen and (min-width: 1023px) {
|
|
73
|
+
.singlesGroupWrapper {
|
|
74
|
+
width: 33.33%;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { shape, string } from 'prop-types';
|
|
3
|
+
import { useStyle } from '@magento/venia-ui/lib/classify';
|
|
4
|
+
|
|
5
|
+
import Shimmer from '@magento/venia-ui/lib/components/Shimmer';
|
|
6
|
+
import defaultClasses from './shopByCard.module.css';
|
|
7
|
+
import cn from 'classnames';
|
|
8
|
+
import Divider from '@riosst100/pwa-marketplace/src/components/Divider';
|
|
9
|
+
|
|
10
|
+
const ShopByCard = props => {
|
|
11
|
+
const classes = useStyle(defaultClasses, props.classes);
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
<h1 className='mx-auto relative block text-xl font-bold text-center pt-10 pb-4'><Shimmer width="25%" height="6vh" /></h1>
|
|
16
|
+
<div className='border border-gray-100 px-6'>
|
|
17
|
+
<center>
|
|
18
|
+
<section className='single_list-indexing-container relative m-auto pt-5'>
|
|
19
|
+
<Shimmer width="95%" height="6vh" />
|
|
20
|
+
</section>
|
|
21
|
+
</center>
|
|
22
|
+
<Divider className="mb-5 px-4" />
|
|
23
|
+
<section className='singles-container'>
|
|
24
|
+
<div className={cn('singles-wrapper block -mx-4', classes.singlesWrapper)}>
|
|
25
|
+
<div className='singles_group-wrapper mb-4 px-2 inline-block w-full'>
|
|
26
|
+
<div className='singles_item_group_letter text-xl font-medium border-b border-gray-100 pb-1 mb-2' ><Shimmer width="95%" height="100vh" /></div>
|
|
27
|
+
</div>
|
|
28
|
+
<div className='singles_group-wrapper mb-4 px-2 inline-block w-full'>
|
|
29
|
+
<div className='singles_item_group_letter text-xl font-medium border-b border-gray-100 pb-1 mb-2' ><Shimmer width="95%" height="100vh" /></div>
|
|
30
|
+
</div>
|
|
31
|
+
<div className='singles_group-wrapper mb-4 px-2 inline-block w-full'>
|
|
32
|
+
<div className='singles_item_group_letter text-xl font-medium border-b border-gray-100 pb-1 mb-2' ><Shimmer width="95%" height="100vh" /></div>
|
|
33
|
+
</div>
|
|
34
|
+
<div className='singles_group-wrapper mb-4 px-2 inline-block w-full'>
|
|
35
|
+
<div className='singles_item_group_letter text-xl font-medium border-b border-gray-100 pb-1 mb-2' ><Shimmer width="95%" height="100vh" /></div>
|
|
36
|
+
</div>
|
|
37
|
+
<div className='singles_group-wrapper mb-4 px-2 inline-block w-full'>
|
|
38
|
+
<div className='singles_item_group_letter text-xl font-medium border-b border-gray-100 pb-1 mb-2' ><Shimmer width="95%" height="100vh" /></div>
|
|
39
|
+
</div>
|
|
40
|
+
<div className='singles_group-wrapper mb-4 px-2 inline-block w-full'>
|
|
41
|
+
<div className='singles_item_group_letter text-xl font-medium border-b border-gray-100 pb-1 mb-2' ><Shimmer width="95%" height="100vh" /></div>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
</section>
|
|
45
|
+
</div>
|
|
46
|
+
</>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default ShopByCard;
|
|
@@ -12,6 +12,7 @@ import { useIntl } from 'react-intl';
|
|
|
12
12
|
import ShopBy from '@riosst100/pwa-marketplace/src/components/ShopBy/shopBy';
|
|
13
13
|
import SubCategoryPage from '@riosst100/pwa-marketplace/src/components/CustomSubCategoryPage/subCategoryPage';
|
|
14
14
|
import ShopBySets from '@riosst100/pwa-marketplace/src/components/ShopBySets/shopBySets';
|
|
15
|
+
import ShopByCard from '@riosst100/pwa-marketplace/src/components/ShopByCard/shopByCard';
|
|
15
16
|
import { useLocation } from 'react-router-dom';
|
|
16
17
|
import SportCardsSets from '@riosst100/pwa-marketplace/src/components/SportCardsSets/sportCardsSets';
|
|
17
18
|
import NonSportCardsSets from '@riosst100/pwa-marketplace/src/components/NonSportCardsSets/nonSportCardsSets';
|
|
@@ -100,6 +101,9 @@ const Category = props => {
|
|
|
100
101
|
isLoading={loading} /> : shopby == "sets" || shopby == "expansion_sets" || shopby == "release_year" ? <ShopBySets
|
|
101
102
|
categoryId={uid}
|
|
102
103
|
shopby={shopby}
|
|
104
|
+
isLoading={loading} /> : shopby == "card" ? <ShopByCard
|
|
105
|
+
categoryId={uid}
|
|
106
|
+
shopby={shopby}
|
|
103
107
|
isLoading={loading} /> : (shopby && shopby != "gauge" ? (
|
|
104
108
|
<ShopBy
|
|
105
109
|
categoryId={uid}
|
|
@@ -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_COLLECTIBLE_GAME_QUERY = gql`
|
|
15
|
+
query getShopByCard($categoryUrlKey: String!, $productType: String) {
|
|
16
|
+
shopByCard(categoryUrlKey: $categoryUrlKey, productType: $productType) {
|
|
17
|
+
release_type
|
|
18
|
+
sets {
|
|
19
|
+
set_name
|
|
20
|
+
option_id
|
|
21
|
+
set_abbreviation
|
|
22
|
+
release_date
|
|
23
|
+
release_year
|
|
24
|
+
release_number
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
export const GET_SPORT_CARDS_SETS_QUERY = gql`
|
|
31
|
+
query getSportCardsSets($categoryUrlKey: String!, $setType: String) {
|
|
32
|
+
sportCardsSets(categoryUrlKey: $categoryUrlKey, setType: $setType) {
|
|
33
|
+
group
|
|
34
|
+
sets {
|
|
35
|
+
set_name
|
|
36
|
+
option_id
|
|
37
|
+
release_year
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
export default {
|
|
44
|
+
getStoreConfigData: GET_STORE_CONFIG_DATA,
|
|
45
|
+
getCollectibleGameQuery: GET_COLLECTIBLE_GAME_QUERY,
|
|
46
|
+
getSportCardsSetsQuery: GET_SPORT_CARDS_SETS_QUERY
|
|
47
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
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 './shopByCard.gql';
|
|
8
|
+
|
|
9
|
+
export const useShopByCard = props => {
|
|
10
|
+
|
|
11
|
+
const { searchQuery, setActive, currentSort, shopby } = props
|
|
12
|
+
|
|
13
|
+
const { value: sortby } = currentSort
|
|
14
|
+
|
|
15
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, null);
|
|
16
|
+
const { getStoreConfigData, getCollectibleGameQuery } = 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
|
+
const pathnameArr = pathname.split('/');
|
|
31
|
+
|
|
32
|
+
const categoryUrlKey = pathnameArr[pathnameArr.length - 1].replace('.html','');
|
|
33
|
+
const productType = shopby;
|
|
34
|
+
|
|
35
|
+
const categoryUrlSuffix = storeConfigData?.storeConfig?.category_url_suffix;
|
|
36
|
+
|
|
37
|
+
const { error, loading, data } = useQuery(getCollectibleGameQuery, {
|
|
38
|
+
fetchPolicy: 'cache-and-network',
|
|
39
|
+
nextFetchPolicy: 'cache-first',
|
|
40
|
+
skip: !storeConfigData,
|
|
41
|
+
variables: {
|
|
42
|
+
categoryUrlKey: categoryUrlKey,
|
|
43
|
+
productType: productType
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const isBackgroundLoading = !!data && loading;
|
|
48
|
+
|
|
49
|
+
const shopByCard = useMemo(() => {
|
|
50
|
+
if (!data) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const shopByCard = data.shopByCard;
|
|
55
|
+
if (!shopByCard) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const sortbyData = [];
|
|
60
|
+
if (sortby != 'all') {
|
|
61
|
+
shopByCard.map((setRelease, index) => {
|
|
62
|
+
const { release_type, sets } = setRelease;
|
|
63
|
+
if (sets.length) {
|
|
64
|
+
sets.map((set, index) => {
|
|
65
|
+
const { release_year } = set;
|
|
66
|
+
if (release_year) {
|
|
67
|
+
// groupingSetsByYear.splice(release_year, 0, set);
|
|
68
|
+
const result = sortbyData.find(item => item.release_type === release_year);
|
|
69
|
+
|
|
70
|
+
// groupingSetsByYear[release_year] = set;
|
|
71
|
+
if (result) {
|
|
72
|
+
result.sets.push(set)
|
|
73
|
+
} else {
|
|
74
|
+
if (sortby == "date" || sortby == "newest" && sortbyData.length < 2) {
|
|
75
|
+
sortbyData.push({
|
|
76
|
+
'release_type': release_year,
|
|
77
|
+
'sets': [set]
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return sortby != "all" ? sortbyData && sortbyData.length ? sortbyData.sort((a, b) => b.release_type.toLowerCase().localeCompare(a.release_type.toLowerCase())) : sortbyData : shopByCard.slice().sort((a, b) => a.release_type.toLowerCase().localeCompare(b.release_type.toLowerCase()));
|
|
88
|
+
}, [data, sortby]);
|
|
89
|
+
|
|
90
|
+
const availableGroups = shopByCard && shopByCard.length ? shopByCard.map(({ release_type }) => release_type) : [];
|
|
91
|
+
|
|
92
|
+
const filteredShopByCard = useMemo(() => {
|
|
93
|
+
if (!shopByCard) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const filteredSets = [];
|
|
98
|
+
|
|
99
|
+
if (searchQuery) {
|
|
100
|
+
|
|
101
|
+
setActive('all')
|
|
102
|
+
|
|
103
|
+
shopByCard.map(({ release_type, sets }, index) => {
|
|
104
|
+
const newSets = sets.filter(function(set) {
|
|
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
|
+
});
|
|
107
|
+
|
|
108
|
+
if (newSets && newSets.length) {
|
|
109
|
+
filteredSets.push({
|
|
110
|
+
'release_type': release_type,
|
|
111
|
+
'sets': newSets
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return searchQuery ? filteredSets : shopByCard;
|
|
118
|
+
}, [shopByCard, searchQuery, sortby]);
|
|
119
|
+
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
setPageLoading(isBackgroundLoading);
|
|
122
|
+
}, [isBackgroundLoading, setPageLoading]);
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
error,
|
|
126
|
+
loading,
|
|
127
|
+
shopByCard,
|
|
128
|
+
filteredShopByCard,
|
|
129
|
+
categoryUrlSuffix,
|
|
130
|
+
categoryUrlKey,
|
|
131
|
+
productType,
|
|
132
|
+
availableGroups
|
|
133
|
+
};
|
|
134
|
+
};
|
|
@@ -174,7 +174,7 @@ export const useSportCardsSets = props => {
|
|
|
174
174
|
})
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
return sortby == "release" ? sportCardsSets
|
|
177
|
+
return sortby == "release" ? sportCardsSets : sportCardsSets;
|
|
178
178
|
}, [queryResponse, activeTab]);
|
|
179
179
|
|
|
180
180
|
const availableGroups = sportCardsSets && sportCardsSets.length ? sportCardsSets.map(({ group }) => group) : [];
|