@gravity-ui/blog-constructor 2.1.0-alpha.0 → 2.1.0-alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- package/build/cjs/components/PostInfo/components/Save.js +10 -6
- package/build/cjs/components/PostInfo/components/Sharing.js +16 -9
- package/build/cjs/models/common.d.ts +4 -0
- package/build/cjs/models/common.js +7 -2
- package/build/esm/components/PostInfo/components/Save.js +9 -5
- package/build/esm/components/PostInfo/components/Sharing.js +17 -10
- package/build/esm/models/common.d.ts +4 -0
- package/build/esm/models/common.js +6 -1
- package/package.json +1 -1
- package/server/models/common.d.ts +4 -0
- package/server/models/common.js +7 -2
@@ -27,16 +27,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
29
|
exports.Save = void 0;
|
30
|
-
const
|
30
|
+
const page_constructor_1 = require("@gravity-ui/page-constructor");
|
31
31
|
const uikit_1 = require("@gravity-ui/uikit");
|
32
|
-
const
|
33
|
-
const
|
32
|
+
const react_1 = __importStar(require("react"));
|
33
|
+
const UserContext_1 = require("../../../contexts/UserContext");
|
34
|
+
const metrika_js_1 = __importDefault(require("../../../counters/metrika.js"));
|
34
35
|
const utils_1 = require("../../../counters/utils");
|
35
36
|
// @ts-ignore
|
36
|
-
const metrika_js_1 = __importDefault(require("../../../counters/metrika.js"));
|
37
37
|
const Save_1 = require("../../../icons/Save");
|
38
38
|
const SaveFilled_1 = require("../../../icons/SaveFilled");
|
39
|
-
const
|
39
|
+
const common_1 = require("../../../models/common");
|
40
|
+
const cn_1 = require("../../../utils/cn");
|
41
|
+
const common_2 = require("../../../utils/common");
|
40
42
|
const ICON_SIZE = 16;
|
41
43
|
const b = (0, cn_1.block)('post-info');
|
42
44
|
/**
|
@@ -53,6 +55,7 @@ const b = (0, cn_1.block)('post-info');
|
|
53
55
|
*/
|
54
56
|
const Save = ({ title, postId, hasUserLike, handleUserLike, metrikaGoal, size, theme, dataQa, }) => {
|
55
57
|
const { uid } = (0, react_1.useContext)(UserContext_1.UserContext);
|
58
|
+
const handleAnalytics = (0, page_constructor_1.useAnalytics)(common_1.DefaultEventNames.SaveButton);
|
56
59
|
return (react_1.default.createElement("div", { className: b('item', { size }), onClick: (event) => {
|
57
60
|
// both preventDefault and stopImmediatePropagation required to work properly
|
58
61
|
// https://stackoverflow.com/questions/24415631/reactjs-syntheticevent-stoppropagation-only-works-with-react-events
|
@@ -61,9 +64,10 @@ const Save = ({ title, postId, hasUserLike, handleUserLike, metrikaGoal, size, t
|
|
61
64
|
if (!uid) {
|
62
65
|
return;
|
63
66
|
}
|
64
|
-
(0,
|
67
|
+
(0, common_2.postLikeStatus)(postId, Boolean(hasUserLike));
|
65
68
|
handleUserLike();
|
66
69
|
metrika_js_1.default.reachGoal(utils_1.MetrikaCounter.CrossSite, metrikaGoal);
|
70
|
+
handleAnalytics();
|
67
71
|
}, "data-qa": `${dataQa ? dataQa + '-' : ''}save` },
|
68
72
|
react_1.default.createElement("div", { className: b('content', { cursor: Boolean(uid), theme }) },
|
69
73
|
react_1.default.createElement("span", { className: b('icon') },
|
@@ -27,28 +27,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
29
|
exports.Sharing = void 0;
|
30
|
-
const
|
30
|
+
const page_constructor_1 = require("@gravity-ui/page-constructor");
|
31
31
|
const uikit_1 = require("@gravity-ui/uikit");
|
32
|
+
const react_1 = __importStar(require("react"));
|
32
33
|
const MobileContext_1 = require("../../../contexts/MobileContext");
|
33
|
-
const RouterContext_1 = require("../../../contexts/RouterContext");
|
34
34
|
const PostPageContext_1 = require("../../../contexts/PostPageContext");
|
35
|
+
const RouterContext_1 = require("../../../contexts/RouterContext");
|
36
|
+
const metrika_js_1 = __importDefault(require("../../../counters/metrika.js"));
|
37
|
+
const utils_1 = require("../../../counters/utils");
|
35
38
|
const i18n_1 = require("../../../i18n");
|
36
|
-
const
|
39
|
+
const ShareArrowUp_1 = require("../../../icons/ShareArrowUp");
|
40
|
+
const common_1 = require("../../../models/common");
|
37
41
|
const cn_1 = require("../../../utils/cn");
|
38
|
-
const
|
42
|
+
const common_2 = require("../../../utils/common");
|
39
43
|
// @ts-ignore
|
40
|
-
const metrika_js_1 = __importDefault(require("../../../counters/metrika.js"));
|
41
|
-
const ShareArrowUp_1 = require("../../../icons/ShareArrowUp");
|
42
44
|
const b = (0, cn_1.block)('post-info');
|
43
45
|
const Sharing = ({ theme, metrikaGoal }) => {
|
44
46
|
const router = (0, react_1.useContext)(RouterContext_1.RouterContext);
|
45
47
|
const isMobile = (0, react_1.useContext)(MobileContext_1.MobileContext);
|
46
48
|
const { shareOptions } = (0, react_1.useContext)(PostPageContext_1.PostPageContext);
|
47
|
-
const
|
49
|
+
const handleAnalyticsGlobal = (0, page_constructor_1.useAnalytics)(common_1.DefaultEventNames.ShareButton);
|
50
|
+
const handleMetrika = (0, react_1.useCallback)(() => {
|
48
51
|
metrika_js_1.default.reachGoal(utils_1.MetrikaCounter.CrossSite, metrikaGoal);
|
49
|
-
};
|
52
|
+
}, [metrikaGoal]);
|
53
|
+
const handleAnalytics = (0, react_1.useCallback)(() => {
|
54
|
+
handleAnalyticsGlobal();
|
55
|
+
handleMetrika();
|
56
|
+
}, [handleAnalyticsGlobal, handleMetrika]);
|
50
57
|
return (react_1.default.createElement("div", { className: b('item') },
|
51
58
|
react_1.default.createElement("span", { className: b('icon') },
|
52
|
-
react_1.default.createElement(uikit_1.SharePopover, { url: (0,
|
59
|
+
react_1.default.createElement(uikit_1.SharePopover, { url: (0, common_2.getAbsolutePath)(router), className: b('share'), iconClass: b('share-icon'), switcherClassName: b('switcher', { theme }), tooltipClassName: b('popup'), useWebShareApi: isMobile, direction: 'column', buttonTitle: (0, i18n_1.i18)(i18n_1.Keyset.ActionShare), customIcon: ShareArrowUp_1.ShareArrowUp, placement: "bottom", openByHover: false, shareOptions: shareOptions, handleMetrika: handleAnalytics }))));
|
53
60
|
};
|
54
61
|
exports.Sharing = Sharing;
|
@@ -149,3 +149,7 @@ export type HandleChangeQueryParams = (params: Query) => void;
|
|
149
149
|
export type SetQueryType = (params: Query, options?: {
|
150
150
|
[y: string]: boolean;
|
151
151
|
}) => Promise<void> | void;
|
152
|
+
export declare enum DefaultEventNames {
|
153
|
+
ShareButton = "share-button-click",
|
154
|
+
SaveButton = "save-button-click"
|
155
|
+
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.BlockType = exports.Theme = void 0;
|
3
|
+
exports.DefaultEventNames = exports.BlockType = exports.Theme = void 0;
|
4
4
|
var Theme;
|
5
5
|
(function (Theme) {
|
6
6
|
Theme["Light"] = "light";
|
@@ -19,4 +19,9 @@ var BlockType;
|
|
19
19
|
BlockType["Suggest"] = "blog-suggest-block";
|
20
20
|
BlockType["Meta"] = "blog-meta-block";
|
21
21
|
BlockType["Feed"] = "blog-feed-block";
|
22
|
-
})(BlockType = exports.BlockType || (exports.BlockType = {}));
|
22
|
+
})(BlockType = exports.BlockType || (exports.BlockType = {}));
|
23
|
+
var DefaultEventNames;
|
24
|
+
(function (DefaultEventNames) {
|
25
|
+
DefaultEventNames["ShareButton"] = "share-button-click";
|
26
|
+
DefaultEventNames["SaveButton"] = "save-button-click";
|
27
|
+
})(DefaultEventNames = exports.DefaultEventNames || (exports.DefaultEventNames = {}));
|
@@ -1,13 +1,15 @@
|
|
1
|
-
import
|
1
|
+
import { useAnalytics } from '@gravity-ui/page-constructor';
|
2
2
|
import { Icon } from '@gravity-ui/uikit';
|
3
|
-
import {
|
4
|
-
import {
|
3
|
+
import React, { useContext } from 'react';
|
4
|
+
import { UserContext } from '../../../contexts/UserContext';
|
5
|
+
import metrika from '../../../counters/metrika.js';
|
5
6
|
import { MetrikaCounter } from '../../../counters/utils';
|
6
7
|
// @ts-ignore
|
7
|
-
import metrika from '../../../counters/metrika.js';
|
8
8
|
import { Save as SaveIcon } from '../../../icons/Save';
|
9
9
|
import { SaveFilled } from '../../../icons/SaveFilled';
|
10
|
-
import {
|
10
|
+
import { DefaultEventNames } from '../../../models/common';
|
11
|
+
import { block } from '../../../utils/cn';
|
12
|
+
import { postLikeStatus } from '../../../utils/common';
|
11
13
|
import '../PostInfo.css';
|
12
14
|
const ICON_SIZE = 16;
|
13
15
|
const b = block('post-info');
|
@@ -25,6 +27,7 @@ const b = block('post-info');
|
|
25
27
|
*/
|
26
28
|
export const Save = ({ title, postId, hasUserLike, handleUserLike, metrikaGoal, size, theme, dataQa, }) => {
|
27
29
|
const { uid } = useContext(UserContext);
|
30
|
+
const handleAnalytics = useAnalytics(DefaultEventNames.SaveButton);
|
28
31
|
return (React.createElement("div", { className: b('item', { size }), onClick: (event) => {
|
29
32
|
// both preventDefault and stopImmediatePropagation required to work properly
|
30
33
|
// https://stackoverflow.com/questions/24415631/reactjs-syntheticevent-stoppropagation-only-works-with-react-events
|
@@ -36,6 +39,7 @@ export const Save = ({ title, postId, hasUserLike, handleUserLike, metrikaGoal,
|
|
36
39
|
postLikeStatus(postId, Boolean(hasUserLike));
|
37
40
|
handleUserLike();
|
38
41
|
metrika.reachGoal(MetrikaCounter.CrossSite, metrikaGoal);
|
42
|
+
handleAnalytics();
|
39
43
|
}, "data-qa": `${dataQa ? dataQa + '-' : ''}save` },
|
40
44
|
React.createElement("div", { className: b('content', { cursor: Boolean(uid), theme }) },
|
41
45
|
React.createElement("span", { className: b('icon') },
|
@@ -1,25 +1,32 @@
|
|
1
|
-
import
|
1
|
+
import { useAnalytics } from '@gravity-ui/page-constructor';
|
2
2
|
import { SharePopover } from '@gravity-ui/uikit';
|
3
|
+
import React, { useCallback, useContext } from 'react';
|
3
4
|
import { MobileContext } from '../../../contexts/MobileContext';
|
4
|
-
import { RouterContext } from '../../../contexts/RouterContext';
|
5
5
|
import { PostPageContext } from '../../../contexts/PostPageContext';
|
6
|
-
import {
|
7
|
-
import { getAbsolutePath } from '../../../utils/common';
|
8
|
-
import { block } from '../../../utils/cn';
|
9
|
-
import { MetrikaCounter } from '../../../counters/utils';
|
10
|
-
// @ts-ignore
|
6
|
+
import { RouterContext } from '../../../contexts/RouterContext';
|
11
7
|
import metrika from '../../../counters/metrika.js';
|
8
|
+
import { MetrikaCounter } from '../../../counters/utils';
|
9
|
+
import { Keyset, i18 } from '../../../i18n';
|
12
10
|
import { ShareArrowUp } from '../../../icons/ShareArrowUp';
|
11
|
+
import { DefaultEventNames } from '../../../models/common';
|
12
|
+
import { block } from '../../../utils/cn';
|
13
|
+
import { getAbsolutePath } from '../../../utils/common';
|
14
|
+
// @ts-ignore
|
13
15
|
import '../PostInfo.css';
|
14
16
|
const b = block('post-info');
|
15
17
|
export const Sharing = ({ theme, metrikaGoal }) => {
|
16
18
|
const router = useContext(RouterContext);
|
17
19
|
const isMobile = useContext(MobileContext);
|
18
20
|
const { shareOptions } = useContext(PostPageContext);
|
19
|
-
const
|
21
|
+
const handleAnalyticsGlobal = useAnalytics(DefaultEventNames.ShareButton);
|
22
|
+
const handleMetrika = useCallback(() => {
|
20
23
|
metrika.reachGoal(MetrikaCounter.CrossSite, metrikaGoal);
|
21
|
-
};
|
24
|
+
}, [metrikaGoal]);
|
25
|
+
const handleAnalytics = useCallback(() => {
|
26
|
+
handleAnalyticsGlobal();
|
27
|
+
handleMetrika();
|
28
|
+
}, [handleAnalyticsGlobal, handleMetrika]);
|
22
29
|
return (React.createElement("div", { className: b('item') },
|
23
30
|
React.createElement("span", { className: b('icon') },
|
24
|
-
React.createElement(SharePopover, { url: getAbsolutePath(router), className: b('share'), iconClass: b('share-icon'), switcherClassName: b('switcher', { theme }), tooltipClassName: b('popup'), useWebShareApi: isMobile, direction: 'column', buttonTitle: i18(Keyset.ActionShare), customIcon: ShareArrowUp, placement: "bottom", openByHover: false, shareOptions: shareOptions, handleMetrika:
|
31
|
+
React.createElement(SharePopover, { url: getAbsolutePath(router), className: b('share'), iconClass: b('share-icon'), switcherClassName: b('switcher', { theme }), tooltipClassName: b('popup'), useWebShareApi: isMobile, direction: 'column', buttonTitle: i18(Keyset.ActionShare), customIcon: ShareArrowUp, placement: "bottom", openByHover: false, shareOptions: shareOptions, handleMetrika: handleAnalytics }))));
|
25
32
|
};
|
@@ -149,3 +149,7 @@ export type HandleChangeQueryParams = (params: Query) => void;
|
|
149
149
|
export type SetQueryType = (params: Query, options?: {
|
150
150
|
[y: string]: boolean;
|
151
151
|
}) => Promise<void> | void;
|
152
|
+
export declare enum DefaultEventNames {
|
153
|
+
ShareButton = "share-button-click",
|
154
|
+
SaveButton = "save-button-click"
|
155
|
+
}
|
@@ -16,4 +16,9 @@ export var BlockType;
|
|
16
16
|
BlockType["Suggest"] = "blog-suggest-block";
|
17
17
|
BlockType["Meta"] = "blog-meta-block";
|
18
18
|
BlockType["Feed"] = "blog-feed-block";
|
19
|
-
})(BlockType || (BlockType = {}));
|
19
|
+
})(BlockType || (BlockType = {}));
|
20
|
+
export var DefaultEventNames;
|
21
|
+
(function (DefaultEventNames) {
|
22
|
+
DefaultEventNames["ShareButton"] = "share-button-click";
|
23
|
+
DefaultEventNames["SaveButton"] = "save-button-click";
|
24
|
+
})(DefaultEventNames || (DefaultEventNames = {}));
|
package/package.json
CHANGED
@@ -149,3 +149,7 @@ export type HandleChangeQueryParams = (params: Query) => void;
|
|
149
149
|
export type SetQueryType = (params: Query, options?: {
|
150
150
|
[y: string]: boolean;
|
151
151
|
}) => Promise<void> | void;
|
152
|
+
export declare enum DefaultEventNames {
|
153
|
+
ShareButton = "share-button-click",
|
154
|
+
SaveButton = "save-button-click"
|
155
|
+
}
|
package/server/models/common.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.BlockType = exports.Theme = void 0;
|
3
|
+
exports.DefaultEventNames = exports.BlockType = exports.Theme = void 0;
|
4
4
|
var Theme;
|
5
5
|
(function (Theme) {
|
6
6
|
Theme["Light"] = "light";
|
@@ -19,4 +19,9 @@ var BlockType;
|
|
19
19
|
BlockType["Suggest"] = "blog-suggest-block";
|
20
20
|
BlockType["Meta"] = "blog-meta-block";
|
21
21
|
BlockType["Feed"] = "blog-feed-block";
|
22
|
-
})(BlockType = exports.BlockType || (exports.BlockType = {}));
|
22
|
+
})(BlockType = exports.BlockType || (exports.BlockType = {}));
|
23
|
+
var DefaultEventNames;
|
24
|
+
(function (DefaultEventNames) {
|
25
|
+
DefaultEventNames["ShareButton"] = "share-button-click";
|
26
|
+
DefaultEventNames["SaveButton"] = "save-button-click";
|
27
|
+
})(DefaultEventNames = exports.DefaultEventNames || (exports.DefaultEventNames = {}));
|