@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.
@@ -41,7 +41,7 @@ function getTrackEvents(event) {
41
41
  },
42
42
  ];
43
43
  break;
44
- case "viewProduct":
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 "clickProduct":
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 "viewPromotion":
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 "clickPromotion":
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 "zeroResults":
76
+ case "clickPromotion":
77
77
  events = [
78
78
  {
79
79
  eventName,
@@ -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
- if (redirect)
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
- else
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,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@usereactify/search",
3
3
  "description": "React UI library for Reactify Search",
4
- "version": "3.10.0",
4
+ "version": "3.10.1",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",