@riosst100/pwa-marketplace 1.5.6 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@riosst100/pwa-marketplace",
3
3
  "author": "riosst100@gmail.com",
4
- "version": "1.5.6",
4
+ "version": "1.5.8",
5
5
  "main": "src/index.js",
6
6
  "pwa-studio": {
7
7
  "targets": {
@@ -15,36 +15,28 @@ import ProductSort from '@riosst100/pwa-marketplace/src/overwrites/venia-ui/lib/
15
15
  import CustomSortBy from '@riosst100/pwa-marketplace/src/components/CustomSortBy';
16
16
 
17
17
  const CollectibleGameSets = props => {
18
-
19
- const { productType } = props;
20
-
21
18
  const [active, setActive] = useState('all');
22
19
 
20
+ const [sortBy, setSortBy] = useState({
21
+ sortText: 'All (A-Z)',
22
+ value: 'all'
23
+ });
24
+
23
25
  const classes = useStyle(defaultClasses);
24
26
 
25
- const talonProps = useCollectibleGameSets({ productType });
27
+ const talonProps = useCollectibleGameSets();
26
28
 
27
- const { error, loading, collectibleGameSets, categoryUrlSuffix, categoryUrlKey } = talonProps;
29
+ const { error, loading, collectibleGameSets, categoryUrlSuffix, categoryUrlKey, productType } = talonProps;
28
30
 
29
31
  if (loading && !collectibleGameSets)
30
32
  return <CollectibleGameSetsShimmer />;
31
33
  if (error && !collectibleGameSets) return <ErrorView />;
32
34
 
33
- if (!collectibleGameSets) {
34
- return (
35
- <h1>
36
- <FormattedMessage
37
- id={'sets.notDataFound'}
38
- defaultMessage={
39
- 'No data found.'
40
- }
41
- />
42
- </h1>
43
- );
35
+ if (!collectibleGameSets && !loading && !error) {
36
+ return <CollectibleGameSetsShimmer />;
44
37
  }
45
38
 
46
39
  const setsLengthArr = [];
47
-
48
40
  const groupByYear = [];
49
41
 
50
42
  const setRelases = collectibleGameSets.map((setRelease, index) => {
@@ -93,11 +85,6 @@ const CollectibleGameSets = props => {
93
85
 
94
86
  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'];
95
87
 
96
- const [sortBy, setSortBy] = useState({
97
- sortText: 'All (A-Z)',
98
- value: 'all'
99
- });
100
-
101
88
  const availableSortBy = [
102
89
  {
103
90
  'label': 'All (A-Z)',
@@ -114,14 +101,15 @@ const CollectibleGameSets = props => {
114
101
  ];
115
102
 
116
103
  return (
117
- <>
104
+ <Fragment>
105
+ <StoreTitle>{"Magic: The Gathering" + " | " + (productType == "expansion-sets" ? "Expansion Sets" : "All Sets")}</StoreTitle>
118
106
  <h1 className='mx-auto relative block text-xl font-bold text-center pt-10 pb-4'>
119
- {productType == "sealed-products" ? "Expansion Sets" : "All Sets"}
107
+ {productType == "expansion-sets" ? "Expansion Sets" : "All Sets"}
120
108
  </h1>
121
109
  <div className='border border-gray-100 px-6'>
122
- <CustomSortBy sortProps={[sortBy, setSortBy]} availableSortMethods={availableSortBy} />
123
- {productType != "sealed-products" ? (
110
+ {productType != "expansion-sets" ? (
124
111
  <>
112
+ <CustomSortBy sortProps={[sortBy, setSortBy]} availableSortMethods={availableSortBy} />
125
113
  <section className='single_list-indexing-container relative m-auto py-10'>
126
114
  <ul className='flex gap-2 justify-center flex-wrap'>
127
115
  <li>
@@ -165,8 +153,8 @@ const CollectibleGameSets = props => {
165
153
  </div>
166
154
  </section>
167
155
  </div>
168
- </>
156
+ </Fragment>
169
157
  );
170
- };
158
+ }
171
159
 
172
160
  export default CollectibleGameSets;
@@ -0,0 +1,35 @@
1
+ import { useCustomSubCategory } from '@riosst100/pwa-marketplace/src/talons/SubCategory/useCustomSubCategory';
2
+ import React, { useState } from 'react';
3
+ import { Link } from 'react-router-dom';
4
+ import resourceUrl from '@magento/peregrine/lib/util/makeUrl';
5
+ import defaultClasses from './customSubCategory.module.css';
6
+ import { useStyle } from '@magento/venia-ui/lib/classify';
7
+
8
+ const CustomSubCategory = props => {
9
+ const { customSubCategory } = props;
10
+
11
+ const talonProps = useCustomSubCategory({ customSubCategory });
12
+
13
+ const classes = useStyle(defaultClasses, props.classes);
14
+
15
+ const {
16
+ normalizedData
17
+ } = talonProps;
18
+
19
+ const subCategory = [];
20
+
21
+ normalizedData && normalizedData.map(({ text, path }, index) => {
22
+ subCategory.push(
23
+ <Link
24
+ key={index}
25
+ to={resourceUrl(path)}
26
+ >
27
+ <li className={classes.item}>{text}</li>
28
+ </Link>
29
+ )
30
+ });
31
+
32
+ return subCategory.length ? <ul className={classes.root}>{subCategory}</ul> : '';
33
+ };
34
+
35
+ export default CustomSubCategory;
@@ -0,0 +1,22 @@
1
+ .root {
2
+ composes: flex from global;
3
+ composes: flex-wrap from global;
4
+ composes: mt-3 from global;
5
+ composes: gap-[15px] from global;
6
+ margin-bottom: 10px;
7
+ }
8
+
9
+ .item {
10
+ composes: px-4 from global;
11
+ composes: py-2 from global;
12
+ composes: transition-colors from global;
13
+ composes: duration-150 from global;
14
+ composes: border from global;
15
+ composes: border-solid from global;
16
+ composes: leading-normal from global;
17
+ composes: text-base from global;
18
+ composes: text-colorDefault from global;
19
+ composes: bg-white from global;
20
+ composes: border-gray-100 from global;
21
+ border-radius: 5px;
22
+ }
@@ -32,7 +32,10 @@ export const GET_CATEGORY_CONTENT = gql`
32
32
  allowed_filters {
33
33
  code
34
34
  }
35
- custom_landing_page
35
+ custom_subcategory {
36
+ name
37
+ path
38
+ }
36
39
  attributes_block {
37
40
  label
38
41
  code
@@ -31,6 +31,7 @@ import BrandSlider from '@riosst100/pwa-marketplace/src/components/BrandSlider';
31
31
  import CollectibleGameSets from '@riosst100/pwa-marketplace/src/components/CollectibleGameSets/collectibleGameSets';
32
32
  import { useLocation } from 'react-router-dom';
33
33
  import { getFiltersFromSearch } from '@magento/peregrine/lib/talons/FilterModal/helpers';
34
+ import CustomSubCategory from '@riosst100/pwa-marketplace/src/components/SubCategory/customSubCategory';
34
35
 
35
36
  const FilterModal = React.lazy(() => import('@magento/venia-ui/lib/components/FilterModal'));
36
37
  const FilterSidebar = React.lazy(() =>
@@ -216,7 +217,8 @@ const CategoryContent = props => {
216
217
  </div>
217
218
  {/* {activeFilters.size <= 0 && category && category.custom_landing_page ? ( */}
218
219
  <>
219
- <SubCategory children={children} customLandingPage={category ? category.custom_landing_page : ''} />
220
+ <SubCategory children={children} />
221
+ {!currentFilter && <CustomSubCategory customSubCategory={category ? category.custom_subcategory : null} />}
220
222
  </>
221
223
  {/* ) : ( */}
222
224
  <>
@@ -8,8 +8,6 @@ import DEFAULT_OPERATIONS from './collectibleGameSets.gql';
8
8
 
9
9
  export const useCollectibleGameSets = props => {
10
10
 
11
- const { productType } = props
12
-
13
11
  const operations = mergeOperations(DEFAULT_OPERATIONS, null);
14
12
  const { getStoreConfigData, getCollectibleGameQuery } = operations;
15
13
  const { pathname } = useLocation();
@@ -27,11 +25,12 @@ export const useCollectibleGameSets = props => {
27
25
 
28
26
  const pathnameArr = pathname.split('/');
29
27
 
30
- const categoryUrlKey = pathnameArr[pathnameArr.length - 1].replace('.html','');
28
+ const categoryUrlKey = pathnameArr[pathnameArr.length - 2].replace('.html','');
29
+ const productType = pathnameArr[pathnameArr.length - 1].replace('.html','');
31
30
 
32
31
  const categoryUrlSuffix = storeConfigData?.storeConfig?.category_url_suffix;
33
32
 
34
- const { error: allSetsError, loading: allSetsLoading, data: allSetsData } = useQuery(getCollectibleGameQuery, {
33
+ const { error, loading, data } = useQuery(getCollectibleGameQuery, {
35
34
  fetchPolicy: 'cache-and-network',
36
35
  nextFetchPolicy: 'cache-first',
37
36
  skip: !storeConfigData,
@@ -41,31 +40,24 @@ export const useCollectibleGameSets = props => {
41
40
  }
42
41
  });
43
42
 
44
- const { error: expansionSetsError, loading: expansionSetsLoading, data: expansionSetsData } = useQuery(getCollectibleGameQuery, {
45
- fetchPolicy: 'cache-and-network',
46
- nextFetchPolicy: 'cache-first',
47
- skip: !storeConfigData,
48
- variables: {
49
- categoryUrlKey: categoryUrlKey,
50
- productType: productType
51
- }
52
- });
53
-
54
- const loading = !!allSetsData && allSetsLoading;
55
- const error = !!allSetsData && allSetsError;
43
+ const isBackgroundLoading = !!data && loading;
56
44
 
57
45
  const collectibleGameSets = useMemo(() => {
58
- if (!allSetsData) {
46
+ if (!data) {
59
47
  return null;
60
48
  }
61
49
 
62
- const collectibleGameSets = productType == "sealed-products" ? expansionSetsData.collectibleGameSets : allSetsData.collectibleGameSets;
50
+ const collectibleGameSets = data.collectibleGameSets;
63
51
  if (!collectibleGameSets) {
64
52
  return null;
65
53
  }
66
54
 
67
55
  return collectibleGameSets;
68
- }, [allSetsData, expansionSetsData, categoryUrlKey, productType]);
56
+ }, [data, categoryUrlKey]);
57
+
58
+ useEffect(() => {
59
+ setPageLoading(isBackgroundLoading);
60
+ }, [isBackgroundLoading, setPageLoading]);
69
61
 
70
62
  return {
71
63
  error,
@@ -0,0 +1,49 @@
1
+ import { useMemo } from 'react';
2
+ import { useQuery } from '@apollo/client';
3
+
4
+ import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
5
+
6
+ import DEFAULT_OPERATIONS from './subCategory.gql';
7
+
8
+ const getPath = (path, suffix) => {
9
+ if (path) {
10
+ return `/${path}${suffix || ''}`;
11
+ }
12
+
13
+ // If there is no path this is just a dead link.
14
+ return '#';
15
+ };
16
+
17
+ export const useCustomSubCategory = props => {
18
+ const { customSubCategory } = props;
19
+
20
+ const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
21
+ const { getStoreConfigQuery } = operations;
22
+
23
+ const { data: storeConfigData } = useQuery(getStoreConfigQuery, {
24
+ fetchPolicy: 'cache-and-network'
25
+ });
26
+
27
+ const categoryUrlSuffix = useMemo(() => {
28
+ if (storeConfigData) {
29
+ return storeConfigData.storeConfig.category_url_suffix;
30
+ }
31
+ }, [storeConfigData]);
32
+
33
+ const normalizedData = useMemo(() => {
34
+ if (customSubCategory) {
35
+ return (
36
+ customSubCategory.length &&
37
+ customSubCategory
38
+ .map(category => ({
39
+ text: category.name,
40
+ path: `/${category.path}`
41
+ }))
42
+ );
43
+ }
44
+ }, [categoryUrlSuffix, customSubCategory]);
45
+
46
+ return {
47
+ normalizedData: normalizedData || []
48
+ };
49
+ };