@usereactify/search 3.12.0-beta.2 → 3.12.0-beta.5
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/hooks/useSort.d.ts +1 -1
- package/dist/hooks/useSort.js +3 -3
- package/dist/provider.d.ts +1 -1
- package/dist/provider.js +22 -15
- 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/hooks/useSort.d.ts
CHANGED
package/dist/hooks/useSort.js
CHANGED
|
@@ -10,12 +10,12 @@ const hooks_1 = require("../hooks");
|
|
|
10
10
|
const useSort = () => {
|
|
11
11
|
const { track } = (0, hooks_1.useAnalytics)();
|
|
12
12
|
const { sortOption, sortOptions, setSortOption } = (0, provider_1.useContext)();
|
|
13
|
-
const handleSortChange = react_1.default.useCallback((
|
|
14
|
-
setSortOption(
|
|
13
|
+
const handleSortChange = react_1.default.useCallback((sortOptionHandle) => {
|
|
14
|
+
setSortOption(sortOptionHandle);
|
|
15
15
|
track({
|
|
16
16
|
eventName: "sortChange",
|
|
17
17
|
payload: {
|
|
18
|
-
type:
|
|
18
|
+
type: sortOptionHandle,
|
|
19
19
|
},
|
|
20
20
|
});
|
|
21
21
|
}, [track, setSortOption]);
|
package/dist/provider.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ declare type Context = {
|
|
|
14
14
|
onRedirect?: (type: "redirect" | "search", url: string) => void;
|
|
15
15
|
submitSearch: (localSearchQuery?: string) => void;
|
|
16
16
|
setSearchQuery: (searchQuery: string) => void;
|
|
17
|
-
setSortOption: (
|
|
17
|
+
setSortOption: (sortOptionHandle: string) => void;
|
|
18
18
|
showInstantSearchResults: boolean;
|
|
19
19
|
setShowInstantSearchResults: (showInstantSearchResults: boolean) => void;
|
|
20
20
|
theme?: Theme;
|
package/dist/provider.js
CHANGED
|
@@ -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);
|
|
@@ -167,15 +167,16 @@ 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.
|
|
171
|
-
const sortOption = react_1.default.useMemo(() => sortOptions.find(({
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
const [sortOptionState, setSortOptionState] = react_1.default.useState((_a = sortOptions[0]) === null || _a === void 0 ? void 0 : _a.handle);
|
|
171
|
+
const sortOption = react_1.default.useMemo(() => sortOptions.find(({ handle }) => handle === sortOptionState) ||
|
|
172
|
+
sortOptions[0], [sortOptions, sortOptionState]);
|
|
173
|
+
const setSortOption = react_1.default.useCallback((sortOptionHandle, ignoreHistoryState = false) => {
|
|
174
|
+
setSortOptionState(sortOptionHandle);
|
|
174
175
|
if (!ignoreHistoryState) {
|
|
175
176
|
const url = new URL(window.location.href);
|
|
176
177
|
url.searchParams.has("sort")
|
|
177
|
-
? url.searchParams.set("sort",
|
|
178
|
-
: url.searchParams.append("sort",
|
|
178
|
+
? url.searchParams.set("sort", sortOptionHandle)
|
|
179
|
+
: url.searchParams.append("sort", sortOptionHandle);
|
|
179
180
|
window.history.pushState({}, "", url.toString());
|
|
180
181
|
}
|
|
181
182
|
}, [window.location.href]);
|
|
@@ -189,29 +190,35 @@ const useSortState = (config, collection) => {
|
|
|
189
190
|
// value within it is a "Filter Option"
|
|
190
191
|
const useFilterStack = (config, collection, filterStackHandle) => react_1.default.useMemo(() => {
|
|
191
192
|
const type = !!collection ? "collection" : "search";
|
|
192
|
-
//
|
|
193
|
-
const
|
|
193
|
+
// select filters by type
|
|
194
|
+
const matchingFilterStacks = config.filters.filter((filter) => filter.type === type);
|
|
194
195
|
// select filter stack by handle if provided
|
|
195
196
|
if (filterStackHandle) {
|
|
196
|
-
const matchingFilterStack =
|
|
197
|
+
const matchingFilterStack = matchingFilterStacks.find((filterStack) => filterStackHandle === filterStack.handle);
|
|
197
198
|
if (matchingFilterStack) {
|
|
198
199
|
return matchingFilterStack;
|
|
199
200
|
}
|
|
200
201
|
}
|
|
201
202
|
// select filter stack by collection if provided
|
|
202
203
|
if (collection === null || collection === void 0 ? void 0 : collection.handle) {
|
|
203
|
-
const matchingFilterStack =
|
|
204
|
+
const matchingFilterStack = matchingFilterStacks.find((filterStack) => { var _a; return (_a = filterStack.collections) === null || _a === void 0 ? void 0 : _a.includes(collection.handle); });
|
|
204
205
|
if (matchingFilterStack) {
|
|
205
206
|
return matchingFilterStack;
|
|
206
207
|
}
|
|
207
208
|
}
|
|
208
209
|
// select filter with "default" handle
|
|
209
|
-
|
|
210
|
+
let matchingFilterStack = matchingFilterStacks.find((filterStack) => filterStack.handle === "default");
|
|
211
|
+
if (matchingFilterStack) {
|
|
212
|
+
return matchingFilterStack;
|
|
213
|
+
}
|
|
214
|
+
// select any filter with "default" handle
|
|
215
|
+
matchingFilterStack = config.filters.find((filterStack) => filterStack.handle === "default");
|
|
210
216
|
if (matchingFilterStack) {
|
|
211
217
|
return matchingFilterStack;
|
|
212
218
|
}
|
|
213
219
|
// select any available filter as a last resort
|
|
214
|
-
|
|
220
|
+
matchingFilterStack = config.filters[0];
|
|
221
|
+
return matchingFilterStack;
|
|
215
222
|
}, [config, collection]);
|
|
216
223
|
const useCuration = (config, collection, searchQuery) => react_1.default.useMemo(() => {
|
|
217
224
|
debug("resolveCuration.start", { config, collection, searchQuery });
|