jamespot-front-business 1.1.67 → 1.1.68

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
@@ -484,6 +484,36 @@ const CommentListSlice = toolkit.createSlice({
484
484
  discardComments: (state, action) => {
485
485
  state.comments = state.comments.filter((c) => c.idArticle !== action.payload.idArticle);
486
486
  },
487
+ hydrateComment: (state, action) => {
488
+ const { idArticle, list } = action.payload;
489
+ const hasList = state.comments.find((c) => c.idArticle === idArticle);
490
+ if (!hasList) {
491
+ state.comments = [
492
+ ...state.comments.filter((c) => c.idArticle !== idArticle),
493
+ {
494
+ idArticle,
495
+ list,
496
+ },
497
+ ];
498
+ return;
499
+ }
500
+ const initialUris = [];
501
+ const allUris = state.comments.reduce((uris, c) => {
502
+ return [...uris, ...c.list.map((el) => el.uri)];
503
+ }, initialUris);
504
+ const safeList = list.filter((el) => !allUris.includes(el.uri));
505
+ state.comments = state.comments.map((c) => {
506
+ return c.idArticle === idArticle
507
+ ? Object.assign(Object.assign({}, c), { list: [...c.list, ...safeList] }) : c;
508
+ });
509
+ },
510
+ updateComment: (state, action) => {
511
+ state.comments = state.comments.map((c) => {
512
+ const { idArticle, idComment, data } = action.payload;
513
+ return c.idArticle === idArticle
514
+ ? Object.assign(Object.assign({}, c), { list: c.list.map((comment) => comment.id === idComment ? Object.assign(Object.assign({}, comment), { description: data.description }) : comment) }) : c;
515
+ });
516
+ },
487
517
  },
488
518
  extraReducers: (builder) => {
489
519
  builder