@twreporter/redux 7.2.1 → 7.3.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 CHANGED
@@ -3,6 +3,41 @@
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
+ # [7.3.0-rc.0](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/redux@7.2.2...@twreporter/redux@7.3.0-rc.0) (2022-08-22)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix redux test ([11b4c5f](https://github.com/twreporter/twreporter-npm-packages/commit/11b4c5f56e86eb4a3943317ad1485fe16cef64d6))
12
+
13
+
14
+ ### Features
15
+
16
+ * add `fetchPostsByCategorySetListId` action ([5980ebb](https://github.com/twreporter/twreporter-npm-packages/commit/5980ebb6eb8bc81f294b260b65421cad04e44050))
17
+
18
+
19
+
20
+
21
+
22
+ ## [7.2.2](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/redux@7.2.2-rc.0...@twreporter/redux@7.2.2) (2022-07-06)
23
+
24
+ **Note:** Version bump only for package @twreporter/redux
25
+
26
+
27
+
28
+
29
+
30
+ ## [7.2.2-rc.0](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/redux@7.2.1...@twreporter/redux@7.2.2-rc.0) (2022-06-30)
31
+
32
+
33
+ ### Bug Fixes
34
+
35
+ * new bookmark should be fetched when mount ([9bb438f](https://github.com/twreporter/twreporter-npm-packages/commit/9bb438f81bd321fee47f55c872589091d8db8be6))
36
+
37
+
38
+
39
+
40
+
6
41
  ## [7.2.1](https://github.com/twreporter/twreporter-npm-packages/compare/@twreporter/redux@7.2.1-rc.0...@twreporter/redux@7.2.1) (2022-04-29)
7
42
 
8
43
  **Note:** Version bump only for package @twreporter/redux
@@ -32,6 +32,7 @@ var _default = {
32
32
  fetchIndexPageContent: _indexPage.fetchIndexPageContent,
33
33
  fetchPostsByCategoryListId: _posts.fetchPostsByCategoryListId,
34
34
  fetchPostsByTagListId: _posts.fetchPostsByTagListId,
35
+ fetchPostsByCategorySetListId: _posts.fetchPostsByCategorySetListId,
35
36
  fetchRelatedPostsOfAnEntity: _posts.fetchRelatedPostsOfAnEntity,
36
37
  fetchTopics: _topics.fetchTopics,
37
38
  getAccessToken: _auth.getAccessToken,
@@ -7,6 +7,7 @@ exports.fetchAFullPost = fetchAFullPost;
7
7
  exports.fetchRelatedPostsOfAnEntity = fetchRelatedPostsOfAnEntity;
8
8
  exports.fetchPostsByCategoryListId = fetchPostsByCategoryListId;
9
9
  exports.fetchPostsByTagListId = fetchPostsByTagListId;
10
+ exports.fetchPostsByCategorySetListId = fetchPostsByCategorySetListId;
10
11
 
11
12
  var _url = require("../utils/url");
12
13
 
@@ -28,14 +29,27 @@ var _get = _interopRequireDefault(require("lodash/get"));
28
29
 
29
30
  var _merge = _interopRequireDefault(require("lodash/merge"));
30
31
 
32
+ var _split = _interopRequireDefault(require("lodash/split"));
33
+
31
34
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
32
35
 
33
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
36
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
37
+
38
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
39
+
40
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
41
+
42
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
43
+
44
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
45
+
46
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
34
47
 
35
48
  var _ = {
36
49
  filter: _filter["default"],
37
50
  get: _get["default"],
38
- merge: _merge["default"]
51
+ merge: _merge["default"],
52
+ split: _split["default"]
39
53
  };
40
54
  var entities = _reduxStateFieldNames["default"].entities,
41
55
  postsInEntities = _reduxStateFieldNames["default"].postsInEntities;
@@ -234,8 +248,9 @@ var startPage = 1;
234
248
  /**
235
249
  * Fetch a listed posts(only containing meta properties),
236
250
  * such as the posts belonging to the same tag/category/topic.
237
- * @param {string} listId - id of tag or category
238
- * @param {string} listType - tag_id or category_id
251
+ * @param {string} listId - id of tag, category or category_set
252
+ * @param {string} listType - tag_id, category_id or category_set_id
253
+ * category_set_id: `${category_id}_${subcateogry_id}`
239
254
  * @param {number} [limit=10] - the number of posts you want to get in one request
240
255
  * @param {number} [page=1] - page is used to calculate `offset`, which indicates how many posts we should skip
241
256
  * @param {number} timeout - request api timeout
@@ -247,30 +262,24 @@ function fetchPostsByListId(listId, listType) {
247
262
  var page = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : startPage;
248
263
  var timeout = arguments.length > 4 ? arguments[4] : undefined;
249
264
  return function (dispatch, getState) {
250
- var _params;
251
-
252
- if (typeof listId !== 'string' || !listId) {
265
+ var fail = function fail(reason) {
253
266
  var action = {
254
267
  type: _actionTypes["default"].postsByListId.read.failure,
255
268
  payload: {
256
- listId: '',
257
- error: new Error('listId should be a string and not empty, but got ' + listId)
269
+ listId: typeof listId === 'string' ? listId : '',
270
+ error: new Error(reason)
258
271
  }
259
272
  };
260
273
  dispatch(action);
261
274
  return Promise.reject(action);
262
- }
275
+ };
263
276
 
264
277
  if (typeof page !== 'number' || isNaN(page) || page < startPage) {
265
- var _action2 = {
266
- type: _actionTypes["default"].postsByListId.read.failure,
267
- payload: {
268
- listId: listId,
269
- error: new Error('page should be > 0')
270
- }
271
- };
272
- dispatch(_action2);
273
- return Promise.reject(_action2);
278
+ return fail('page should be > 0');
279
+ }
280
+
281
+ if (typeof listId !== 'string' || !listId) {
282
+ return fail("listId should be a string and not empty, but got ".concat(listId));
274
283
  }
275
284
 
276
285
  var state = getState();
@@ -279,7 +288,7 @@ function fetchPostsByListId(listId, listType) {
279
288
 
280
289
 
281
290
  if (Array.isArray(_.get(list, ['pages', page]))) {
282
- var _action3 = {
291
+ var action = {
283
292
  type: _actionTypes["default"].postsByListId.read.alreadyExists,
284
293
  payload: {
285
294
  listId: listId,
@@ -287,8 +296,8 @@ function fetchPostsByListId(listId, listType) {
287
296
  page: page
288
297
  }
289
298
  };
290
- dispatch(_action3);
291
- return Promise.resolve(_action3);
299
+ dispatch(action);
300
+ return Promise.resolve(action);
292
301
  }
293
302
 
294
303
  var offset = (page - 1) * limit;
@@ -296,7 +305,23 @@ function fetchPostsByListId(listId, listType) {
296
305
  var apiOrigin = _.get(state, [_reduxStateFieldNames["default"].origins, 'api']);
297
306
 
298
307
  var path = "/v2/".concat(_apiEndpoints["default"].posts);
299
- var params = (_params = {}, _defineProperty(_params, listType, listId), _defineProperty(_params, "limit", limit), _defineProperty(_params, "offset", offset), _params);
308
+ var params = {
309
+ limit: limit,
310
+ offset: offset
311
+ };
312
+
313
+ if (listType === 'category_set_id') {
314
+ var _$split = _.split(listId, '_'),
315
+ _$split2 = _slicedToArray(_$split, 2),
316
+ categoryId = _$split2[0],
317
+ subcategoryId = _$split2[1];
318
+
319
+ params.category_id = categoryId;
320
+ params.subcategory_id = subcategoryId;
321
+ } else {
322
+ params[listType] = listId;
323
+ }
324
+
300
325
  var url = (0, _url.formURL)(apiOrigin, path, params);
301
326
  dispatch({
302
327
  type: _actionTypes["default"].postsByListId.read.request,
@@ -346,4 +371,23 @@ function fetchPostsByTagListId(listId) {
346
371
  return function (dispatch, getState) {
347
372
  return fetchPostsByListId(listId, 'tag_id', limit, page, timeout)(dispatch, getState);
348
373
  };
374
+ }
375
+ /**
376
+ * Fetch posts(only containing meta properties) by category set id.
377
+ * @param {string} listId - id of category set
378
+ * category set id: `${category_id}_${subcategory_id}`
379
+ * @param {number} [limit=10] - the number of posts you want to get in one request
380
+ * @param {number} [page=1] - page is used to calculate `offset`, which indicates how many posts we should skip
381
+ * @param {number} [timeout=apiConfig.timeout] - request api timeout
382
+ * @return {import('../typedef').Thunk} async action creator
383
+ */
384
+
385
+
386
+ function fetchPostsByCategorySetListId(listId) {
387
+ var limit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
388
+ var page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
389
+ var timeout = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _apiConfig["default"].timeout;
390
+ return function (dispatch, getState) {
391
+ return fetchPostsByListId(listId, 'category_set_id', limit, page, timeout)(dispatch, getState);
392
+ };
349
393
  }
@@ -15,6 +15,10 @@ var _findIndex = _interopRequireDefault(require("lodash/findIndex"));
15
15
 
16
16
  var _uniq = _interopRequireDefault(require("lodash/uniq"));
17
17
 
18
+ var _orderBy = _interopRequireDefault(require("lodash/orderBy"));
19
+
20
+ var _map = _interopRequireDefault(require("lodash/map"));
21
+
18
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
23
 
20
24
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
@@ -39,7 +43,9 @@ var _ = {
39
43
  assign: _assign["default"],
40
44
  findIndex: _findIndex["default"],
41
45
  get: _get["default"],
42
- uniq: _uniq["default"]
46
+ uniq: _uniq["default"],
47
+ orderBy: _orderBy["default"],
48
+ map: _map["default"]
43
49
  };
44
50
  var defaultLimit = 10;
45
51
  var initState = {
@@ -77,25 +83,21 @@ function bookmarks() {
77
83
  total = meta.total,
78
84
  limit = meta.limit;
79
85
 
80
- var bookmarkIDList = _toConsumableArray(state.bookmarkIDList);
81
-
82
86
  var entities = _objectSpread({}, state.entities); // Push new fetched records to stored ones and push ids to id list
83
87
 
84
88
 
85
89
  fetchedRecords.forEach(function (record) {
86
90
  var id = _.get(record, 'id');
87
91
 
88
- if (id) {
89
- if (!bookmarkIDList.some(function (idInList) {
90
- return idInList === id;
91
- })) {
92
- bookmarkIDList.push(id);
93
- } // prevent duplicate items in list
94
-
95
-
96
- entities["".concat(id)] = record;
92
+ if (!id) {
93
+ return;
97
94
  }
95
+
96
+ entities["".concat(id)] = record;
98
97
  });
98
+
99
+ var bookmarkIDList = _.map(_.orderBy(entities, ['added_at'], ['desc']), 'id');
100
+
99
101
  return _objectSpread(_objectSpread({}, state), {}, {
100
102
  actionType: action.type,
101
103
  isRequesting: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twreporter/redux",
3
- "version": "7.2.1",
3
+ "version": "7.3.0-rc.0",
4
4
  "description": "redux actions and reducers for twreporter website",
5
5
  "repository": "https://github.com/twreporter/twreporter-npm-packages.git",
6
6
  "author": "twreporter <developer@twreporter.org>",
@@ -43,5 +43,5 @@
43
43
  "files": [
44
44
  "lib"
45
45
  ],
46
- "gitHead": "d558a91e42cdf3a177e5d0d3471e834bc75f1cd0"
46
+ "gitHead": "c39b265ecd77107f0e1aeb6d3d147efb969c6226"
47
47
  }