@usereactify/search 3.12.0-beta.1 → 3.12.0-beta.4
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/dist/filter/FilterStack.js +1 -1
- package/dist/provider.d.ts +1 -1
- package/dist/provider.js +34 -19
- package/dist/types/firestore.d.ts +1 -0
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ const FilterStack = (props) => {
|
|
|
14
14
|
return null;
|
|
15
15
|
if (render)
|
|
16
16
|
return render(filters);
|
|
17
|
-
return (react_1.default.createElement(react_1.default.Fragment, null, filters.map((filter) => (react_1.default.createElement(FilterWithState, Object.assign({ key: filter.
|
|
17
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, filters.map((filter) => (react_1.default.createElement(FilterWithState, Object.assign({ key: filter.id, filter: filter }, props))))));
|
|
18
18
|
};
|
|
19
19
|
exports.FilterStack = FilterStack;
|
|
20
20
|
const FilterWithState = ({ filter, renderFilter, }) => {
|
package/dist/provider.d.ts
CHANGED
package/dist/provider.js
CHANGED
|
@@ -38,7 +38,7 @@ const Provider = (_a) => {
|
|
|
38
38
|
exports.Provider = Provider;
|
|
39
39
|
const ConfiguredProvider = (props) => {
|
|
40
40
|
var _a, _b;
|
|
41
|
-
const { index, config, children, collection, instantSearch,
|
|
41
|
+
const { index, config, children, collection, instantSearch, filterStackHandle, noReactiveBase, shopifyPermanentDomain, additionalComponentHandles, onRedirect, } = props;
|
|
42
42
|
const credentials = (_a = props.credentials) !== null && _a !== void 0 ? _a : defaultCredentials;
|
|
43
43
|
const theme = (_b = props.theme) !== null && _b !== void 0 ? _b : {
|
|
44
44
|
typography: {
|
|
@@ -77,13 +77,13 @@ const ConfiguredProvider = (props) => {
|
|
|
77
77
|
setSearchQuery(searchQueryFromURL);
|
|
78
78
|
}, [searchQueryFromURL]);
|
|
79
79
|
react_1.default.useEffect(() => {
|
|
80
|
-
if (searchSortFromURL && (sortOption === null || sortOption === void 0 ? void 0 : sortOption.
|
|
80
|
+
if (searchSortFromURL && (sortOption === null || sortOption === void 0 ? void 0 : sortOption.handle) !== searchSortFromURL) {
|
|
81
81
|
setSortOption(searchSortFromURL, true);
|
|
82
82
|
}
|
|
83
83
|
}, [searchSortFromURL]);
|
|
84
84
|
react_1.default.useEffect(() => {
|
|
85
|
-
if (window.location.search === "" && (sortOption === null || sortOption === void 0 ? void 0 : sortOption.
|
|
86
|
-
setSortOption(sortOption.
|
|
85
|
+
if (window.location.search === "" && (sortOption === null || sortOption === void 0 ? void 0 : sortOption.handle)) {
|
|
86
|
+
setSortOption(sortOption.handle, true);
|
|
87
87
|
}
|
|
88
88
|
}, [window.location.href]);
|
|
89
89
|
const [showInstantSearchResults, setShowInstantSearchResults] = react_1.default.useState(false);
|
|
@@ -107,7 +107,7 @@ const ConfiguredProvider = (props) => {
|
|
|
107
107
|
// do not attempt to resolve a filter stack if in instantSearch mode
|
|
108
108
|
const filterStack = instantSearch
|
|
109
109
|
? undefined
|
|
110
|
-
: useFilterStack(config, collection,
|
|
110
|
+
: useFilterStack(config, collection, filterStackHandle);
|
|
111
111
|
const curation = useCuration(config, collection, searchQuery);
|
|
112
112
|
const contextValue = react_1.default.useMemo(() => ({
|
|
113
113
|
index,
|
|
@@ -167,7 +167,7 @@ const useSortState = (config, collection) => {
|
|
|
167
167
|
.sort((a, b) => `${a.position}`.localeCompare(`${b.position}`))
|
|
168
168
|
.filter(({ visibility }) => ["all", type].includes(visibility));
|
|
169
169
|
}, [config, collection]);
|
|
170
|
-
const [sortOptionState, setSortOptionState] = react_1.default.useState((_a = sortOptions[0]) === null || _a === void 0 ? void 0 : _a.
|
|
170
|
+
const [sortOptionState, setSortOptionState] = react_1.default.useState((_a = sortOptions[0]) === null || _a === void 0 ? void 0 : _a.handle);
|
|
171
171
|
const sortOption = react_1.default.useMemo(() => sortOptions.find(({ id }) => id === sortOptionState) || sortOptions[0], [sortOptions, sortOptionState]);
|
|
172
172
|
const setSortOption = react_1.default.useCallback((sortOptionId, ignoreHistoryState = false) => {
|
|
173
173
|
setSortOptionState(sortOptionId);
|
|
@@ -187,22 +187,37 @@ const useSortState = (config, collection) => {
|
|
|
187
187
|
// @todo we need a better name for the overall page like "Filter Stack" or something,
|
|
188
188
|
// each block is then called a filter so like Size would be a "Filter" and then each
|
|
189
189
|
// value within it is a "Filter Option"
|
|
190
|
-
const useFilterStack = (config, collection,
|
|
191
|
-
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
190
|
+
const useFilterStack = (config, collection, filterStackHandle) => react_1.default.useMemo(() => {
|
|
191
|
+
const type = !!collection ? "collection" : "search";
|
|
192
|
+
// select filters by type
|
|
193
|
+
const matchingFilterStacks = config.filters.filter((filter) => filter.type === type);
|
|
194
|
+
// select filter stack by handle if provided
|
|
195
|
+
if (filterStackHandle) {
|
|
196
|
+
const matchingFilterStack = matchingFilterStacks.find((filterStack) => filterStackHandle === filterStack.handle);
|
|
197
|
+
if (matchingFilterStack) {
|
|
198
|
+
return matchingFilterStack;
|
|
199
|
+
}
|
|
197
200
|
}
|
|
198
|
-
//
|
|
201
|
+
// select filter stack by collection if provided
|
|
199
202
|
if (collection === null || collection === void 0 ? void 0 : collection.handle) {
|
|
200
|
-
const
|
|
201
|
-
if (
|
|
202
|
-
return
|
|
203
|
+
const matchingFilterStack = matchingFilterStacks.find((filterStack) => { var _a; return (_a = filterStack.collections) === null || _a === void 0 ? void 0 : _a.includes(collection.handle); });
|
|
204
|
+
if (matchingFilterStack) {
|
|
205
|
+
return matchingFilterStack;
|
|
206
|
+
}
|
|
203
207
|
}
|
|
204
|
-
|
|
205
|
-
|
|
208
|
+
// select filter with "default" handle
|
|
209
|
+
let matchingFilterStack = matchingFilterStacks.find((filterStack) => filterStack.handle === "default");
|
|
210
|
+
if (matchingFilterStack) {
|
|
211
|
+
return matchingFilterStack;
|
|
212
|
+
}
|
|
213
|
+
// select any filter with "default" handle
|
|
214
|
+
matchingFilterStack = config.filters.find((filterStack) => filterStack.handle === "default");
|
|
215
|
+
if (matchingFilterStack) {
|
|
216
|
+
return matchingFilterStack;
|
|
217
|
+
}
|
|
218
|
+
// select any available filter as a last resort
|
|
219
|
+
matchingFilterStack = config.filters[0];
|
|
220
|
+
return matchingFilterStack;
|
|
206
221
|
}, [config, collection]);
|
|
207
222
|
const useCuration = (config, collection, searchQuery) => react_1.default.useMemo(() => {
|
|
208
223
|
debug("resolveCuration.start", { config, collection, searchQuery });
|