@twreporter/react-components 9.0.2 → 9.1.0-rc.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.
- package/CHANGELOG.md +22 -0
- package/lib/badge/badge.stories.js +3 -9
- package/lib/badge/index.js +8 -24
- package/lib/bookmark-list/bookmark.js +20 -69
- package/lib/bookmark-list/bookmarks.js +10 -40
- package/lib/bookmark-list/customized-link.js +4 -14
- package/lib/bookmark-list/image-wrapper.js +9 -36
- package/lib/bookmark-list/index.js +36 -91
- package/lib/bookmark-list/redirect-to-sign-in.js +1 -10
- package/lib/bookmark-list/stories/bookmark.stories.js +3 -9
- package/lib/bookmark-widget/index.js +91 -220
- package/lib/button/components/iconButton.js +15 -34
- package/lib/button/components/iconWithTextButton.js +16 -31
- package/lib/button/components/link.js +27 -45
- package/lib/button/components/menuButton.js +18 -38
- package/lib/button/components/pillButton.js +31 -60
- package/lib/button/components/textButton.js +29 -61
- package/lib/button/components/toggleButton.js +11 -31
- package/lib/button/enums/index.js +4 -7
- package/lib/button/index.js +5 -18
- package/lib/button/stories/iconButton.stories.js +4 -15
- package/lib/button/stories/iconWithTextButton.stories.js +4 -13
- package/lib/button/stories/link.stories.js +9 -27
- package/lib/button/stories/menuButton.stories.js +3 -10
- package/lib/button/stories/pillButton.stories.js +4 -15
- package/lib/button/stories/textButton.stories.js +4 -15
- package/lib/button/stories/toggleButton.stories.js +3 -8
- package/lib/button/utils/size.js +3 -8
- package/lib/button/utils/theme.js +11 -102
- package/lib/card/components/article-card.js +31 -59
- package/lib/card/components/dialog.js +7 -22
- package/lib/card/components/short-story.js +24 -44
- package/lib/card/index.js +2 -8
- package/lib/card/stories/articleCard.stories.js +3 -14
- package/lib/card/stories/dialog.stories.js +3 -11
- package/lib/card/stories/shortStory.stories.js +3 -16
- package/lib/checkbox/checkbox.stories.js +3 -8
- package/lib/checkbox/index.js +10 -31
- package/lib/color.stories.js +9 -34
- package/lib/confirmation/index.js +7 -29
- package/lib/customized-link.js +5 -18
- package/lib/divider.js +3 -19
- package/lib/divider.stories.js +5 -18
- package/lib/donation-link.js +2 -14
- package/lib/empty-state/enums/index.js +2 -3
- package/lib/empty-state/index.js +20 -41
- package/lib/empty-state/stories/empty-guide.stories.js +3 -11
- package/lib/error/index.js +3 -8
- package/lib/error/message.js +3 -44
- package/lib/footer/constants/links.js +10 -16
- package/lib/footer/footer.stories.js +3 -10
- package/lib/footer/index.js +5 -40
- package/lib/footer/link.js +15 -46
- package/lib/footer/logo.js +12 -32
- package/lib/hook/index.js +3 -18
- package/lib/hook/use-bookmark.js +21 -47
- package/lib/hook/use-font-face-observer.js +9 -24
- package/lib/hook/use-outside-click.js +4 -9
- package/lib/icon/enum/index.js +5 -9
- package/lib/icon/index.js +49 -105
- package/lib/icon/stories/arrow.stories.js +7 -16
- package/lib/icon/stories/article.stories.js +2 -7
- package/lib/icon/stories/bookmark.stories.js +6 -14
- package/lib/icon/stories/changeIconColor.stories.js +2 -12
- package/lib/icon/stories/clock.stories.js +2 -7
- package/lib/icon/stories/copy.stories.js +2 -7
- package/lib/icon/stories/cross.stories.js +2 -7
- package/lib/icon/stories/hamburger.stories.js +2 -7
- package/lib/icon/stories/home.stories.js +2 -7
- package/lib/icon/stories/letter.stories.js +2 -7
- package/lib/icon/stories/loading.stories.js +2 -7
- package/lib/icon/stories/member.stories.js +2 -7
- package/lib/icon/stories/printer.stories.js +2 -7
- package/lib/icon/stories/search.stories.js +2 -7
- package/lib/icon/stories/share.stories.js +2 -7
- package/lib/icon/stories/socialMedia.stories.js +2 -8
- package/lib/icon/stories/text.stories.js +2 -7
- package/lib/icon/stories/topic.stories.js +2 -7
- package/lib/image-with-fallback.js +22 -52
- package/lib/input/components/search-bar.js +40 -85
- package/lib/input/components/text-field.js +20 -40
- package/lib/input/enums/index.js +6 -8
- package/lib/input/index.js +2 -7
- package/lib/input/stories/search-bar.stories.js +3 -16
- package/lib/input/stories/text-field.stories.js +3 -14
- package/lib/input/utils/theme.js +2 -9
- package/lib/is-fetching-wrapper.js +16 -48
- package/lib/junior-link.js +6 -29
- package/lib/link-with-tracker.js +14 -47
- package/lib/listing-page/components/card-list.js +20 -51
- package/lib/listing-page/components/image.js +15 -46
- package/lib/listing-page/components/list-item.js +18 -65
- package/lib/listing-page/components/list.js +17 -61
- package/lib/listing-page/components/page-content.js +2 -12
- package/lib/listing-page/components/topics/index.js +26 -74
- package/lib/listing-page/components/topics/post-item.js +14 -47
- package/lib/listing-page/components/topics/posts.js +1 -10
- package/lib/listing-page/components/topics/section.js +3 -25
- package/lib/listing-page/components/topics/topic-item.js +17 -56
- package/lib/listing-page/constants/mockup-spec.js +2 -3
- package/lib/listing-page/constants/predefined-css.js +2 -10
- package/lib/listing-page/constants/prop-types.js +2 -7
- package/lib/listing-page/constants/topics.js +2 -3
- package/lib/listing-page/index.js +2 -8
- package/lib/listing-page/stories/cardList.stories.js +3 -10
- package/lib/logo/components/logo-footer.js +6 -21
- package/lib/logo/components/logo-header.js +7 -23
- package/lib/logo/components/logo-loading-fallback.js +4 -13
- package/lib/logo/components/logo-symbol.js +7 -23
- package/lib/logo/index.js +2 -9
- package/lib/logo/stories/logoFooter.stories.js +2 -8
- package/lib/logo/stories/logoHeader.stories.js +3 -9
- package/lib/logo/stories/logoLoadingFallback.stories.js +2 -8
- package/lib/logo/stories/logoSymbol.stories.js +3 -9
- package/lib/logo/utils/path.js +2 -9
- package/lib/material-icon.js +9 -17
- package/lib/mobile-member-role-card/index.js +22 -49
- package/lib/mobile-member-role-card/stories/member-role-card.stories.js +3 -12
- package/lib/mobile-pop-up-modal.js +10 -44
- package/lib/more.js +10 -37
- package/lib/pagination/index.js +17 -83
- package/lib/podcast-link.js +6 -29
- package/lib/rwd.js +6 -26
- package/lib/shared-enum.js +2 -3
- package/lib/side-bar/index.js +16 -59
- package/lib/simple-header/index.js +2 -12
- package/lib/simple-header/simpleHeader.stories.js +3 -8
- package/lib/snack-bar/components/snack-bar.js +9 -20
- package/lib/snack-bar/hooks/use-snack-bar.js +12 -25
- package/lib/snack-bar/index.js +2 -7
- package/lib/snack-bar/stories/snackBar.stories.js +12 -29
- package/lib/snack-bar/utils/theme.js +3 -9
- package/lib/storybook/constants/index.js +3 -11
- package/lib/storybook/utils/get-enum-arg.js +2 -5
- package/lib/table-of-contents/index.js +62 -128
- package/lib/text/constants/headline-type.js +5 -8
- package/lib/text/enums/index.js +3 -5
- package/lib/text/headline.js +14 -41
- package/lib/text/paragraph.js +13 -34
- package/lib/text/stories/headline.stories.js +8 -21
- package/lib/text/stories/paragraph.stories.js +6 -17
- package/lib/text/utils/webfonts.js +9 -22
- package/lib/title-bar/components/tab.js +27 -69
- package/lib/title-bar/components/title1.js +6 -17
- package/lib/title-bar/components/title2.js +7 -23
- package/lib/title-bar/index.js +2 -8
- package/lib/title-bar/stories/tab.stories.js +5 -12
- package/lib/title-bar/stories/title1.stories.js +5 -12
- package/lib/title-bar/stories/title2.stories.js +3 -11
- package/lib/utils/link-with-params.js +0 -5
- package/package.json +4 -4
- package/lib/hook/use-store.js +0 -46
|
@@ -1,71 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports["default"] = void 0;
|
|
9
|
-
|
|
7
|
+
var _react = require("react");
|
|
10
8
|
var _reactRedux = require("react-redux");
|
|
11
|
-
|
|
9
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
12
10
|
var _signInHref = require("@twreporter/core/lib/utils/sign-in-href");
|
|
13
|
-
|
|
14
|
-
var _propTypes = _interopRequireDefault(require("@twreporter/core/lib/constants/prop-types"));
|
|
15
|
-
|
|
16
|
-
var _propTypes2 = _interopRequireDefault(require("prop-types"));
|
|
17
|
-
|
|
18
|
-
var _react = _interopRequireDefault(require("react"));
|
|
19
|
-
|
|
11
|
+
var _propTypes2 = _interopRequireDefault(require("@twreporter/core/lib/constants/prop-types"));
|
|
20
12
|
var _redux = _interopRequireDefault(require("@twreporter/redux"));
|
|
21
|
-
|
|
22
13
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
23
|
-
|
|
24
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
25
|
-
|
|
26
|
-
function ownKeys(
|
|
27
|
-
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
33
|
-
|
|
34
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
35
|
-
|
|
36
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
37
|
-
|
|
38
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
39
|
-
|
|
40
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
41
|
-
|
|
42
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
43
|
-
|
|
44
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
45
|
-
|
|
46
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
47
|
-
|
|
48
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
49
|
-
|
|
50
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
51
|
-
|
|
15
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
16
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
20
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } // @twreporter
|
|
21
|
+
// lodash
|
|
52
22
|
var _ = {
|
|
53
23
|
get: _get["default"]
|
|
54
24
|
};
|
|
55
25
|
var _twreporterRedux$acti = _redux["default"].actions,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
26
|
+
createSingleBookmark = _twreporterRedux$acti.createSingleBookmark,
|
|
27
|
+
deleteSingleBookmark = _twreporterRedux$acti.deleteSingleBookmark,
|
|
28
|
+
getSingleBookmark = _twreporterRedux$acti.getSingleBookmark;
|
|
59
29
|
var reduxStatePropKeys = _redux["default"].reduxStateFields;
|
|
60
|
-
|
|
61
30
|
function getHostFromWindowLocation() {
|
|
62
31
|
var defaultHost = 'https://www.twreporter.org';
|
|
63
|
-
|
|
64
32
|
try {
|
|
65
33
|
var _window$location = window.location,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
34
|
+
host = _window$location.host,
|
|
35
|
+
protocol = _window$location.protocol;
|
|
69
36
|
if (host && protocol) {
|
|
70
37
|
return "".concat(protocol, "//").concat(host);
|
|
71
38
|
} else {
|
|
@@ -75,185 +42,89 @@ function getHostFromWindowLocation() {
|
|
|
75
42
|
} catch (err) {
|
|
76
43
|
console.warn('Error on getting `host` and `protocol` from `window.location`:', err);
|
|
77
44
|
}
|
|
45
|
+
return defaultHost;
|
|
78
46
|
}
|
|
79
|
-
|
|
80
|
-
var
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
function
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
toAutoCheck = _this$props.toAutoCheck;
|
|
116
|
-
|
|
117
|
-
if (isAuthed && toAutoCheck && !this.checkIfThisArticleBookmarked()) {
|
|
118
|
-
var _this$props2 = this.props,
|
|
119
|
-
jwt = _this$props2.jwt,
|
|
120
|
-
userID = _this$props2.userID,
|
|
121
|
-
_getSingleBookmark = _this$props2.getSingleBookmark;
|
|
122
|
-
|
|
123
|
-
_getSingleBookmark(jwt, userID, articleSlug, getHostFromWindowLocation());
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
console.error('`this.props.articleMeta.slug` must be an unempty string, but is', articleSlug);
|
|
47
|
+
var BookmarkWidget = function BookmarkWidget(_ref) {
|
|
48
|
+
var articleMeta = _ref.articleMeta,
|
|
49
|
+
renderIcon = _ref.renderIcon,
|
|
50
|
+
_ref$toAutoCheck = _ref.toAutoCheck,
|
|
51
|
+
toAutoCheck = _ref$toAutoCheck === void 0 ? true : _ref$toAutoCheck;
|
|
52
|
+
var dispatch = (0, _reactRedux.useDispatch)();
|
|
53
|
+
var jwt = (0, _reactRedux.useSelector)(function (state) {
|
|
54
|
+
return _.get(state, [reduxStatePropKeys.auth, 'accessToken']);
|
|
55
|
+
});
|
|
56
|
+
var userID = (0, _reactRedux.useSelector)(function (state) {
|
|
57
|
+
return _.get(state, [reduxStatePropKeys.auth, 'userInfo', 'user_id']);
|
|
58
|
+
});
|
|
59
|
+
var isAuthed = (0, _reactRedux.useSelector)(function (state) {
|
|
60
|
+
return _.get(state, [reduxStatePropKeys.auth, 'isAuthed']);
|
|
61
|
+
});
|
|
62
|
+
var bookmark = (0, _reactRedux.useSelector)(function (state) {
|
|
63
|
+
var bookmarkInStore = _.get(state, [reduxStatePropKeys.bookmarkWidget, 'bookmark']);
|
|
64
|
+
var currentSlug = _.get(articleMeta, 'slug');
|
|
65
|
+
return currentSlug && currentSlug === _.get(bookmarkInStore, 'slug') ? bookmarkInStore : null;
|
|
66
|
+
});
|
|
67
|
+
(0, _react.useEffect)(function () {
|
|
68
|
+
/* TODO: Implement `status` for bookmark widget in redux reducer and action:
|
|
69
|
+
There should be different states below for the bookmark widget status of an article:
|
|
70
|
+
unknown: It has not checked the bookmark status yet
|
|
71
|
+
isChecking: The request to check was made but has not gotten the response yet
|
|
72
|
+
bookmarked: The article is bookmarked
|
|
73
|
+
notBookmarked: The article is not bookmarked
|
|
74
|
+
invalid: There's an error or there's no valid authentication info
|
|
75
|
+
The current code does not distinguish the `unknown`, `notBookmarked`, `isChecking`, and `invalid` situation.
|
|
76
|
+
The best result is that we only send request to check bookmark when the status is `unknown`.
|
|
77
|
+
But now we send request when there's no bookmark data for this component in the redux store when `componentDidMount`, no matter what's the reason of it.
|
|
78
|
+
*/
|
|
79
|
+
var articleSlug = _.get(articleMeta, 'slug');
|
|
80
|
+
if (articleSlug && typeof articleSlug === 'string') {
|
|
81
|
+
if (isAuthed && toAutoCheck && !checkIfThisArticleBookmarked()) {
|
|
82
|
+
dispatch(getSingleBookmark(jwt, userID, articleSlug, getHostFromWindowLocation()));
|
|
127
83
|
}
|
|
84
|
+
} else {
|
|
85
|
+
console.error('`articleMeta.slug` must be a non-empty string, but is', articleSlug);
|
|
128
86
|
}
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
var
|
|
133
|
-
|
|
134
|
-
jwt = _this$props3.jwt;
|
|
135
|
-
|
|
136
|
-
if (!isAuthed || !jwt) {
|
|
137
|
-
var currentHref = typeof window === 'undefined' ? '' : window.location.href;
|
|
138
|
-
window.location.href = (0, _signInHref.getSignInHref)(currentHref);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}, {
|
|
142
|
-
key: "addCurrentPageToBookmarks",
|
|
143
|
-
value: function addCurrentPageToBookmarks() {
|
|
144
|
-
this.redirectToLoginPageIfNotAuthorized();
|
|
145
|
-
var _this$props4 = this.props,
|
|
146
|
-
jwt = _this$props4.jwt,
|
|
147
|
-
userID = _this$props4.userID,
|
|
148
|
-
createSingleBookmark = _this$props4.createSingleBookmark,
|
|
149
|
-
articleMeta = _this$props4.articleMeta;
|
|
150
|
-
|
|
151
|
-
var bookmarkToBeCreated = _objectSpread(_objectSpread({}, articleMeta), {}, {
|
|
152
|
-
host: getHostFromWindowLocation()
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
return createSingleBookmark(jwt, userID, bookmarkToBeCreated);
|
|
156
|
-
}
|
|
157
|
-
}, {
|
|
158
|
-
key: "removeCurrentPageFromBookmarks",
|
|
159
|
-
value: function removeCurrentPageFromBookmarks() {
|
|
160
|
-
this.redirectToLoginPageIfNotAuthorized();
|
|
161
|
-
var _this$props5 = this.props,
|
|
162
|
-
jwt = _this$props5.jwt,
|
|
163
|
-
userID = _this$props5.userID,
|
|
164
|
-
deleteSingleBookmark = _this$props5.deleteSingleBookmark,
|
|
165
|
-
bookmark = _this$props5.bookmark;
|
|
166
|
-
|
|
167
|
-
var bookmarkID = _.get(bookmark, 'id');
|
|
168
|
-
|
|
169
|
-
if (bookmarkID) {
|
|
170
|
-
deleteSingleBookmark(jwt, userID, bookmarkID);
|
|
171
|
-
} else {
|
|
172
|
-
console.error('Error on deleting bookmark with `BookmarkWidget`: No valid bookmark id.');
|
|
173
|
-
}
|
|
87
|
+
}, [articleMeta, isAuthed, toAutoCheck, jwt, userID, dispatch]);
|
|
88
|
+
var redirectToLoginPageIfNotAuthorized = function redirectToLoginPageIfNotAuthorized() {
|
|
89
|
+
if (!isAuthed || !jwt) {
|
|
90
|
+
var currentHref = typeof window === 'undefined' ? '' : window.location.href;
|
|
91
|
+
window.location.href = (0, _signInHref.getSignInHref)(currentHref);
|
|
174
92
|
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return Boolean(bookmark);
|
|
93
|
+
};
|
|
94
|
+
var addCurrentPageToBookmarks = function addCurrentPageToBookmarks() {
|
|
95
|
+
redirectToLoginPageIfNotAuthorized();
|
|
96
|
+
var bookmarkToBeCreated = _objectSpread(_objectSpread({}, articleMeta), {}, {
|
|
97
|
+
host: getHostFromWindowLocation()
|
|
98
|
+
});
|
|
99
|
+
dispatch(createSingleBookmark(jwt, userID, bookmarkToBeCreated));
|
|
100
|
+
};
|
|
101
|
+
var removeCurrentPageFromBookmarks = function removeCurrentPageFromBookmarks() {
|
|
102
|
+
redirectToLoginPageIfNotAuthorized();
|
|
103
|
+
var bookmarkID = _.get(bookmark, 'id');
|
|
104
|
+
if (bookmarkID) {
|
|
105
|
+
dispatch(deleteSingleBookmark(jwt, userID, bookmarkID));
|
|
106
|
+
} else {
|
|
107
|
+
console.error('Error on deleting bookmark with `BookmarkWidget`: No valid bookmark id.');
|
|
191
108
|
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
var
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (!slug) {
|
|
199
|
-
return null;
|
|
109
|
+
};
|
|
110
|
+
var checkIfThisArticleBookmarked = function checkIfThisArticleBookmarked() {
|
|
111
|
+
if (bookmark) {
|
|
112
|
+
var hostFromWindow = getHostFromWindowLocation();
|
|
113
|
+
if (_.get(bookmark, 'host') !== hostFromWindow) {
|
|
114
|
+
console.warn('Warning on checking bookmark status in `BookmarkWidget`:', 'The `host` in the bookmark data is different from the `host` in current `window`.', 'host in bookmark:', bookmark.host, 'host in `window.location`:', hostFromWindow);
|
|
200
115
|
}
|
|
201
|
-
|
|
202
|
-
var isBookmarked = this.checkIfThisArticleBookmarked();
|
|
203
|
-
var renderIcon = this.props.renderIcon;
|
|
204
|
-
return typeof renderIcon === 'function' ? renderIcon(isBookmarked, this.addCurrentPageToBookmarks, this.removeCurrentPageFromBookmarks) : null;
|
|
205
116
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
bookmark: null,
|
|
214
|
-
isAuthed: false,
|
|
215
|
-
jwt: '',
|
|
216
|
-
userID: NaN,
|
|
217
|
-
toAutoCheck: true
|
|
117
|
+
return Boolean(bookmark);
|
|
118
|
+
};
|
|
119
|
+
if (!articleMeta.slug) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
var isBookmarked = checkIfThisArticleBookmarked();
|
|
123
|
+
return typeof renderIcon === 'function' ? renderIcon(isBookmarked, addCurrentPageToBookmarks, removeCurrentPageFromBookmarks) : null;
|
|
218
124
|
};
|
|
219
125
|
BookmarkWidget.propTypes = {
|
|
220
|
-
articleMeta:
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
createSingleBookmark: _propTypes2["default"].func.isRequired,
|
|
224
|
-
deleteSingleBookmark: _propTypes2["default"].func.isRequired,
|
|
225
|
-
getSingleBookmark: _propTypes2["default"].func.isRequired,
|
|
226
|
-
isAuthed: _propTypes2["default"].bool,
|
|
227
|
-
jwt: _propTypes2["default"].string,
|
|
228
|
-
userID: _propTypes2["default"].number,
|
|
229
|
-
renderIcon: _propTypes2["default"].func.isRequired,
|
|
230
|
-
toAutoCheck: _propTypes2["default"].bool
|
|
126
|
+
articleMeta: _propTypes2["default"].articleMetaForBookmark.isRequired,
|
|
127
|
+
renderIcon: _propTypes["default"].func.isRequired,
|
|
128
|
+
toAutoCheck: _propTypes["default"].bool
|
|
231
129
|
};
|
|
232
|
-
|
|
233
|
-
function mapStateToProps(state, ownProps) {
|
|
234
|
-
var currentSlug = _.get(ownProps, 'articleMeta.slug');
|
|
235
|
-
|
|
236
|
-
var jwt = _.get(state, [reduxStatePropKeys.auth, 'accessToken']);
|
|
237
|
-
|
|
238
|
-
var userID = _.get(state, [reduxStatePropKeys.auth, 'userInfo', 'user_id']);
|
|
239
|
-
|
|
240
|
-
var isAuthed = _.get(state, [reduxStatePropKeys.auth, 'isAuthed']);
|
|
241
|
-
|
|
242
|
-
var bookmarkInStore = _.get(state, [reduxStatePropKeys.bookmarkWidget, 'bookmark']);
|
|
243
|
-
|
|
244
|
-
var bookmarkForThisWidget = currentSlug && currentSlug === _.get(bookmarkInStore, 'slug') ? bookmarkInStore : null;
|
|
245
|
-
return {
|
|
246
|
-
bookmark: bookmarkForThisWidget,
|
|
247
|
-
isAuthed: isAuthed,
|
|
248
|
-
jwt: jwt,
|
|
249
|
-
userID: userID
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
var _default = (0, _reactRedux.connect)(mapStateToProps, {
|
|
254
|
-
getSingleBookmark: getSingleBookmark,
|
|
255
|
-
createSingleBookmark: createSingleBookmark,
|
|
256
|
-
deleteSingleBookmark: deleteSingleBookmark
|
|
257
|
-
})(BookmarkWidget);
|
|
258
|
-
|
|
259
|
-
exports["default"] = _default;
|
|
130
|
+
var _default = exports["default"] = BookmarkWidget;
|
|
@@ -4,35 +4,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
13
|
-
|
|
14
10
|
var _theme = require("../utils/theme");
|
|
15
|
-
|
|
16
11
|
var _enums = require("../enums");
|
|
17
|
-
|
|
18
12
|
var _mediaQuery = _interopRequireDefault(require("@twreporter/core/lib/utils/media-query"));
|
|
19
|
-
|
|
20
13
|
var _theme2 = require("@twreporter/core/lib/constants/theme");
|
|
21
|
-
|
|
22
14
|
var _excluded = ["iconComponent", "theme", "type", "disabled", "active"];
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
var _templateObject; // utils
|
|
16
|
+
// enums
|
|
17
|
+
// @twreporter
|
|
26
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
27
|
-
|
|
28
19
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
29
|
-
|
|
30
20
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
31
|
-
|
|
32
21
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
33
|
-
|
|
34
22
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
35
|
-
|
|
36
23
|
var ButtonContainer = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
|
37
24
|
displayName: "iconButton__ButtonContainer",
|
|
38
25
|
componentId: "sc-1v7s35n-0"
|
|
@@ -47,32 +34,27 @@ var ButtonContainer = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
|
|
47
34
|
}, function (props) {
|
|
48
35
|
return props.$hoverColor;
|
|
49
36
|
}));
|
|
50
|
-
|
|
51
37
|
var IconButton = function IconButton(_ref) {
|
|
52
38
|
var iconComponent = _ref.iconComponent,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
39
|
+
_ref$theme = _ref.theme,
|
|
40
|
+
theme = _ref$theme === void 0 ? _theme2.THEME.normal : _ref$theme,
|
|
41
|
+
_ref$type = _ref.type,
|
|
42
|
+
type = _ref$type === void 0 ? _enums.Type.PRIMARY : _ref$type,
|
|
43
|
+
_ref$disabled = _ref.disabled,
|
|
44
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
45
|
+
_ref$active = _ref.active,
|
|
46
|
+
active = _ref$active === void 0 ? false : _ref$active,
|
|
47
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
63
48
|
var themeFunc = type === _enums.Type.PRIMARY ? _theme.getPrimaryIconButtonTheme : _theme.getSecondaryIconButtonTheme;
|
|
64
|
-
|
|
65
49
|
var _themeFunc = themeFunc(theme, active, disabled),
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
50
|
+
color = _themeFunc.color,
|
|
51
|
+
hoverColor = _themeFunc.hoverColor;
|
|
69
52
|
return /*#__PURE__*/_react["default"].createElement(ButtonContainer, _extends({
|
|
70
53
|
$color: color,
|
|
71
54
|
$hoverColor: hoverColor,
|
|
72
55
|
$disabled: disabled
|
|
73
56
|
}, props), iconComponent);
|
|
74
57
|
};
|
|
75
|
-
|
|
76
58
|
IconButton.propTypes = {
|
|
77
59
|
iconComponent: _propTypes["default"].element.isRequired,
|
|
78
60
|
theme: _propTypes["default"].oneOf(Object.values(_theme2.THEME)),
|
|
@@ -82,5 +64,4 @@ IconButton.propTypes = {
|
|
|
82
64
|
};
|
|
83
65
|
IconButton.THEME = _theme2.THEME;
|
|
84
66
|
IconButton.Type = _enums.Type;
|
|
85
|
-
var _default = IconButton;
|
|
86
|
-
exports["default"] = _default;
|
|
67
|
+
var _default = exports["default"] = IconButton;
|
|
@@ -4,27 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
13
|
-
|
|
14
10
|
var _theme = require("../utils/theme");
|
|
15
|
-
|
|
16
11
|
var _paragraph = require("../../text/paragraph");
|
|
17
|
-
|
|
18
12
|
var _mediaQuery = _interopRequireDefault(require("@twreporter/core/lib/utils/media-query"));
|
|
19
|
-
|
|
20
13
|
var _theme2 = require("@twreporter/core/lib/constants/theme");
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
var _templateObject; // utils
|
|
15
|
+
// components
|
|
16
|
+
// @twreporter
|
|
24
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
25
|
-
|
|
26
18
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
27
|
-
|
|
28
19
|
var ButtonContainer = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
|
29
20
|
displayName: "iconWithTextButton__ButtonContainer",
|
|
30
21
|
componentId: "sc-1f9d1q4-0"
|
|
@@ -39,7 +30,6 @@ var ButtonContainer = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
|
|
39
30
|
}, function (props) {
|
|
40
31
|
return props.$hoverColor;
|
|
41
32
|
}));
|
|
42
|
-
|
|
43
33
|
var StyledP4 = /*#__PURE__*/(0, _styledComponents["default"])(_paragraph.P4).withConfig({
|
|
44
34
|
displayName: "iconWithTextButton__StyledP4",
|
|
45
35
|
componentId: "sc-1f9d1q4-1"
|
|
@@ -48,24 +38,21 @@ var StyledP4 = /*#__PURE__*/(0, _styledComponents["default"])(_paragraph.P4).wit
|
|
|
48
38
|
}, function (props) {
|
|
49
39
|
return props.$hideText ? '0' : '1';
|
|
50
40
|
});
|
|
51
|
-
|
|
52
41
|
var IconWithTextButton = function IconWithTextButton(_ref) {
|
|
53
42
|
var _ref$text = _ref.text,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
43
|
+
text = _ref$text === void 0 ? '' : _ref$text,
|
|
44
|
+
iconComponent = _ref.iconComponent,
|
|
45
|
+
_ref$theme = _ref.theme,
|
|
46
|
+
theme = _ref$theme === void 0 ? _theme2.THEME.normal : _ref$theme,
|
|
47
|
+
_ref$disabled = _ref.disabled,
|
|
48
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
49
|
+
_ref$active = _ref.active,
|
|
50
|
+
active = _ref$active === void 0 ? false : _ref$active,
|
|
51
|
+
_ref$hideText = _ref.hideText,
|
|
52
|
+
hideText = _ref$hideText === void 0 ? false : _ref$hideText;
|
|
65
53
|
var _getIconWithTextButto = (0, _theme.getIconWithTextButtonTheme)(theme, active, disabled),
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
54
|
+
color = _getIconWithTextButto.color,
|
|
55
|
+
hoverColor = _getIconWithTextButto.hoverColor;
|
|
69
56
|
return /*#__PURE__*/_react["default"].createElement(ButtonContainer, {
|
|
70
57
|
$color: color,
|
|
71
58
|
$hoverColor: hoverColor,
|
|
@@ -76,7 +63,6 @@ var IconWithTextButton = function IconWithTextButton(_ref) {
|
|
|
76
63
|
$hideText: hideText
|
|
77
64
|
}));
|
|
78
65
|
};
|
|
79
|
-
|
|
80
66
|
IconWithTextButton.propTypes = {
|
|
81
67
|
text: _propTypes["default"].string,
|
|
82
68
|
iconComponent: _propTypes["default"].element.isRequired,
|
|
@@ -86,5 +72,4 @@ IconWithTextButton.propTypes = {
|
|
|
86
72
|
hideText: _propTypes["default"].bool
|
|
87
73
|
};
|
|
88
74
|
IconWithTextButton.THEME = _theme2.THEME;
|
|
89
|
-
var _default = IconWithTextButton;
|
|
90
|
-
exports["default"] = _default;
|
|
75
|
+
var _default = exports["default"] = IconWithTextButton;
|