|
@@ -1,6 +1,7 @@
|
|
export const postsFeedReducer = (state = {}, { type, findId, newResult, userData = {}, count = null }) => {
|
|
export const postsFeedReducer = (state = {}, { type, findId, newResult, userData = {}, count = null }) => {
|
|
const { posts } = state
|
|
const { posts } = state
|
|
const types = {
|
|
const types = {
|
|
|
|
+
|
|
'ADD-POSTS-FEED': () => ({
|
|
'ADD-POSTS-FEED': () => ({
|
|
...state,
|
|
...state,
|
|
posts: Array.isArray(newResult)
|
|
posts: Array.isArray(newResult)
|
|
@@ -8,13 +9,16 @@ export const postsFeedReducer = (state = {}, { type, findId, newResult, userData
|
|
: { ...posts, ...newResult },
|
|
: { ...posts, ...newResult },
|
|
count
|
|
count
|
|
}),
|
|
}),
|
|
|
|
+
|
|
'GET-POST': () => ({ ...state, posts: { ...newResult } }),
|
|
'GET-POST': () => ({ ...state, posts: { ...newResult } }),
|
|
|
|
+
|
|
'ADD-PROFILE-DATA': () => ({
|
|
'ADD-PROFILE-DATA': () => ({
|
|
...state,
|
|
...state,
|
|
posts: !!posts ? [...posts, ...newResult] : [...newResult],
|
|
posts: !!posts ? [...posts, ...newResult] : [...newResult],
|
|
userData,
|
|
userData,
|
|
count
|
|
count
|
|
}),
|
|
}),
|
|
|
|
+
|
|
'REMOVE-POSTS-FEED': () => ({
|
|
'REMOVE-POSTS-FEED': () => ({
|
|
...state,
|
|
...state,
|
|
posts: [],
|
|
posts: [],
|
|
@@ -22,21 +26,25 @@ export const postsFeedReducer = (state = {}, { type, findId, newResult, userData
|
|
count: 0,
|
|
count: 0,
|
|
subComments: {},
|
|
subComments: {},
|
|
}),
|
|
}),
|
|
|
|
+
|
|
'ADD-POST-LIKE': () => ({
|
|
'ADD-POST-LIKE': () => ({
|
|
...state,
|
|
...state,
|
|
posts: Array.isArray(posts)
|
|
posts: Array.isArray(posts)
|
|
? posts.map(p => p._id === findId ? p = { ...p, likes: [...newResult] } : p)
|
|
? posts.map(p => p._id === findId ? p = { ...p, likes: [...newResult] } : p)
|
|
: { ...state.posts, likes: [...newResult] },
|
|
: { ...state.posts, likes: [...newResult] },
|
|
}),
|
|
}),
|
|
|
|
+
|
|
'REMOVE-POST-LIKE': () => ({
|
|
'REMOVE-POST-LIKE': () => ({
|
|
...state,
|
|
...state,
|
|
posts: Array.isArray(posts)
|
|
posts: Array.isArray(posts)
|
|
? posts.map(p => p._id === findId ? p = { ...p, likes: [...newResult] } : p)
|
|
? posts.map(p => p._id === findId ? p = { ...p, likes: [...newResult] } : p)
|
|
: { ...state.posts, likes: [...newResult] },
|
|
: { ...state.posts, likes: [...newResult] },
|
|
}),
|
|
}),
|
|
|
|
+
|
|
'ADD-COMMENT': () => ({
|
|
'ADD-COMMENT': () => ({
|
|
...state, posts: { ...state.posts, comments: [...newResult] }
|
|
...state, posts: { ...state.posts, comments: [...newResult] }
|
|
}),
|
|
}),
|
|
|
|
+
|
|
'UPDATE-SUBCOMMENT': () => {
|
|
'UPDATE-SUBCOMMENT': () => {
|
|
const upsertSubComments = (commentList, id, nR) => {
|
|
const upsertSubComments = (commentList, id, nR) => {
|
|
return commentList.map(c => {
|
|
return commentList.map(c => {
|
|
@@ -56,6 +64,7 @@ export const postsFeedReducer = (state = {}, { type, findId, newResult, userData
|
|
...state, posts: { ...state.posts, comments: upsertSubComments(posts.comments, findId, newResult) }
|
|
...state, posts: { ...state.posts, comments: upsertSubComments(posts.comments, findId, newResult) }
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
+
|
|
'EDIT-COMMENT': () => {
|
|
'EDIT-COMMENT': () => {
|
|
const { _id, text } = newResult
|
|
const { _id, text } = newResult
|
|
const editComments = (commentList, id, nR) => {
|
|
const editComments = (commentList, id, nR) => {
|
|
@@ -99,6 +108,7 @@ export const postsFeedReducer = (state = {}, { type, findId, newResult, userData
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
+
|
|
'UPDATE-FOLLOWERS': () => ({
|
|
'UPDATE-FOLLOWERS': () => ({
|
|
...state,
|
|
...state,
|
|
userData: { ...state.userData, followers: [...newResult] }
|
|
userData: { ...state.userData, followers: [...newResult] }
|