@riosst100/pwa-marketplace 1.8.7 → 1.8.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.
@@ -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
+ };
@@ -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
- 'label': item.split(',')[0],
72
- 'path': data
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) : [];
@@ -196,7 +197,6 @@ export const useSportCardsSets = props => {
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) {