jamespot-front-business 1.1.80 → 1.1.81

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/dist/cjs.js CHANGED
@@ -503,19 +503,19 @@ const CommentListSlice = toolkit.createSlice({
503
503
  ...state.comments.filter((c) => c.idArticle !== idArticle),
504
504
  {
505
505
  idArticle,
506
- list,
506
+ list: Array.isArray(list) ? list : [],
507
507
  },
508
508
  ];
509
509
  return;
510
510
  }
511
511
  const initialUris = [];
512
512
  const allUris = state.comments.reduce((uris, c) => {
513
- return [...uris, ...c.list.map((el) => el.uri)];
513
+ return Array.isArray(c.list) ? [...uris, ...c.list.map((el) => el.uri)] : [...uris];
514
514
  }, initialUris);
515
- const safeList = list.filter((el) => !allUris.includes(el.uri));
515
+ const safeList = Array.isArray(list) ? list.filter((el) => !allUris.includes(el.uri)) : [];
516
516
  state.comments = state.comments.map((c) => {
517
517
  return c.idArticle === idArticle
518
- ? Object.assign(Object.assign({}, c), { list: [...c.list, ...safeList] }) : c;
518
+ ? Object.assign(Object.assign({}, c), { list: Array.isArray(c.list) ? [...c.list, ...safeList] : [...safeList] }) : c;
519
519
  });
520
520
  },
521
521
  updateComment: (state, action) => {
@@ -602,7 +602,12 @@ const commentSlice = {
602
602
  name: 'comment',
603
603
  reducer: CommentReducer,
604
604
  };
605
- const selectCommentList = (state, idArticle) => state.comment.commentList.comments.find((c) => c.idArticle === idArticle);
605
+ const selectCommentList = (state, idArticle, limit = 0) => {
606
+ const data = state.comment.commentList.comments.find((c) => c.idArticle === idArticle);
607
+ const dataList = data && Array.isArray(data.list) ? data.list : [];
608
+ const list = [...dataList].sort((c1, c2) => c1.id - c2.id);
609
+ return limit !== 0 ? list.slice(-limit) : list;
610
+ };
606
611
  const Comment = {
607
612
  slice: commentSlice,
608
613
  actions: Object.assign({ fetchComments }, CommentListSlice.actions),