@usereactify/search 3.10.0 → 3.10.1
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/hooks/useAnalytics.js +5 -5
- package/dist/provider.d.ts +2 -0
- package/dist/provider.js +16 -6
- package/package.json +1 -1
|
@@ -41,7 +41,7 @@ function getTrackEvents(event) {
|
|
|
41
41
|
},
|
|
42
42
|
];
|
|
43
43
|
break;
|
|
44
|
-
case "
|
|
44
|
+
case "zeroResults":
|
|
45
45
|
events = [
|
|
46
46
|
{
|
|
47
47
|
eventName,
|
|
@@ -49,7 +49,7 @@ function getTrackEvents(event) {
|
|
|
49
49
|
},
|
|
50
50
|
];
|
|
51
51
|
break;
|
|
52
|
-
case "
|
|
52
|
+
case "viewProduct":
|
|
53
53
|
events = [
|
|
54
54
|
{
|
|
55
55
|
eventName,
|
|
@@ -57,7 +57,7 @@ function getTrackEvents(event) {
|
|
|
57
57
|
},
|
|
58
58
|
];
|
|
59
59
|
break;
|
|
60
|
-
case "
|
|
60
|
+
case "clickProduct":
|
|
61
61
|
events = [
|
|
62
62
|
{
|
|
63
63
|
eventName,
|
|
@@ -65,7 +65,7 @@ function getTrackEvents(event) {
|
|
|
65
65
|
},
|
|
66
66
|
];
|
|
67
67
|
break;
|
|
68
|
-
case "
|
|
68
|
+
case "viewPromotion":
|
|
69
69
|
events = [
|
|
70
70
|
{
|
|
71
71
|
eventName,
|
|
@@ -73,7 +73,7 @@ function getTrackEvents(event) {
|
|
|
73
73
|
},
|
|
74
74
|
];
|
|
75
75
|
break;
|
|
76
|
-
case "
|
|
76
|
+
case "clickPromotion":
|
|
77
77
|
events = [
|
|
78
78
|
{
|
|
79
79
|
eventName,
|
package/dist/provider.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ declare type Context = {
|
|
|
11
11
|
collection?: Collection;
|
|
12
12
|
instantSearch: boolean;
|
|
13
13
|
credentials: Credentials;
|
|
14
|
+
onRedirect?: (type: "redirect" | "search", url: string) => void;
|
|
14
15
|
submitSearch: (localSearchQuery?: string) => void;
|
|
15
16
|
setSearchQuery: (searchQuery: string) => void;
|
|
16
17
|
setSortOption: (sortOptionId: string) => void;
|
|
@@ -29,6 +30,7 @@ declare type Props = {
|
|
|
29
30
|
collection?: Collection;
|
|
30
31
|
noReactiveBase?: boolean;
|
|
31
32
|
instantSearch?: boolean;
|
|
33
|
+
onRedirect?: (type: "redirect" | "search", url: string) => void;
|
|
32
34
|
credentials?: Credentials;
|
|
33
35
|
theme?: Theme;
|
|
34
36
|
/** Array of additional component IDs managed outside of Reactify Search */
|
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, filterStackId, noReactiveBase, shopifyPermanentDomain, additionalComponentIds, } = props;
|
|
41
|
+
const { index, config, children, collection, instantSearch, filterStackId, noReactiveBase, shopifyPermanentDomain, additionalComponentIds, 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: {
|
|
@@ -56,16 +56,18 @@ const ConfiguredProvider = (props) => {
|
|
|
56
56
|
react_1.default.useEffect(() => {
|
|
57
57
|
debug("props", props);
|
|
58
58
|
}, [props]);
|
|
59
|
-
// @todo make this hackable with a prop
|
|
60
|
-
// https://gitlab.com/reactifyapps/reactify-search-frontend/-/issues/1
|
|
61
59
|
const searchQueryFromURL = react_1.default.useMemo(() => {
|
|
62
60
|
var _a;
|
|
63
61
|
if (typeof window === "undefined")
|
|
64
62
|
return undefined;
|
|
65
63
|
const urlParams = new URLSearchParams(window.location.search);
|
|
66
64
|
return (_a = urlParams.get("q")) !== null && _a !== void 0 ? _a : undefined;
|
|
67
|
-
}, []);
|
|
65
|
+
}, [window.location.search]);
|
|
68
66
|
const [searchQuery, setSearchQuery] = react_1.default.useState(searchQueryFromURL);
|
|
67
|
+
react_1.default.useEffect(() => {
|
|
68
|
+
if (searchQuery !== searchQueryFromURL)
|
|
69
|
+
setSearchQuery(searchQueryFromURL);
|
|
70
|
+
}, [searchQueryFromURL]);
|
|
69
71
|
const [showInstantSearchResults, setShowInstantSearchResults] = react_1.default.useState(false);
|
|
70
72
|
const submitSearch = react_1.default.useCallback((localSearchQuery) => {
|
|
71
73
|
const actualSearchQuery = localSearchQuery !== null && localSearchQuery !== void 0 ? localSearchQuery : searchQuery;
|
|
@@ -73,10 +75,16 @@ const ConfiguredProvider = (props) => {
|
|
|
73
75
|
return;
|
|
74
76
|
const redirect = config.redirects.find((redirect) => redirect.query.trim().toLowerCase() ===
|
|
75
77
|
actualSearchQuery.trim().toLowerCase());
|
|
76
|
-
|
|
78
|
+
setShowInstantSearchResults(false);
|
|
79
|
+
if (onRedirect) {
|
|
80
|
+
onRedirect(redirect ? "redirect" : "search", redirect ? redirect.url : `/search?q=${actualSearchQuery}`);
|
|
81
|
+
}
|
|
82
|
+
else if (redirect) {
|
|
77
83
|
window.location.href = redirect.url;
|
|
78
|
-
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
79
86
|
window.location.href = `/search?q=${actualSearchQuery}`;
|
|
87
|
+
}
|
|
80
88
|
}, [searchQuery]);
|
|
81
89
|
const { sortOption, sortOptions, setSortOption } = useSortState(config, collection);
|
|
82
90
|
// do not attempt to resolve a filter stack if in instantSearch mode
|
|
@@ -94,6 +102,7 @@ const ConfiguredProvider = (props) => {
|
|
|
94
102
|
filterStack,
|
|
95
103
|
sortOption,
|
|
96
104
|
sortOptions,
|
|
105
|
+
onRedirect,
|
|
97
106
|
submitSearch,
|
|
98
107
|
setSortOption,
|
|
99
108
|
setSearchQuery,
|
|
@@ -114,6 +123,7 @@ const ConfiguredProvider = (props) => {
|
|
|
114
123
|
filterStack,
|
|
115
124
|
sortOption,
|
|
116
125
|
sortOptions,
|
|
126
|
+
onRedirect,
|
|
117
127
|
submitSearch,
|
|
118
128
|
instantSearch,
|
|
119
129
|
additionalComponentIds,
|