@twreporter/redux 8.0.2 → 8.0.3

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/lib/actions/analytics.js +9 -22
  3. package/lib/actions/auth.js +9 -28
  4. package/lib/actions/author-articles.js +14 -43
  5. package/lib/actions/author-details.js +3 -23
  6. package/lib/actions/authors.js +13 -53
  7. package/lib/actions/bookmarks.js +26 -54
  8. package/lib/actions/donation-history.js +5 -23
  9. package/lib/actions/error-action-creators.js +7 -22
  10. package/lib/actions/footprints.js +5 -22
  11. package/lib/actions/index-page.js +9 -26
  12. package/lib/actions/index.js +2 -18
  13. package/lib/actions/latest.js +9 -26
  14. package/lib/actions/post-reviews.js +4 -16
  15. package/lib/actions/posts.js +28 -82
  16. package/lib/actions/topics.js +31 -64
  17. package/lib/actions/user.js +5 -26
  18. package/lib/component/provider.js +7 -31
  19. package/lib/constants/action-types.js +2 -4
  20. package/lib/constants/api-config.js +2 -3
  21. package/lib/constants/api-endpoints.js +2 -3
  22. package/lib/constants/author-page.js +3 -7
  23. package/lib/constants/authors-list.js +3 -7
  24. package/lib/constants/http-protocol.js +2 -3
  25. package/lib/constants/latest.js +1 -2
  26. package/lib/constants/mobile-mockup-specification.js +10 -9
  27. package/lib/constants/post-styles.js +2 -3
  28. package/lib/constants/redux-state-field-names.js +13 -11
  29. package/lib/context/redux-store.js +1 -6
  30. package/lib/index.js +2 -24
  31. package/lib/reducers/analytics.js +6 -20
  32. package/lib/reducers/auth.js +2 -13
  33. package/lib/reducers/author-articles.js +10 -26
  34. package/lib/reducers/authors.js +5 -28
  35. package/lib/reducers/bookmark-widget.js +0 -11
  36. package/lib/reducers/bookmarks.js +9 -40
  37. package/lib/reducers/donation-history.js +11 -39
  38. package/lib/reducers/entities-for-authors.js +2 -10
  39. package/lib/reducers/entities.js +24 -94
  40. package/lib/reducers/feature-topic.js +3 -16
  41. package/lib/reducers/footprints.js +8 -20
  42. package/lib/reducers/index-page.js +2 -23
  43. package/lib/reducers/index.js +5 -29
  44. package/lib/reducers/latest.js +2 -13
  45. package/lib/reducers/origins.js +0 -7
  46. package/lib/reducers/post-reviews.js +6 -16
  47. package/lib/reducers/posts.js +6 -36
  48. package/lib/reducers/related-posts-of.js +12 -55
  49. package/lib/reducers/settings.js +0 -9
  50. package/lib/reducers/topics.js +11 -35
  51. package/lib/reducers/user.js +6 -33
  52. package/lib/schemas/article-schema.js +3 -7
  53. package/lib/store/bind-actions-to-store.js +4 -21
  54. package/lib/store/create-store.js +22 -22
  55. package/lib/typedef.js +2 -25
  56. package/lib/utils/__tests__/denormalize-asset.test.js +1 -1
  57. package/lib/utils/denormalize-asset.js +3 -23
  58. package/lib/utils/detect-env.js +2 -6
  59. package/lib/utils/error.js +9 -55
  60. package/lib/utils/image-processor.js +3 -9
  61. package/lib/utils/jwt.js +3 -10
  62. package/lib/utils/pagination.js +5 -9
  63. package/lib/utils/url.js +0 -6
  64. package/package.json +5 -4
@@ -4,32 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.fetchIndexPageContent = fetchIndexPageContent;
7
-
8
7
  var _url = require("../utils/url");
9
-
10
8
  var _apiConfig = _interopRequireDefault(require("../constants/api-config"));
11
-
12
9
  var _apiEndpoints = _interopRequireDefault(require("../constants/api-endpoints"));
13
-
14
10
  var _axios = _interopRequireDefault(require("axios"));
15
-
16
11
  var _errorActionCreators = _interopRequireDefault(require("./error-action-creators"));
17
-
18
12
  var _reduxStateFieldNames = _interopRequireDefault(require("../constants/redux-state-field-names"));
19
-
20
13
  var _actionTypes = _interopRequireDefault(require("../constants/action-types"));
21
-
22
14
  var _get = _interopRequireDefault(require("lodash/get"));
23
-
24
15
  var _values = _interopRequireDefault(require("lodash/values"));
25
-
26
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
27
-
28
17
  // lodash
18
+
29
19
  var _ = {
30
20
  get: _get["default"],
31
21
  values: _values["default"]
32
22
  };
23
+
33
24
  /**
34
25
  * @param {Function} dispatch - dispatch of redux
35
26
  * @param {string} origin - URL origin
@@ -37,36 +28,35 @@ var _ = {
37
28
  * @param {number} timeout - request timeout to api
38
29
  * @return {Promise} resolve with success action or reject with fail action
39
30
  **/
40
-
41
31
  function _fetch(dispatch, origin, path, timeout) {
42
- var url = (0, _url.formURL)(origin, path); // Start to get content
43
-
32
+ var url = (0, _url.formURL)(origin, path);
33
+ // Start to get content
44
34
  dispatch({
45
35
  type: _actionTypes["default"].indexPage.read.request,
46
36
  url: url
47
37
  });
48
38
  return _axios["default"].get(url, {
49
39
  timeout: timeout
50
- }) // Get content successfully
40
+ })
41
+ // Get content successfully
51
42
  .then(function (response) {
52
43
  var items = _.get(response, 'data.data', {});
53
-
54
44
  var successAction = {
55
45
  type: _actionTypes["default"].indexPage.read.success,
56
46
  payload: {
57
47
  items: items
58
48
  }
59
- }; // dispatch content for each sections
60
-
49
+ };
50
+ // dispatch content for each sections
61
51
  dispatch(successAction);
62
52
  return successAction;
63
53
  })["catch"](function (error) {
64
54
  var failAction = _errorActionCreators["default"].axios(error, _actionTypes["default"].indexPage.read.failure);
65
-
66
55
  dispatch(failAction);
67
56
  return Promise.reject(failAction);
68
57
  });
69
58
  }
59
+
70
60
  /**
71
61
  * fetchIndexPageContent
72
62
  * This function will fetch the all sections except categories_section
@@ -77,18 +67,13 @@ function _fetch(dispatch, origin, path, timeout) {
77
67
  * @param {number} [timeout=apiConfig.timeout] - request api timeout
78
68
  * @return {import('../typedef').Thunk} async action creator
79
69
  */
80
-
81
-
82
70
  function fetchIndexPageContent() {
83
71
  var timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _apiConfig["default"].timeout;
84
72
  return function (dispatch, getState) {
85
73
  /** @type {import('../typedef').ReduxState} */
86
74
  var state = getState();
87
-
88
75
  var indexPage = _.get(state, _reduxStateFieldNames["default"].indexPage, {});
89
-
90
76
  var isContentReady = _.get(indexPage, 'isReady', false);
91
-
92
77
  if (isContentReady) {
93
78
  var action = {
94
79
  type: _actionTypes["default"].indexPage.read.alreadyExists
@@ -96,9 +81,7 @@ function fetchIndexPageContent() {
96
81
  dispatch(action);
97
82
  return Promise.resolve(action);
98
83
  }
99
-
100
84
  var apiOrigin = _.get(state, [_reduxStateFieldNames["default"].origins, 'api']);
101
-
102
85
  return _fetch(dispatch, apiOrigin, "/v2/".concat(_apiEndpoints["default"].indexPage), timeout);
103
86
  };
104
87
  }
@@ -4,36 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
8
7
  var _auth = require("./auth");
9
-
10
8
  var _authorArticles = require("./author-articles");
11
-
12
9
  var _authorDetails = require("./author-details");
13
-
14
10
  var _authors = require("./authors");
15
-
16
11
  var _indexPage = require("./index-page");
17
-
18
12
  var _posts = require("./posts");
19
-
20
13
  var _topics = require("./topics");
21
-
22
14
  var _bookmarks = require("./bookmarks");
23
-
24
15
  var _latest = require("./latest");
25
-
26
16
  var _user = require("./user");
27
-
28
17
  var _analytics = require("./analytics");
29
-
30
18
  var _footprints = require("./footprints");
31
-
32
19
  var _donationHistory = require("./donation-history");
33
-
34
20
  var _postReviews = require("./post-reviews");
35
-
36
- var _default = {
21
+ var _default = exports["default"] = {
37
22
  createSingleBookmark: _bookmarks.createSingleBookmark,
38
23
  deleteSingleBookmark: _bookmarks.deleteSingleBookmark,
39
24
  fetchAFullPost: _posts.fetchAFullPost,
@@ -62,5 +47,4 @@ var _default = {
62
47
  getUserDonationHistory: _donationHistory.getUserDonationHistory,
63
48
  getUserPeriodicDonationHistory: _donationHistory.getUserPeriodicDonationHistory,
64
49
  getPostReviews: _postReviews.getPostReviews
65
- };
66
- exports["default"] = _default;
50
+ };
@@ -4,32 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.fetchLatestTags = fetchLatestTags;
7
-
8
7
  var _url = require("../utils/url");
9
-
10
8
  var _apiConfig = _interopRequireDefault(require("../constants/api-config"));
11
-
12
9
  var _apiEndpoints = _interopRequireDefault(require("../constants/api-endpoints"));
13
-
14
10
  var _axios = _interopRequireDefault(require("axios"));
15
-
16
11
  var _errorActionCreators = _interopRequireDefault(require("./error-action-creators"));
17
-
18
12
  var _reduxStateFieldNames = _interopRequireDefault(require("../constants/redux-state-field-names"));
19
-
20
13
  var _actionTypes = _interopRequireDefault(require("../constants/action-types"));
21
-
22
14
  var _get = _interopRequireDefault(require("lodash/get"));
23
-
24
15
  var _values = _interopRequireDefault(require("lodash/values"));
25
-
26
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
27
-
28
17
  // lodash
18
+
29
19
  var _ = {
30
20
  get: _get["default"],
31
21
  values: _values["default"]
32
22
  };
23
+
33
24
  /**
34
25
  * @param {Function} dispatch - dispatch of redux
35
26
  * @param {string} origin - URL origin
@@ -37,54 +28,48 @@ var _ = {
37
28
  * @param {number} timeout - request timeout to api
38
29
  * @return {Promise} resolve with success action or reject with fail action
39
30
  **/
40
-
41
31
  function _fetch(dispatch, origin, path, params, timeout) {
42
- var url = (0, _url.formURL)(origin, path, params); // Start to get content
43
-
32
+ var url = (0, _url.formURL)(origin, path, params);
33
+ // Start to get content
44
34
  dispatch({
45
35
  type: _actionTypes["default"].latest.read.request,
46
36
  url: url
47
37
  });
48
38
  return _axios["default"].get(url, {
49
39
  timeout: timeout
50
- }) // Get content successfully
40
+ })
41
+ // Get content successfully
51
42
  .then(function (response) {
52
43
  var tags = _.get(response, 'data.data.records', []);
53
-
54
44
  var successAction = {
55
45
  type: _actionTypes["default"].latest.read.success,
56
46
  payload: {
57
47
  tags: tags
58
48
  }
59
- }; // dispatch content for each sections
60
-
49
+ };
50
+ // dispatch content for each sections
61
51
  dispatch(successAction);
62
52
  return successAction;
63
53
  })["catch"](function (error) {
64
54
  var failAction = _errorActionCreators["default"].axios(error, _actionTypes["default"].latest.read.failure);
65
-
66
55
  dispatch(failAction);
67
56
  return Promise.reject(failAction);
68
57
  });
69
58
  }
59
+
70
60
  /**
71
61
  * fetchLatestTags
72
62
  *
73
63
  * @param {number} [timeout=apiConfig.timeout] - request api timeout
74
64
  * @return {import('../typedef').Thunk} async action creator
75
65
  */
76
-
77
-
78
66
  function fetchLatestTags() {
79
67
  var timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _apiConfig["default"].timeout;
80
68
  return function (dispatch, getState) {
81
69
  /** @type {import('../typedef').ReduxState} */
82
70
  var state = getState();
83
-
84
71
  var latestPage = _.get(state, _reduxStateFieldNames["default"].latest, {});
85
-
86
72
  var isContentReady = _.get(latestPage, 'isReady', false);
87
-
88
73
  if (isContentReady) {
89
74
  var action = {
90
75
  type: _actionTypes["default"].latest.read.alreadyExists
@@ -92,9 +77,7 @@ function fetchLatestTags() {
92
77
  dispatch(action);
93
78
  return Promise.resolve(action);
94
79
  }
95
-
96
80
  var apiOrigin = _.get(state, [_reduxStateFieldNames["default"].origins, 'api']);
97
-
98
81
  return _fetch(dispatch, apiOrigin, "/v2/".concat(_apiEndpoints["default"].tags), {
99
82
  latest_order: 1
100
83
  }, timeout);
@@ -4,31 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getPostReviews = getPostReviews;
7
-
8
7
  var _axios = _interopRequireDefault(require("axios"));
9
-
10
8
  var _apiConfig = _interopRequireDefault(require("../constants/api-config"));
11
-
12
9
  var _apiEndpoints = _interopRequireDefault(require("../constants/api-endpoints"));
13
-
14
10
  var _reduxStateFieldNames = _interopRequireDefault(require("../constants/redux-state-field-names"));
15
-
16
11
  var _actionTypes = _interopRequireDefault(require("../constants/action-types"));
17
-
18
12
  var _url = require("../utils/url");
19
-
20
13
  var _errorActionCreators = _interopRequireDefault(require("./error-action-creators"));
21
-
22
14
  var _get = _interopRequireDefault(require("lodash/get"));
23
-
24
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
25
-
26
16
  // constants
17
+
27
18
  // lodash
19
+
28
20
  var _ = {
29
21
  get: _get["default"]
30
22
  };
31
23
  var apiTimeout = _apiConfig["default"].timeout;
24
+
32
25
  /**
33
26
  * @typedef {Object} RequestAction
34
27
  * @property {string} type - The type of action
@@ -51,7 +44,6 @@ var apiTimeout = _apiConfig["default"].timeout;
51
44
  * @param {string} actionType
52
45
  * @returns {SuccessAction}
53
46
  */
54
-
55
47
  function buildSuccessActionFromRes(axiosResponse, actionType) {
56
48
  return {
57
49
  type: actionType,
@@ -61,6 +53,7 @@ function buildSuccessActionFromRes(axiosResponse, actionType) {
61
53
  }
62
54
  };
63
55
  }
56
+
64
57
  /**
65
58
  * @typedef {Object} FailAction
66
59
  * @property {string} type - Action error type
@@ -75,8 +68,6 @@ function buildSuccessActionFromRes(axiosResponse, actionType) {
75
68
  * @param {string} jwt - access_token granted for the user
76
69
  * @returns {Function} - function will be executed in Redux Thunk middleware
77
70
  */
78
-
79
-
80
71
  function getPostReviews(jwt) {
81
72
  /**
82
73
  * @param {Function} dispatch - Redux store dispatch function
@@ -85,9 +76,7 @@ function getPostReviews(jwt) {
85
76
  */
86
77
  return function (dispatch, getState) {
87
78
  var state = getState();
88
-
89
79
  var apiOrigin = _.get(state, [_reduxStateFieldNames["default"].origins, 'api']);
90
-
91
80
  var url = (0, _url.formURL)(apiOrigin, "/v2/".concat(_apiEndpoints["default"].postReviews));
92
81
  dispatch({
93
82
  type: _actionTypes["default"].postReviews.read.request,
@@ -106,7 +95,6 @@ function getPostReviews(jwt) {
106
95
  return successAction;
107
96
  })["catch"](function (error) {
108
97
  var failAction = _errorActionCreators["default"].axios(error, _actionTypes["default"].postReviews.read.failure);
109
-
110
98
  dispatch(failAction);
111
99
  return Promise.reject(failAction);
112
100
  });