commentTypes.js 860 B

12345678910111213141516171819202122232425262728293031323334
  1. export const actionAddCommentPostFeedType = (postId, newResult) => ({
  2. type: 'ADD_COMMENT_POSTS',
  3. postId,
  4. newResult,
  5. })
  6. export const actionAddCommentType = (newResult) => ({
  7. type: 'ADD_COMMENT',
  8. newResult,
  9. })
  10. export const actionAddSubCommentType = (commentId, newResult) => ({
  11. type: 'ANSWERS-COMMENT',
  12. commentId,
  13. newResult,
  14. })
  15. export const actionAddSubCommentFeedType = (commentId, newResult) => ({
  16. type: 'FEED-ANSWERS-COMMENT',
  17. commentId,
  18. newResult,
  19. })
  20. export const addAnswers = (comments, commentId, newResult) =>
  21. comments.map((comment) => {
  22. if (comment._id === commentId) {
  23. return { ...comment, answers: newResult }
  24. } else if (comment?.answers?.length) {
  25. return {
  26. ...comment,
  27. answers: addAnswers(comment.answers, commentId, newResult),
  28. }
  29. } else {
  30. return { ...comment }
  31. }
  32. })