I have successfully implemented the delete comment function in my Angular app. My problem now is on the liking function of the comment. How do i implement the like function. I have the variable is_liked to determine if its like or not. The value = 0 means its not like and the value = 1 is liked. Pls see my stackblitz link here
onLikeComment(data: Comment) {
this.store.dispatch(new LikeComment(data)).subscribe();
}
@Action(LikeComment)
likeComment(
ctx: StateContext<PostStateModel>,
{ payload }: LikeComment
) {
if (payload.is_liked === 1) {
payload.is_liked = 0;
} else {
payload.is_liked = 1;
}
const state = ctx.getState();
ctx.setState(
patch({
post: {
...state.post,
comments: [
...state.post.comments,
updateItem<any>(name => name === payload.id, payload)
]
}
})
);
}