@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.
- package/CHANGELOG.md +16 -0
- package/lib/actions/analytics.js +9 -22
- package/lib/actions/auth.js +9 -28
- package/lib/actions/author-articles.js +14 -43
- package/lib/actions/author-details.js +3 -23
- package/lib/actions/authors.js +13 -53
- package/lib/actions/bookmarks.js +26 -54
- package/lib/actions/donation-history.js +5 -23
- package/lib/actions/error-action-creators.js +7 -22
- package/lib/actions/footprints.js +5 -22
- package/lib/actions/index-page.js +9 -26
- package/lib/actions/index.js +2 -18
- package/lib/actions/latest.js +9 -26
- package/lib/actions/post-reviews.js +4 -16
- package/lib/actions/posts.js +28 -82
- package/lib/actions/topics.js +31 -64
- package/lib/actions/user.js +5 -26
- package/lib/component/provider.js +7 -31
- package/lib/constants/action-types.js +2 -4
- package/lib/constants/api-config.js +2 -3
- package/lib/constants/api-endpoints.js +2 -3
- package/lib/constants/author-page.js +3 -7
- package/lib/constants/authors-list.js +3 -7
- package/lib/constants/http-protocol.js +2 -3
- package/lib/constants/latest.js +1 -2
- package/lib/constants/mobile-mockup-specification.js +10 -9
- package/lib/constants/post-styles.js +2 -3
- package/lib/constants/redux-state-field-names.js +13 -11
- package/lib/context/redux-store.js +1 -6
- package/lib/index.js +2 -24
- package/lib/reducers/analytics.js +6 -20
- package/lib/reducers/auth.js +2 -13
- package/lib/reducers/author-articles.js +10 -26
- package/lib/reducers/authors.js +5 -28
- package/lib/reducers/bookmark-widget.js +0 -11
- package/lib/reducers/bookmarks.js +9 -40
- package/lib/reducers/donation-history.js +11 -39
- package/lib/reducers/entities-for-authors.js +2 -10
- package/lib/reducers/entities.js +24 -94
- package/lib/reducers/feature-topic.js +3 -16
- package/lib/reducers/footprints.js +8 -20
- package/lib/reducers/index-page.js +2 -23
- package/lib/reducers/index.js +5 -29
- package/lib/reducers/latest.js +2 -13
- package/lib/reducers/origins.js +0 -7
- package/lib/reducers/post-reviews.js +6 -16
- package/lib/reducers/posts.js +6 -36
- package/lib/reducers/related-posts-of.js +12 -55
- package/lib/reducers/settings.js +0 -9
- package/lib/reducers/topics.js +11 -35
- package/lib/reducers/user.js +6 -33
- package/lib/schemas/article-schema.js +3 -7
- package/lib/store/bind-actions-to-store.js +4 -21
- package/lib/store/create-store.js +22 -22
- package/lib/typedef.js +2 -25
- package/lib/utils/__tests__/denormalize-asset.test.js +1 -1
- package/lib/utils/denormalize-asset.js +3 -23
- package/lib/utils/detect-env.js +2 -6
- package/lib/utils/error.js +9 -55
- package/lib/utils/image-processor.js +3 -9
- package/lib/utils/jwt.js +3 -10
- package/lib/utils/pagination.js +5 -9
- package/lib/utils/url.js +0 -6
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [8.0.3](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/redux@8.0.3-rc.0...@twreporter/redux@8.0.3) (2024-06-24)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @twreporter/redux
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [8.0.3-rc.0](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/redux@8.0.2...@twreporter/redux@8.0.3-rc.0) (2024-06-18)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @twreporter/redux
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [8.0.2](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/redux@8.0.2-rc.0...@twreporter/redux@8.0.2) (2024-06-04)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @twreporter/redux
|
package/lib/actions/analytics.js
CHANGED
|
@@ -4,33 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.setUserAnalyticsData = setUserAnalyticsData;
|
|
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 _reduxStateFieldNames = _interopRequireDefault(require("../constants/redux-state-field-names"));
|
|
15
|
-
|
|
16
11
|
var _actionTypes = _interopRequireDefault(require("../constants/action-types"));
|
|
17
|
-
|
|
18
12
|
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
19
|
-
|
|
20
13
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
21
|
-
|
|
22
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
23
|
-
|
|
24
|
-
function ownKeys(
|
|
25
|
-
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
function
|
|
29
|
-
|
|
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); } // lodash
|
|
30
21
|
var _ = {
|
|
31
22
|
get: _get["default"]
|
|
32
23
|
};
|
|
33
24
|
var apiTimeout = _apiConfig["default"].timeout;
|
|
25
|
+
|
|
34
26
|
/**
|
|
35
27
|
* @typedef {Object} RequestAction
|
|
36
28
|
* @property {string} type - The type of action
|
|
@@ -53,7 +45,6 @@ var apiTimeout = _apiConfig["default"].timeout;
|
|
|
53
45
|
* @param {string} actionType
|
|
54
46
|
* @returns {SuccessAction}
|
|
55
47
|
*/
|
|
56
|
-
|
|
57
48
|
function buildSuccessActionFromRes(fetchResponse, actionType) {
|
|
58
49
|
return {
|
|
59
50
|
type: actionType,
|
|
@@ -63,6 +54,7 @@ function buildSuccessActionFromRes(fetchResponse, actionType) {
|
|
|
63
54
|
}
|
|
64
55
|
};
|
|
65
56
|
}
|
|
57
|
+
|
|
66
58
|
/**
|
|
67
59
|
* @typedef {Object} FailAction
|
|
68
60
|
* @property {string} type - Action error type
|
|
@@ -82,12 +74,9 @@ function buildSuccessActionFromRes(fetchResponse, actionType) {
|
|
|
82
74
|
* @param {number} readPostStatus.readPostSec - read post second
|
|
83
75
|
* @return {Function} - function will be executed in Redux Thunk middleware
|
|
84
76
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
77
|
function setUserAnalyticsData(jwt, userID, postID, _ref) {
|
|
88
78
|
var readPostCount = _ref.readPostCount,
|
|
89
|
-
|
|
90
|
-
|
|
79
|
+
readPostSec = _ref.readPostSec;
|
|
91
80
|
/**
|
|
92
81
|
* @param {Function} dispatch - Redux store dispatch function
|
|
93
82
|
* @param {Function} getState - Redux store getState function
|
|
@@ -95,9 +84,7 @@ function setUserAnalyticsData(jwt, userID, postID, _ref) {
|
|
|
95
84
|
*/
|
|
96
85
|
return function (dispatch, getState) {
|
|
97
86
|
var state = getState();
|
|
98
|
-
|
|
99
87
|
var apiOrigin = _.get(state, [_reduxStateFieldNames["default"].origins, 'api']);
|
|
100
|
-
|
|
101
88
|
var url = (0, _url.formURL)(apiOrigin, "/v2/".concat(_apiEndpoints["default"].users, "/").concat(userID, "/analytics"));
|
|
102
89
|
dispatch({
|
|
103
90
|
type: _actionTypes["default"].analytics.update.request,
|
package/lib/actions/auth.js
CHANGED
|
@@ -5,28 +5,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
exports.getAccessToken = getAccessToken;
|
|
8
|
-
|
|
9
8
|
var _url = require("../utils/url");
|
|
10
|
-
|
|
11
9
|
var _actionTypes = _interopRequireDefault(require("../constants/action-types"));
|
|
12
|
-
|
|
13
10
|
var _apiConfig = _interopRequireDefault(require("../constants/api-config"));
|
|
14
|
-
|
|
15
11
|
var _axios = _interopRequireDefault(require("axios"));
|
|
16
|
-
|
|
17
12
|
var _errorActionCreators = _interopRequireDefault(require("./error-action-creators"));
|
|
18
|
-
|
|
19
13
|
var _reduxStateFieldNames = _interopRequireDefault(require("../constants/redux-state-field-names"));
|
|
20
|
-
|
|
21
14
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
22
|
-
|
|
23
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
24
|
-
|
|
25
16
|
// lodash
|
|
17
|
+
|
|
26
18
|
var _ = {
|
|
27
19
|
get: _get["default"]
|
|
28
20
|
};
|
|
29
21
|
var timeout = _apiConfig["default"].timeout;
|
|
22
|
+
|
|
30
23
|
/**
|
|
31
24
|
* Send POST method request with Cookie in the headers
|
|
32
25
|
* to fetch the access_token.
|
|
@@ -34,7 +27,6 @@ var timeout = _apiConfig["default"].timeout;
|
|
|
34
27
|
* @param {string} [cookieList] - cookieList contains `id_token` cookie
|
|
35
28
|
* @return {Function} returned function will get executed by the Redux Thunk middleware
|
|
36
29
|
*/
|
|
37
|
-
|
|
38
30
|
function getAccessToken(cookieList) {
|
|
39
31
|
/**
|
|
40
32
|
* @param {Function} dispatch - Redux store dispatch function
|
|
@@ -43,29 +35,24 @@ function getAccessToken(cookieList) {
|
|
|
43
35
|
*/
|
|
44
36
|
return function (dispatch, getState) {
|
|
45
37
|
var state = getState();
|
|
46
|
-
|
|
47
38
|
var apiOrigin = _.get(state, [_reduxStateFieldNames["default"].origins, 'api']);
|
|
48
|
-
|
|
49
39
|
var url = (0, _url.formURL)(apiOrigin, '/v2/auth/token');
|
|
50
40
|
var headers = {};
|
|
51
|
-
|
|
52
41
|
if (cookieList) {
|
|
53
42
|
headers.Cookie = cookieList;
|
|
54
43
|
}
|
|
55
|
-
|
|
56
44
|
var options = {
|
|
57
45
|
timeout: timeout,
|
|
58
46
|
headers: headers,
|
|
59
47
|
withCredentials: true
|
|
60
48
|
};
|
|
61
|
-
|
|
62
49
|
var interceptor = _axios["default"].interceptors.request.use(function (config) {
|
|
63
50
|
var method = config.method,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
51
|
+
url = config.url,
|
|
52
|
+
headers = config.headers,
|
|
53
|
+
data = config.data,
|
|
54
|
+
withCredentials = config.withCredentials,
|
|
55
|
+
timeout = config.timeout;
|
|
69
56
|
dispatch({
|
|
70
57
|
type: _actionTypes["default"].REQUEST_AUTH,
|
|
71
58
|
payload: {
|
|
@@ -79,12 +66,9 @@ function getAccessToken(cookieList) {
|
|
|
79
66
|
body: data
|
|
80
67
|
}
|
|
81
68
|
});
|
|
82
|
-
|
|
83
69
|
_axios["default"].interceptors.request.eject(interceptor);
|
|
84
|
-
|
|
85
70
|
return config;
|
|
86
71
|
});
|
|
87
|
-
|
|
88
72
|
return _axios["default"].post(url, null, options).then(function (axiosRes) {
|
|
89
73
|
var successAction = {
|
|
90
74
|
type: _actionTypes["default"].AUTH_SUCCESS,
|
|
@@ -98,14 +82,11 @@ function getAccessToken(cookieList) {
|
|
|
98
82
|
return successAction;
|
|
99
83
|
})["catch"](function (err) {
|
|
100
84
|
var failAction = _errorActionCreators["default"].axios(err, _actionTypes["default"].AUTH_FAILURE);
|
|
101
|
-
|
|
102
85
|
dispatch(failAction);
|
|
103
86
|
return Promise.reject(failAction);
|
|
104
87
|
});
|
|
105
88
|
};
|
|
106
89
|
}
|
|
107
|
-
|
|
108
|
-
var _default = {
|
|
90
|
+
var _default = exports["default"] = {
|
|
109
91
|
getAccessToken: getAccessToken
|
|
110
|
-
};
|
|
111
|
-
exports["default"] = _default;
|
|
92
|
+
};
|
|
@@ -6,37 +6,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.fetchAuthorCollection = fetchAuthorCollection;
|
|
7
7
|
exports.fetchAuthorCollectionIfNeeded = fetchAuthorCollectionIfNeeded;
|
|
8
8
|
exports.requestAuthorCollection = requestAuthorCollection;
|
|
9
|
-
|
|
10
9
|
var _articleSchema = require("../schemas/article-schema");
|
|
11
|
-
|
|
12
10
|
var _humps = require("humps");
|
|
13
|
-
|
|
14
11
|
var _authorPage = require("../constants/author-page");
|
|
15
|
-
|
|
16
12
|
var _url = require("../utils/url");
|
|
17
|
-
|
|
18
13
|
var _normalizr = require("normalizr");
|
|
19
|
-
|
|
20
14
|
var _actionTypes = _interopRequireDefault(require("../constants/action-types"));
|
|
21
|
-
|
|
22
15
|
var _axios = _interopRequireDefault(require("axios"));
|
|
23
|
-
|
|
24
16
|
var _errorActionCreators = _interopRequireDefault(require("./error-action-creators"));
|
|
25
|
-
|
|
26
17
|
var _reduxStateFieldNames = _interopRequireDefault(require("../constants/redux-state-field-names"));
|
|
27
|
-
|
|
28
18
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
29
|
-
|
|
30
19
|
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
31
|
-
|
|
32
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
33
|
-
|
|
34
21
|
// lodash
|
|
22
|
+
|
|
35
23
|
var _ = {
|
|
36
24
|
get: _get["default"],
|
|
37
25
|
omit: _omit["default"]
|
|
38
26
|
};
|
|
39
|
-
|
|
40
27
|
function requestAuthorCollection(authorId) {
|
|
41
28
|
return {
|
|
42
29
|
type: _actionTypes["default"].FETCH_AUTHOR_COLLECTION_REQUEST,
|
|
@@ -45,6 +32,7 @@ function requestAuthorCollection(authorId) {
|
|
|
45
32
|
}
|
|
46
33
|
};
|
|
47
34
|
}
|
|
35
|
+
|
|
48
36
|
/**
|
|
49
37
|
* NormalizedData
|
|
50
38
|
* @typedef {Object} NormalizedData
|
|
@@ -65,12 +53,10 @@ function requestAuthorCollection(authorId) {
|
|
|
65
53
|
* @property {number} receivedAt
|
|
66
54
|
*/
|
|
67
55
|
|
|
68
|
-
|
|
69
56
|
function fetchAuthorCollection(_ref) {
|
|
70
57
|
var targetPage = _ref.targetPage,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
58
|
+
authorId = _ref.authorId,
|
|
59
|
+
returnDelay = _ref.returnDelay;
|
|
74
60
|
/**
|
|
75
61
|
* @param {Function} dispatch - Redux store dispatch function
|
|
76
62
|
* @param {Function} getState - Redux store getState function
|
|
@@ -83,23 +69,16 @@ function fetchAuthorCollection(_ref) {
|
|
|
83
69
|
offset: targetPage * _authorPage.MAX_ARTICLES_PER_FETCH
|
|
84
70
|
};
|
|
85
71
|
var state = getState();
|
|
86
|
-
|
|
87
72
|
var apiOrigin = _.get(state, [_reduxStateFieldNames["default"].origins, 'api']);
|
|
88
|
-
|
|
89
73
|
var url = (0, _url.formURL)(apiOrigin, "/v2/authors/".concat(authorId, "/posts"), searchParas, false);
|
|
90
|
-
dispatch(requestAuthorCollection(authorId));
|
|
91
|
-
|
|
74
|
+
dispatch(requestAuthorCollection(authorId));
|
|
75
|
+
// Call our API server to fetch the data
|
|
92
76
|
return _axios["default"].get(url).then(function (_ref2) {
|
|
93
77
|
var data = _ref2.data;
|
|
94
|
-
|
|
95
78
|
var articles = _.get(data, 'data.records', {});
|
|
96
|
-
|
|
97
79
|
var offset = _.get(data, 'data.meta.offset', 0);
|
|
98
|
-
|
|
99
80
|
var limit = _.get(data, 'data.meta.limit', 10);
|
|
100
|
-
|
|
101
81
|
var total = _.get(data, 'data.meta.total', 0);
|
|
102
|
-
|
|
103
82
|
var receiveAuthorCollectionAction = {
|
|
104
83
|
type: _actionTypes["default"].FETCH_AUTHOR_COLLECTION_SUCCESS,
|
|
105
84
|
payload: {
|
|
@@ -110,8 +89,8 @@ function fetchAuthorCollection(_ref) {
|
|
|
110
89
|
totalResults: total,
|
|
111
90
|
receivedAt: Date.now()
|
|
112
91
|
}
|
|
113
|
-
};
|
|
114
|
-
|
|
92
|
+
};
|
|
93
|
+
// delay for displaying loading spinner
|
|
115
94
|
if (returnDelay > 0) {
|
|
116
95
|
return new Promise(function (resolve) {
|
|
117
96
|
setTimeout(function () {
|
|
@@ -120,12 +99,10 @@ function fetchAuthorCollection(_ref) {
|
|
|
120
99
|
}, returnDelay);
|
|
121
100
|
});
|
|
122
101
|
}
|
|
123
|
-
|
|
124
102
|
dispatch(receiveAuthorCollectionAction);
|
|
125
103
|
return receiveAuthorCollectionAction;
|
|
126
104
|
})["catch"](function (error) {
|
|
127
105
|
var failAction = _errorActionCreators["default"].axios(error, _actionTypes["default"].FETCH_AUTHOR_COLLECTION_FAILURE);
|
|
128
|
-
|
|
129
106
|
failAction.payload.authorId = authorId;
|
|
130
107
|
failAction.payload.failedAt = Date.now();
|
|
131
108
|
dispatch(failAction);
|
|
@@ -133,7 +110,6 @@ function fetchAuthorCollection(_ref) {
|
|
|
133
110
|
});
|
|
134
111
|
};
|
|
135
112
|
}
|
|
136
|
-
|
|
137
113
|
function fetchAuthorCollectionIfNeeded(authorId) {
|
|
138
114
|
/**
|
|
139
115
|
* @param {Function} dispatch - Redux store dispatch function
|
|
@@ -142,23 +118,19 @@ function fetchAuthorCollectionIfNeeded(authorId) {
|
|
|
142
118
|
*/
|
|
143
119
|
return function (dispatch, getState) {
|
|
144
120
|
var currentState = getState();
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
121
|
+
var articlesDataOfAnAuthor = _.get(currentState, ['articlesByAuthor', authorId], null);
|
|
122
|
+
// If state.articlesByAuthor[authorId] does not exist:
|
|
149
123
|
if (articlesDataOfAnAuthor === null) {
|
|
150
124
|
return dispatch(fetchAuthorCollection({
|
|
151
125
|
authorId: authorId,
|
|
152
126
|
targetPage: _authorPage.NUMBER_OF_FIRST_RESPONSE_PAGE,
|
|
153
127
|
returnDelay: 0
|
|
154
128
|
}));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
129
|
+
}
|
|
130
|
+
// If state.articlesByAuthor[authorId] exists:
|
|
158
131
|
var currentPage = articlesDataOfAnAuthor.currentPage,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
132
|
+
isFetching = articlesDataOfAnAuthor.isFetching,
|
|
133
|
+
hasMore = articlesDataOfAnAuthor.hasMore;
|
|
162
134
|
if (!isFetching && hasMore) {
|
|
163
135
|
return dispatch(fetchAuthorCollection({
|
|
164
136
|
authorId: authorId,
|
|
@@ -166,7 +138,6 @@ function fetchAuthorCollectionIfNeeded(authorId) {
|
|
|
166
138
|
returnDelay: _authorPage.RETURN_DELAY_TIME
|
|
167
139
|
}));
|
|
168
140
|
}
|
|
169
|
-
|
|
170
141
|
var action = {
|
|
171
142
|
type: _actionTypes["default"].dataAlreadyExists,
|
|
172
143
|
payload: {
|
|
@@ -6,35 +6,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.fetchAuthorDetails = fetchAuthorDetails;
|
|
7
7
|
exports.receiveFetchAuthorDetails = receiveFetchAuthorDetails;
|
|
8
8
|
exports.requestFetchAuthorDetails = requestFetchAuthorDetails;
|
|
9
|
-
|
|
10
9
|
var _articleSchema = require("../schemas/article-schema");
|
|
11
|
-
|
|
12
10
|
var _humps = require("humps");
|
|
13
|
-
|
|
14
11
|
var _url = require("../utils/url");
|
|
15
|
-
|
|
16
12
|
var _normalizr = require("normalizr");
|
|
17
|
-
|
|
18
13
|
var _actionTypes = _interopRequireDefault(require("../constants/action-types"));
|
|
19
|
-
|
|
20
14
|
var _axios = _interopRequireDefault(require("axios"));
|
|
21
|
-
|
|
22
15
|
var _errorActionCreators = _interopRequireDefault(require("./error-action-creators"));
|
|
23
|
-
|
|
24
16
|
var _reduxStateFieldNames = _interopRequireDefault(require("../constants/redux-state-field-names"));
|
|
25
|
-
|
|
26
17
|
var _assign = _interopRequireDefault(require("lodash/assign"));
|
|
27
|
-
|
|
28
18
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
29
|
-
|
|
30
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
31
|
-
|
|
32
20
|
// lodash
|
|
21
|
+
|
|
33
22
|
var _ = {
|
|
34
23
|
assign: _assign["default"],
|
|
35
24
|
get: _get["default"]
|
|
36
25
|
};
|
|
37
|
-
|
|
38
26
|
function requestFetchAuthorDetails(authorId) {
|
|
39
27
|
return {
|
|
40
28
|
type: _actionTypes["default"].authorDetails.read.request,
|
|
@@ -43,6 +31,7 @@ function requestFetchAuthorDetails(authorId) {
|
|
|
43
31
|
}
|
|
44
32
|
};
|
|
45
33
|
}
|
|
34
|
+
|
|
46
35
|
/**
|
|
47
36
|
* @typedef NormalizedDataOfAuthorDetails
|
|
48
37
|
* @property {string} result
|
|
@@ -61,8 +50,6 @@ function requestFetchAuthorDetails(authorId) {
|
|
|
61
50
|
* @param {NormalizedDataOfAuthorDetails} normalizedData
|
|
62
51
|
* @returns {SuccessActionOfFetchAuthorDetails}
|
|
63
52
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
53
|
function receiveFetchAuthorDetails(normalizedData) {
|
|
67
54
|
return {
|
|
68
55
|
type: _actionTypes["default"].authorDetails.read.success,
|
|
@@ -71,7 +58,6 @@ function receiveFetchAuthorDetails(normalizedData) {
|
|
|
71
58
|
}
|
|
72
59
|
};
|
|
73
60
|
}
|
|
74
|
-
|
|
75
61
|
function fetchAuthorDetails(authorId) {
|
|
76
62
|
/**
|
|
77
63
|
* @param {Function} dispatch - Redux store dispatch function
|
|
@@ -83,27 +69,21 @@ function fetchAuthorDetails(authorId) {
|
|
|
83
69
|
author_id: authorId
|
|
84
70
|
};
|
|
85
71
|
var state = getState();
|
|
86
|
-
|
|
87
72
|
var apiOrigin = _.get(state, [_reduxStateFieldNames["default"].origins, 'api']);
|
|
88
|
-
|
|
89
73
|
var url = (0, _url.formURL)(apiOrigin, "/v2/authors/".concat(authorId), searchParas);
|
|
90
74
|
dispatch(requestFetchAuthorDetails(authorId));
|
|
91
75
|
return _axios["default"].get(url).then(function (_ref) {
|
|
92
76
|
var data = _ref.data;
|
|
93
|
-
|
|
94
77
|
var author = _.assign({}, _.get(data, 'data'));
|
|
95
|
-
/** type {NormalizedDataOfAuthorDetails} */
|
|
96
|
-
|
|
97
78
|
|
|
79
|
+
/** type {NormalizedDataOfAuthorDetails} */
|
|
98
80
|
var normalizedData = (0, _normalizr.normalize)((0, _humps.camelizeKeys)(author), _articleSchema.author);
|
|
99
81
|
/** type {SuccessActionOfFetchAuthorDetails} */
|
|
100
|
-
|
|
101
82
|
var successAction = receiveFetchAuthorDetails(normalizedData);
|
|
102
83
|
dispatch(successAction);
|
|
103
84
|
return successAction;
|
|
104
85
|
}, function (error) {
|
|
105
86
|
var failAction = _errorActionCreators["default"].axios(error, _actionTypes["default"].authorDetails.read.failure);
|
|
106
|
-
|
|
107
87
|
dispatch(failAction);
|
|
108
88
|
return Promise.reject(failAction);
|
|
109
89
|
});
|
package/lib/actions/authors.js
CHANGED
|
@@ -6,43 +6,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.requestSearchAuthors = requestSearchAuthors;
|
|
7
7
|
exports.searchAuthors = searchAuthors;
|
|
8
8
|
exports.searchAuthorsIfNeeded = searchAuthorsIfNeeded;
|
|
9
|
-
|
|
10
9
|
var _articleSchema = require("../schemas/article-schema");
|
|
11
|
-
|
|
12
10
|
var _humps = require("humps");
|
|
13
|
-
|
|
14
11
|
var _authorsList = require("../constants/authors-list");
|
|
15
|
-
|
|
16
12
|
var _url = require("../utils/url");
|
|
17
|
-
|
|
18
13
|
var _normalizr = require("normalizr");
|
|
19
|
-
|
|
20
14
|
var _actionTypes = _interopRequireDefault(require("../constants/action-types"));
|
|
21
|
-
|
|
22
15
|
var _axios = _interopRequireDefault(require("axios"));
|
|
23
|
-
|
|
24
16
|
var _errorActionCreators = _interopRequireDefault(require("./error-action-creators"));
|
|
25
|
-
|
|
26
17
|
var _reduxStateFieldNames = _interopRequireDefault(require("../constants/redux-state-field-names"));
|
|
27
|
-
|
|
28
18
|
var _assign = _interopRequireDefault(require("lodash/assign"));
|
|
29
|
-
|
|
30
19
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
31
|
-
|
|
32
20
|
var _map = _interopRequireDefault(require("lodash/map"));
|
|
33
|
-
|
|
34
21
|
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
35
|
-
|
|
36
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
37
|
-
|
|
38
23
|
// lodash
|
|
24
|
+
|
|
39
25
|
var _ = {
|
|
40
26
|
assign: _assign["default"],
|
|
41
27
|
get: _get["default"],
|
|
42
28
|
map: _map["default"],
|
|
43
29
|
omit: _omit["default"]
|
|
44
30
|
};
|
|
45
|
-
|
|
46
31
|
function requestSearchAuthors() {
|
|
47
32
|
var keywords = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
48
33
|
return {
|
|
@@ -52,6 +37,7 @@ function requestSearchAuthors() {
|
|
|
52
37
|
}
|
|
53
38
|
};
|
|
54
39
|
}
|
|
40
|
+
|
|
55
41
|
/**
|
|
56
42
|
* NormalizedData
|
|
57
43
|
* @typedef {Object} NormalizedData
|
|
@@ -70,12 +56,10 @@ function requestSearchAuthors() {
|
|
|
70
56
|
* @property {number} receivedAt
|
|
71
57
|
*/
|
|
72
58
|
|
|
73
|
-
|
|
74
59
|
function searchAuthors(_ref) {
|
|
75
60
|
var keywords = _ref.keywords,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
61
|
+
targetPage = _ref.targetPage,
|
|
62
|
+
returnDelay = _ref.returnDelay;
|
|
79
63
|
/**
|
|
80
64
|
* @param {Function} dispatch - Redux store dispatch function
|
|
81
65
|
* @param {Function} getState - Redux store getState function
|
|
@@ -89,23 +73,16 @@ function searchAuthors(_ref) {
|
|
|
89
73
|
offset: targetPage * _authorsList.MAX_RESULTS_PER_FETCH
|
|
90
74
|
};
|
|
91
75
|
var state = getState();
|
|
92
|
-
|
|
93
76
|
var apiOrigin = _.get(state, [_reduxStateFieldNames["default"].origins, 'api']);
|
|
94
|
-
|
|
95
77
|
var url = (0, _url.formURL)(apiOrigin, '/v2/authors', searchParas, false);
|
|
96
|
-
dispatch(requestSearchAuthors(keywords));
|
|
97
|
-
|
|
78
|
+
dispatch(requestSearchAuthors(keywords));
|
|
79
|
+
// Call our API server to fetch the data
|
|
98
80
|
return _axios["default"].get(url).then(function (_ref2) {
|
|
99
81
|
var data = _ref2.data;
|
|
100
|
-
|
|
101
82
|
var authors = _.get(data, 'data.records', {});
|
|
102
|
-
|
|
103
83
|
var offset = _.get(data, 'data.meta.offset', 0);
|
|
104
|
-
|
|
105
84
|
var limit = _.get(data, 'data.meta.limit', 24);
|
|
106
|
-
|
|
107
85
|
var total = _.get(data, 'data.meta.total', 0);
|
|
108
|
-
|
|
109
86
|
var receiveSearchAuthorsAction = {
|
|
110
87
|
type: keywords === '' ? _actionTypes["default"].LIST_ALL_AUTHORS_SUCCESS : _actionTypes["default"].SEARCH_AUTHORS_SUCCESS,
|
|
111
88
|
payload: {
|
|
@@ -115,8 +92,8 @@ function searchAuthors(_ref) {
|
|
|
115
92
|
totalPages: Math.ceil(total / limit),
|
|
116
93
|
receivedAt: Date.now()
|
|
117
94
|
}
|
|
118
|
-
};
|
|
119
|
-
|
|
95
|
+
};
|
|
96
|
+
// delay for displaying loading spinner
|
|
120
97
|
function delayDispatch() {
|
|
121
98
|
return new Promise(function (resolve, reject) {
|
|
122
99
|
// eslint-disable-line no-unused-vars
|
|
@@ -125,37 +102,32 @@ function searchAuthors(_ref) {
|
|
|
125
102
|
}, returnDelay);
|
|
126
103
|
});
|
|
127
104
|
}
|
|
128
|
-
|
|
129
105
|
if (returnDelay > 0) {
|
|
130
106
|
return delayDispatch().then(function () {
|
|
131
107
|
dispatch(receiveSearchAuthorsAction);
|
|
132
108
|
return receiveSearchAuthorsAction;
|
|
133
109
|
});
|
|
134
110
|
}
|
|
135
|
-
|
|
136
111
|
dispatch(receiveSearchAuthorsAction);
|
|
137
112
|
return receiveSearchAuthorsAction;
|
|
138
113
|
}, function (error) {
|
|
139
114
|
var type = keywords === '' ? _actionTypes["default"].LIST_ALL_AUTHORS_FAILURE : _actionTypes["default"].SEARCH_AUTHORS_FAILURE;
|
|
140
|
-
|
|
141
115
|
var failAction = _errorActionCreators["default"].axios(error, type);
|
|
142
|
-
|
|
143
116
|
failAction.payload.failedAt = Date.now();
|
|
144
117
|
dispatch(failAction);
|
|
145
118
|
return Promise.reject(failAction);
|
|
146
119
|
});
|
|
147
120
|
};
|
|
148
121
|
}
|
|
122
|
+
|
|
149
123
|
/*
|
|
150
124
|
Algolia set hitsPerPage limit up to 1000 items per search.
|
|
151
125
|
So if number of authors grows over 1000,
|
|
152
126
|
it will need to check hasMore as case lsat all authors.
|
|
153
127
|
*/
|
|
154
128
|
|
|
155
|
-
|
|
156
129
|
function searchAuthorsIfNeeded() {
|
|
157
130
|
var currentKeywords = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
158
|
-
|
|
159
131
|
/* --------- list all authors --------- */
|
|
160
132
|
if (currentKeywords === '') {
|
|
161
133
|
/**
|
|
@@ -165,13 +137,10 @@ function searchAuthorsIfNeeded() {
|
|
|
165
137
|
*/
|
|
166
138
|
return function (dispatch, getState) {
|
|
167
139
|
var currentState = getState();
|
|
168
|
-
|
|
169
140
|
var authorsList = _.get(currentState, 'authorsList', {});
|
|
170
|
-
|
|
171
141
|
var isFetching = authorsList.isFetching,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
142
|
+
currentPage = authorsList.currentPage,
|
|
143
|
+
hasMore = authorsList.hasMore;
|
|
175
144
|
if (currentPage < _authorsList.NUMBER_OF_FIRST_RESPONSE_PAGE) {
|
|
176
145
|
// If no data exists => fetch first page immediately
|
|
177
146
|
return dispatch(searchAuthors({
|
|
@@ -180,7 +149,6 @@ function searchAuthorsIfNeeded() {
|
|
|
180
149
|
returnDelay: 0
|
|
181
150
|
}));
|
|
182
151
|
}
|
|
183
|
-
|
|
184
152
|
if (!hasMore) {
|
|
185
153
|
var action = {
|
|
186
154
|
type: _actionTypes["default"].noMoreItemsToFetch,
|
|
@@ -195,7 +163,6 @@ function searchAuthorsIfNeeded() {
|
|
|
195
163
|
dispatch(action);
|
|
196
164
|
return Promise.resolve(action);
|
|
197
165
|
}
|
|
198
|
-
|
|
199
166
|
if (isFetching) {
|
|
200
167
|
var _action = {
|
|
201
168
|
type: _actionTypes["default"].lastActionIsStillProcessing,
|
|
@@ -209,9 +176,9 @@ function searchAuthorsIfNeeded() {
|
|
|
209
176
|
};
|
|
210
177
|
dispatch(_action);
|
|
211
178
|
return Promise.resolve(_action);
|
|
212
|
-
}
|
|
213
|
-
|
|
179
|
+
}
|
|
214
180
|
|
|
181
|
+
// If already have data AND not fetching AND has more => delay && next page
|
|
215
182
|
return dispatch(searchAuthors({
|
|
216
183
|
keywords: '',
|
|
217
184
|
targetPage: currentPage + 1,
|
|
@@ -220,21 +187,15 @@ function searchAuthorsIfNeeded() {
|
|
|
220
187
|
};
|
|
221
188
|
}
|
|
222
189
|
/* --------- searching authors --------- */
|
|
223
|
-
|
|
224
190
|
/**
|
|
225
191
|
* @param {Function} dispatch - Redux store dispatch function
|
|
226
192
|
* @param {Function} getState - Redux store getState function
|
|
227
193
|
* @return {Promise} resolve with success action or reject with fail action
|
|
228
194
|
*/
|
|
229
|
-
|
|
230
|
-
|
|
231
195
|
return function (dispatch, getState) {
|
|
232
196
|
var currentState = getState();
|
|
233
|
-
|
|
234
197
|
var authorsList = _.get(currentState, 'searchedAuthorsList', {});
|
|
235
|
-
|
|
236
198
|
var previousKeywords = _.get(authorsList, 'keywords');
|
|
237
|
-
|
|
238
199
|
if (currentKeywords !== previousKeywords) {
|
|
239
200
|
// Situation 1/2:If keywords are new => search
|
|
240
201
|
return dispatch(searchAuthors({
|
|
@@ -243,7 +204,6 @@ function searchAuthorsIfNeeded() {
|
|
|
243
204
|
returnDelay: 0
|
|
244
205
|
}));
|
|
245
206
|
}
|
|
246
|
-
|
|
247
207
|
var action = {
|
|
248
208
|
type: _actionTypes["default"].dataAlreadyExists,
|
|
249
209
|
payload: {
|