@usereactify/search 3.4.4 → 3.5.0
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const useAnalytics: () => {
|
|
2
2
|
track: (event: TrackEvent) => Promise<import("axios").AxiosResponse<any, any> | undefined>;
|
|
3
3
|
};
|
|
4
|
-
export declare type TrackEvent = TrackEvent.SearchEvent | TrackEvent.ClickProductEvent;
|
|
4
|
+
export declare type TrackEvent = TrackEvent.SearchEvent | TrackEvent.ZeroResultsEvent | TrackEvent.ViewProductEvent | TrackEvent.ClickProductEvent;
|
|
5
5
|
export declare namespace TrackEvent {
|
|
6
6
|
interface SearchEvent {
|
|
7
7
|
eventName: "search";
|
|
@@ -12,6 +12,24 @@ export declare namespace TrackEvent {
|
|
|
12
12
|
searchTerm: string;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
interface ZeroResultsEvent {
|
|
16
|
+
eventName: "zeroResults";
|
|
17
|
+
payload: ZeroResultsEvent.Payload;
|
|
18
|
+
}
|
|
19
|
+
namespace ZeroResultsEvent {
|
|
20
|
+
interface Payload {
|
|
21
|
+
searchTerm: string;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
interface ViewProductEvent {
|
|
25
|
+
eventName: "viewProduct";
|
|
26
|
+
payload: ViewProductEvent.Payload;
|
|
27
|
+
}
|
|
28
|
+
namespace ViewProductEvent {
|
|
29
|
+
interface Payload {
|
|
30
|
+
elasticProduct: ElasticProduct;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
15
33
|
interface ClickProductEvent {
|
|
16
34
|
eventName: "clickProduct";
|
|
17
35
|
payload: ClickProductEvent.Payload;
|
|
@@ -41,6 +41,14 @@ function getTrackEvents(event) {
|
|
|
41
41
|
},
|
|
42
42
|
];
|
|
43
43
|
break;
|
|
44
|
+
case "viewProduct":
|
|
45
|
+
events = [
|
|
46
|
+
{
|
|
47
|
+
eventName,
|
|
48
|
+
payload: event.payload,
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
break;
|
|
44
52
|
case "clickProduct":
|
|
45
53
|
events = [
|
|
46
54
|
{
|
|
@@ -49,6 +57,14 @@ function getTrackEvents(event) {
|
|
|
49
57
|
},
|
|
50
58
|
];
|
|
51
59
|
break;
|
|
60
|
+
case "zeroResults":
|
|
61
|
+
events = [
|
|
62
|
+
{
|
|
63
|
+
eventName,
|
|
64
|
+
payload: event.payload,
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
break;
|
|
52
68
|
}
|
|
53
69
|
return events;
|
|
54
70
|
}
|
|
@@ -5,7 +5,10 @@ declare type Props = {
|
|
|
5
5
|
pagePosition: number;
|
|
6
6
|
product: ElasticProduct;
|
|
7
7
|
document: ElasticProduct;
|
|
8
|
-
render?: (props: Omit<Props, "render"> & ReturnType<typeof useProductPrice>
|
|
8
|
+
render?: (props: Omit<Props, "render"> & ReturnType<typeof useProductPrice> & {
|
|
9
|
+
itemRef: (node?: Element | null) => void;
|
|
10
|
+
handleClick: () => void;
|
|
11
|
+
}) => JSX.Element;
|
|
9
12
|
};
|
|
10
13
|
export declare const ResultCard: React.FC<Props>;
|
|
11
14
|
export {};
|
|
@@ -16,15 +16,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.ResultCard = void 0;
|
|
18
18
|
const react_1 = __importDefault(require("react"));
|
|
19
|
+
const react_intersection_observer_1 = require("react-intersection-observer");
|
|
19
20
|
const hooks_1 = require("../hooks");
|
|
20
21
|
const ResultCard = (_a) => {
|
|
21
22
|
var { render } = _a, props = __rest(_a, ["render"]);
|
|
22
23
|
const { product } = props;
|
|
23
24
|
const productPrice = (0, hooks_1.useProductPrice)(product);
|
|
24
|
-
if (render)
|
|
25
|
-
return render(Object.assign(Object.assign({}, props), productPrice));
|
|
26
25
|
const { formattedPrice, formattedCompareAtPrice, onSale } = productPrice;
|
|
27
26
|
const { track } = (0, hooks_1.useAnalytics)();
|
|
27
|
+
const { ref, inView } = (0, react_intersection_observer_1.useInView)({
|
|
28
|
+
threshold: 0.5,
|
|
29
|
+
triggerOnce: true,
|
|
30
|
+
});
|
|
28
31
|
const handleClick = react_1.default.useCallback(() => {
|
|
29
32
|
track({
|
|
30
33
|
eventName: "clickProduct",
|
|
@@ -36,7 +39,24 @@ const ResultCard = (_a) => {
|
|
|
36
39
|
},
|
|
37
40
|
});
|
|
38
41
|
}, [track, product]);
|
|
39
|
-
|
|
42
|
+
const handleView = react_1.default.useCallback(() => {
|
|
43
|
+
track({
|
|
44
|
+
eventName: "viewProduct",
|
|
45
|
+
payload: {
|
|
46
|
+
elasticProduct: {
|
|
47
|
+
id: product.id,
|
|
48
|
+
title: product.title,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}, [track, product]);
|
|
53
|
+
react_1.default.useEffect(() => {
|
|
54
|
+
if (inView)
|
|
55
|
+
handleView();
|
|
56
|
+
}, [inView]);
|
|
57
|
+
if (render)
|
|
58
|
+
return render(Object.assign(Object.assign(Object.assign({}, props), productPrice), { itemRef: ref, handleClick }));
|
|
59
|
+
return (react_1.default.createElement("article", { ref: ref },
|
|
40
60
|
react_1.default.createElement("a", { onClick: handleClick, href: `/products/${product.handle}` },
|
|
41
61
|
product.image && react_1.default.createElement("img", { src: product.image, width: "100%" }),
|
|
42
62
|
product.title),
|
|
@@ -11,6 +11,7 @@ const ResultPagination_1 = require("./ResultPagination");
|
|
|
11
11
|
const ResultCardCallout_1 = require("./ResultCardCallout");
|
|
12
12
|
const ResultLoadMoreButton_1 = require("./ResultLoadMoreButton");
|
|
13
13
|
const ResultPaginationNextPrev_1 = require("./ResultPaginationNextPrev");
|
|
14
|
+
const __1 = require("../");
|
|
14
15
|
const hooks_1 = require("../hooks");
|
|
15
16
|
const elastic_1 = require("../types/elastic");
|
|
16
17
|
const ResultList = (props) => {
|
|
@@ -24,7 +25,8 @@ exports.ResultList = ResultList;
|
|
|
24
25
|
const ResultListInner = (props) => {
|
|
25
26
|
const { gridColumns, renderError, renderAfter, renderBefore, renderLoading, listClassName, renderResults, renderNoResults, renderResultCard, renderLoadMoreButton, renderResultCardCallout, reactivesearchResultProps, } = props;
|
|
26
27
|
const filterStack = (0, hooks_1.useFilterStack)();
|
|
27
|
-
const { instantSearch } = (0, hooks_1.useSearch)();
|
|
28
|
+
const { instantSearch, searchQuery } = (0, hooks_1.useSearch)();
|
|
29
|
+
const { track } = (0, __1.useAnalytics)();
|
|
28
30
|
const initialSearchHasRun = react_1.default.useMemo(() => "undefined" !==
|
|
29
31
|
typeof reactivesearchResultProps.resultStats.numberOfResults, [reactivesearchResultProps]);
|
|
30
32
|
const styleProp = react_1.default.useMemo(() => ({
|
|
@@ -45,6 +47,11 @@ const ResultListInner = (props) => {
|
|
|
45
47
|
return react_1.default.createElement("div", null, "Loading...");
|
|
46
48
|
}
|
|
47
49
|
if (!reactivesearchResultProps.resultStats.numberOfResults) {
|
|
50
|
+
if (searchQuery)
|
|
51
|
+
track({
|
|
52
|
+
eventName: "zeroResults",
|
|
53
|
+
payload: { searchTerm: searchQuery },
|
|
54
|
+
});
|
|
48
55
|
if (renderNoResults)
|
|
49
56
|
return renderNoResults();
|
|
50
57
|
return react_1.default.createElement("div", null, "No results");
|
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.
|
|
4
|
+
"version": "3.5.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"ahooks": "2.10.11",
|
|
33
33
|
"axios": "0.26.1",
|
|
34
34
|
"currency.js": "2.0.4",
|
|
35
|
-
"debug": "4.3.2"
|
|
35
|
+
"debug": "4.3.2",
|
|
36
|
+
"react-intersection-observer": "9.1.0"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
38
39
|
"@appbaseio/reactivesearch": "^3.16.1",
|