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/esm.js CHANGED
@@ -495,19 +495,19 @@ const CommentListSlice = createSlice({
495
495
  ...state.comments.filter((c) => c.idArticle !== idArticle),
496
496
  {
497
497
  idArticle,
498
- list,
498
+ list: Array.isArray(list) ? list : [],
499
499
  },
500
500
  ];
501
501
  return;
502
502
  }
503
503
  const initialUris = [];
504
504
  const allUris = state.comments.reduce((uris, c) => {
505
- return [...uris, ...c.list.map((el) => el.uri)];
505
+ return Array.isArray(c.list) ? [...uris, ...c.list.map((el) => el.uri)] : [...uris];
506
506
  }, initialUris);
507
- const safeList = list.filter((el) => !allUris.includes(el.uri));
507
+ const safeList = Array.isArray(list) ? list.filter((el) => !allUris.includes(el.uri)) : [];
508
508
  state.comments = state.comments.map((c) => {
509
509
  return c.idArticle === idArticle
510
- ? Object.assign(Object.assign({}, c), { list: [...c.list, ...safeList] }) : c;
510
+ ? Object.assign(Object.assign({}, c), { list: Array.isArray(c.list) ? [...c.list, ...safeList] : [...safeList] }) : c;
511
511
  });
512
512
  },
513
513
  updateComment: (state, action) => {
@@ -594,7 +594,12 @@ const commentSlice = {
594
594
  name: 'comment',
595
595
  reducer: CommentReducer,
596
596
  };
597
- const selectCommentList = (state, idArticle) => state.comment.commentList.comments.find((c) => c.idArticle === idArticle);
597
+ const selectCommentList = (state, idArticle, limit = 0) => {
598
+ const data = state.comment.commentList.comments.find((c) => c.idArticle === idArticle);
599
+ const dataList = data && Array.isArray(data.list) ? data.list : [];
600
+ const list = [...dataList].sort((c1, c2) => c1.id - c2.id);
601
+ return limit !== 0 ? list.slice(-limit) : list;
602
+ };
598
603
  const Comment = {
599
604
  slice: commentSlice,
600
605
  actions: Object.assign({ fetchComments }, CommentListSlice.actions),