|
@@ -1,26 +1,27 @@
|
|
import { PlusOutlined } from '@ant-design/icons'
|
|
import { PlusOutlined } from '@ant-design/icons'
|
|
import { actionOnePost } from '../../actions'
|
|
import { actionOnePost } from '../../actions'
|
|
|
|
|
|
-const addAnswers = (comments, id, newResult, field) =>
|
|
|
|
|
|
+const addAnswers = (comments, commentId, newResult) =>
|
|
comments.map(comment => {
|
|
comments.map(comment => {
|
|
- if (comment._id === id) {
|
|
|
|
- return { ...comment, [field]: newResult }
|
|
|
|
- } else if (comment?.answers?.length) {
|
|
|
|
|
|
+ if (comment._id === commentId)
|
|
|
|
+ {
|
|
|
|
+ return { ...comment, 'answers': newResult }
|
|
|
|
+ }
|
|
|
|
+ else if (comment?.answers?.length) {
|
|
return {
|
|
return {
|
|
...comment,
|
|
...comment,
|
|
- answers: addAnswers(comment.answers, id, newResult, field)
|
|
|
|
|
|
+ answers: addAnswers(comment.answers, commentId, newResult)
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
return { ...comment }
|
|
return { ...comment }
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
})
|
|
})
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
export const postReducer = (
|
|
export const postReducer = (
|
|
state = {},
|
|
state = {},
|
|
- { skip, type, newPosts = [], onePost,newResult, commentId, answers,postsFeed, postsFeedCount },
|
|
|
|
|
|
+ { type, onePost,newResult, commentId},
|
|
) => {
|
|
) => {
|
|
const types = {
|
|
const types = {
|
|
'POST': () => {
|
|
'POST': () => {
|
|
@@ -54,7 +55,7 @@ export const postReducer = (
|
|
onePost: ({
|
|
onePost: ({
|
|
...state?.onePost,
|
|
...state?.onePost,
|
|
comments: addAnswers(state.onePost.comments,
|
|
comments: addAnswers(state.onePost.comments,
|
|
- commentId, newResult, 'answers')
|
|
|
|
|
|
+ commentId, newResult)
|
|
}),
|
|
}),
|
|
})
|
|
})
|
|
|
|
|