Skip to content

Commit 41233cc

Browse files
committed
Fix: like, unlike for single post
1 parent 73827ce commit 41233cc

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

https/front/reducers/post.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,14 @@ const reducer = (state = initialState, action) => produce(state, (draft) => {
147147
break;
148148
case LIKE_POST_SUCCESS: {
149149
const post = draft.mainPosts.find((v) => v.id === action.data.PostId);
150-
post.Likers.push({ id: action.data.UserId });
150+
if (post) {
151+
post.Likers.push({ id: action.data.UserId });
152+
}
151153
draft.likePostLoading = false;
152154
draft.likePostDone = true;
155+
if (draft.singlePost?.Likers) {
156+
draft.singlePost.Likers.push({ id: action.data.UserId });
157+
}
153158
break;
154159
}
155160
case LIKE_POST_FAILURE:
@@ -163,9 +168,15 @@ const reducer = (state = initialState, action) => produce(state, (draft) => {
163168
break;
164169
case UNLIKE_POST_SUCCESS: {
165170
const post = draft.mainPosts.find((v) => v.id === action.data.PostId);
166-
post.Likers = post.Likers.filter((v) => v.id !== action.data.UserId);
171+
if (post) {
172+
post.Likers = post.Likers.filter((v) => v.id !== action.data.UserId);
173+
}
167174
draft.unlikePostLoading = false;
168175
draft.unlikePostDone = true;
176+
if (draft.singlePost?.Likers) {
177+
const index = draft.singlePost.Likers.find((v) => v.id === action.data.UserId);
178+
draft.singlePost.Likers.splice(index, 1);
179+
}
169180
break;
170181
}
171182
case UNLIKE_POST_FAILURE:

0 commit comments

Comments
 (0)